Created
April 1, 2021 05:39
-
-
Save yoku0825/d723836b018ae94477d7ec826adbeb7e to your computer and use it in GitHub Desktop.
MySQL 5.6.51にPLEASE句を実装するパッチ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- ./sql/sql_yacc.yy.orig 2021-01-05 19:19:59.000000000 +0900 | |
+++ ./sql/sql_yacc.yy 2021-04-01 11:52:06.167953286 +0900 | |
@@ -2,2 +2,3 @@ | |
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. | |
+ Copyright (c) 2021, yoku0825. All rights reserved. | |
@@ -1570,2 +1571,3 @@ | |
%token SSL_SYM | |
+%token PLEASE_SYM /* yoku0825 */ | |
%token STARTING | |
@@ -2083,4 +2085,12 @@ | |
| xa | |
+ | please | |
; | |
+please: | |
+ PLEASE_SYM statement | |
+ { | |
+ YYTHD->variables.is_pleased= true; | |
+ } | |
+ ; | |
+ | |
deallocate: | |
--- ./sql/sql_parse.cc.orig 2021-01-05 19:19:59.000000000 +0900 | |
+++ ./sql/sql_parse.cc 2021-04-01 14:14:16.605954893 +0900 | |
@@ -1385,2 +1385,3 @@ | |
break; // fatal error is set | |
+ | |
MYSQL_QUERY_START(thd->query(), thd->thread_id, | |
@@ -1389,2 +1390,3 @@ | |
(char *) thd->security_ctx->host_or_ip); | |
+ | |
char *packet_end= thd->query() + thd->query_length(); | |
@@ -1483,3 +1485,4 @@ | |
mysql_parse(thd, beginning_of_next_stmt, length, &parser_state); | |
- } | |
+ | |
+ } | |
@@ -1829,2 +1832,3 @@ | |
thd->send_kill_message(); | |
+ | |
thd->protocol->end_statement(); | |
@@ -6427,2 +6431,3 @@ | |
mysql_reset_thd_for_next_command(thd); | |
+ thd->variables.is_pleased= 0; /* yoku0825 */ | |
@@ -6434,2 +6439,21 @@ | |
+ /* yoku0825 */ | |
+ if (!(thd->variables.is_pleased)) | |
+ { | |
+ if (thd->variables.sql_mode & MODE_STRICT_PLEASE) | |
+ { | |
+ my_printf_error(490825, "Please add PLEASE clause. I don't run your query.", MYF(0)); | |
+ error= 1; | |
+ DBUG_VOID_RETURN; | |
+ } | |
+ else | |
+ { | |
+ sleep(1); | |
+ push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, | |
+ 490825, | |
+ "Please add PLEASE clause for speedup MySQL. See https://sakaik.hateblo.jp/entry/20210401/mysql_please_clause_in_aprilfool"); | |
+ } | |
+ } | |
+ /* yoku0825 */ | |
+ | |
const char *found_semicolon= parser_state->m_lip.found_semicolon; | |
--- ./sql/sql_class.h.orig 2021-01-05 19:19:59.000000000 +0900 | |
+++ ./sql/sql_class.h 2021-04-01 13:55:47.458828101 +0900 | |
@@ -156,2 +156,3 @@ | |
#define MODE_NO_ENGINE_SUBSTITUTION (MODE_HIGH_NOT_PRECEDENCE*2) | |
+#define MODE_STRICT_PLEASE (MODE_NO_ENGINE_SUBSTITUTION*2) | |
#define MODE_PAD_CHAR_TO_FULL_LENGTH (ULL(1) << 31) | |
@@ -569,2 +570,4 @@ | |
+ my_bool is_pleased; /* yoku0825 */ | |
+ | |
double long_query_time_double; | |
--- ./sql/sys_vars.cc.orig 2021-01-05 19:19:59.000000000 +0900 | |
+++ ./sql/sys_vars.cc 2021-04-01 14:19:46.438828823 +0900 | |
@@ -2912,3 +2912,3 @@ | |
"NO_AUTO_CREATE_USER", "HIGH_NOT_PRECEDENCE", "NO_ENGINE_SUBSTITUTION", | |
- "PAD_CHAR_TO_FULL_LENGTH", | |
+ "STRICT_PLEASE_MODE", "PAD_CHAR_TO_FULL_LENGTH", | |
0 | |
@@ -3400,2 +3400,8 @@ | |
+/* yoku0825 */ | |
+static Sys_var_mybool Sys_is_pleased( | |
+ "is_pleased", "yoku0825", | |
+ SESSION_VAR(is_pleased), NO_CMD_LINE, DEFAULT(FALSE)); | |
+/* yoku0825 */ | |
+ | |
static Sys_var_bit Sys_transaction_allow_batching( | |
--- ./sql/lex.h.orig 2021-01-05 19:19:59.000000000 +0900 | |
+++ ./sql/lex.h 2021-04-01 11:46:05.186445098 +0900 | |
@@ -559,2 +559,3 @@ | |
{ "SSL", SYM(SSL_SYM)}, | |
+ { "PLEASE", SYM(PLEASE_SYM)}, | |
{ "START", SYM(START_SYM)}, |
That's very good idea!
But I don't enough time to improve the feature, because I have only 3 hours April 1st in Japanese Standard Time!
See you next April 1st!! :D
How about some positive reinforcement? Instead of refusing to execute non-polite queries please double the execution speed of polite queries :)
RKajiyama told me an idea "multiply sleep time like a connection_control plugin".
I think this is great idea for "not refusing but slowdown for non-polite queries." ;)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could you also add a "HURRY UP!" one to increase speed of long queries ? it would be nice to reduce the query time of about 50% with that SQL command.
Thank you for you great patch !