Skip to content

Instantly share code, notes, and snippets.

@yoku0825
yoku0825 / gist:9db4ac205b607fd538aab5c384c7290b
Created April 8, 2024 14:55
Warning (Code 3170): Memory capacity of 5120 bytes for 'range_optimizer_max_mem_size' exceeded. Range optimization was not done for this query.
Breakpoint 1, push_warning_printf (thd=thd@entry=0x7f7244b6dd30, severity=severity@entry=Sql_condition::SL_WARNING, code=code@entry=3170,
format=0x7f729d06a9a4 "Memory capacity of %llu bytes for '%s' exceeded. %s") at /home/yoku0825/mysql-8.0.36/sql/sql_error.cc:692
692 if (format == nullptr) format = ER_THD_NONCONST(thd, code);
(gdb) bt
+bt
#0 push_warning_printf (thd=thd@entry=0x7f7244b6dd30, severity=severity@entry=Sql_condition::SL_WARNING, code=code@entry=3170,
format=0x7f729d06a9a4 "Memory capacity of %llu bytes for '%s' exceeded. %s") at /home/yoku0825/mysql-8.0.36/sql/sql_error.cc:692
#1 0x0000000000ce4123 in handle_condition (sql_errno=34, level=<optimized out>, thd=0x7f7244b6dd30, this=<optimized out>)
at /home/yoku0825/mysql-8.0.36/sql/range_optimizer/internal.h:90
#2 Range_optimizer_error_handler::handle_condition (this=<optimized out>, thd=0x7f7244b6dd30, sql_errno=<optimized out>, level=<optimized out>)
cd client
/opt/rh/devtoolset-11/root/usr/bin/g++ \
-std=c++17 \
-fno-omit-frame-pointer \
-ftls-model=initial-exec \
-B/opt/rh/devtoolset-11/root/usr/bin \
\
-O2 \
-g \
mysql81 9> SHOW PARSE_TREE SELECT user, host, db, user.select_priv AS global_select, db.select_priv AS schema_select FROM mysql.user LEFT JOIN mysql.db USING(user, host)\G
*************************** 1. row ***************************
Show_parse_tree: {
"text": "SELECT user, host, db, user.select_priv AS global_select, db.select_priv AS schema_select FROM mysql.user LEFT JOIN mysql.db USING(user, host)",
"type": "PT_select_stmt",
"components": [
{
"text": "SELECT user, host, db, user.select_priv AS global_select, db.select_priv AS schema_select FROM mysql.user LEFT JOIN mysql.db USING(user, host)",
"type": "PT_query_expression",
"components": [
@yoku0825
yoku0825 / gist:73bd79fca85915e72a3d366ca81b9c14
Created February 2, 2023 06:20
MySQL Bugs: #109875: binlog_transaction_compression causes OOM when crash recovery happened https://bugs.mysql.com/bug.php?id=109875
--------------------------------------------------------------------------------
n time(i) total(B) useful-heap(B) extra-heap(B) stacks(B)
--------------------------------------------------------------------------------
85 54,500,074,813 21,078,405,512 20,888,346,655 190,058,857 0
86 54,512,142,231 21,078,405,512 20,888,346,655 190,058,857 0
99.10% (20,888,346,655B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.
->40.12% (8,455,717,998B) 0x2078B1C: allocate (new_allocator.h:127)
| ->40.12% (8,455,717,998B) 0x2078B1C: allocate (alloc_traits.h:460)
| ->40.12% (8,455,717,998B) 0x2078B1C: _M_allocate (stl_vector.h:346)
| ->40.12% (8,455,717,998B) 0x2078B1C: void std::vector<unsigned char, std::allocator<unsigned char> >::_M_realloc_insert<unsigned char>(__gnu_cxx::__normal_iterator<unsigned char*, std::vector<unsigned
@yoku0825
yoku0825 / CMakeLists.txt
Created December 17, 2022 15:23
pidを取るi_sプラグイン
MYSQL_ADD_PLUGIN(i_s_pid
i_s_pid.cc
MODULE_ONLY
MODULE_OUTPUT_NAME "i_s_pid"
)
@yoku0825
yoku0825 / gist:2629031b69c06377f4dd5b5dc7552ef3
Created September 26, 2022 14:41
mysqlコマンドラインクライアントって、自分の出力がパイプかどうかどうやって判定してるんだろ
$ strace -e write /usr/mysql/8.0.30/bin/mysql -S /usr/mysql/8.0.30/data/mysql.sock -P 64080 --prompt="mysql80 \C> " -e "SELECT 1"
write(1, "+---+\n", 6+---+
) = 6
write(1, "| 1 |\n", 6| 1 |
) = 6
write(1, "+---+\n", 6+---+
) = 6
write(1, "| 1 |\n", 6| 1 |
) = 6
write(1, "+---+\n", 6+---+
@yoku0825
yoku0825 / gist:bb8ce7f57e92e3800f8d9a1492038b27
Created September 10, 2022 02:37
Invisible auto_increment vs LAST_INSERT_ID
mysql80 15> SHOW CREATE TABLE t1\G
*************************** 1. row ***************************
Table: t1
Create Table: CREATE TABLE `t1` (
`num` bigint unsigned NOT NULL AUTO_INCREMENT /*!80023 INVISIBLE */,
`val` varchar(32) COLLATE utf8mb4_ja_0900_as_cs DEFAULT NULL,
UNIQUE KEY `num` (`num`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_ja_0900_as_cs
1 row in set (0.00 sec)
@yoku0825
yoku0825 / another_
Last active August 25, 2022 08:15
PK AUTO_INCREMENTを比較的後から安全に追加する
master [localhost] {msandbox} ((none)) > ALTER TABLE d1.t1 ADD dummy_uuid VARCHAR(36) DEFAULT NULL UNIQUE;
Query OK, 0 rows affected (0.03 sec)
Records: 0 Duplicates: 0 Warnings: 0
master [localhost] {msandbox} ((none)) > INSERT INTO d1.t1 VALUES (3, UUID());
Query OK, 1 row affected (0.00 sec)
$ ./use_all -e "SELECT * FROM d1.t1"
# master
num dummy_uuid
@yoku0825
yoku0825 / gist:ea57b64d26dc645358f2de87f6ef8518
Created July 6, 2022 14:07
競技用my.cnfとなるとこんなもんですかね?
[mysqld]
binlog_row_image = MINIMAL ### バイナリログのエントリあたりの容量を削減
default_authentication_plugin = mysql_native_password ### 5.7, MariaDBとかから載せ替えるなら
event_scheduler = OFF ### 使ってなければお好みで。メモリリークあり
information_schema_stats_expiry = 0 ### SHOW TABLE STATUSが更新されない件
innodb_buffer_pool_size = ?
skip-innodb_doublewrite ### 永続性そっちのけならアリ
innodb_flush_log_at_trx_commit = 2 ### 実はこれより ALTER INSTANCE DISABLE INNODB REDO_LOGの方が効く。ALTER INSTANCE .. はib_logfileに書き込まれるので対応するオプションはない。あと、正常終了しなかったときに二度と起動しなくなる
innodb_flush_method = O_DIRECT_NO_FSYNC
innodb_log_writer_threads = OFF ### もしCPU性能が低いVMとかの場合、これをOFFにするとちょっと速くなることがある
----system---- ----total-cpu-usage---- -dsk/total- -net/total- ---paging-- ---system-- ------memory-usage----- --io/total- ---load-avg---
time |usr sys idl wai hiq siq| read writ| recv send| in out | int csw | used buff cach free| read writ| 1m 5m 15m
21-02 10:01:24| 3 0 96 1 0 0| 0 5998k| 567k 1127k| 0 0 |3088 5277 |6573M 2392k 48.2G 8303M| 0 373 |0.19 0.16 0.19
21-02 10:01:25| 2 0 96 1 0 0| 0 8285k| 425k 847k| 0 0 |2847 4928 |6573M 2392k 48.2G 8299M| 0 329 |0.19 0.16 0.19