diff options
author | Alexey Botchkov <holyfoot@askmonty.org> | 2021-09-13 09:21:47 +0400 |
---|---|---|
committer | Oleksandr Byelkin <sanja@mariadb.com> | 2021-10-19 17:35:06 +0200 |
commit | 585d88a2378112010469fe6d4787f264b70380e8 (patch) | |
tree | f8a8d14f6d9a5f307dac93f562a105f601228fac | |
parent | e1f9a809009313d211b98926f698023aef8e92af (diff) | |
download | mariadb-git-585d88a2378112010469fe6d4787f264b70380e8.tar.gz |
MDEV-19275 SQL service for plugins.
review fixes.
-rw-r--r-- | include/mysql.h | 8 | ||||
-rw-r--r-- | mysql-test/suite/plugins/r/test_sql_service.result | 19 | ||||
-rw-r--r-- | mysql-test/suite/plugins/t/test_sql_service.test | 12 | ||||
-rw-r--r-- | plugin/test_sql_service/test_sql_service.c | 6 | ||||
-rw-r--r-- | sql/sql_prepare.cc | 13 |
5 files changed, 52 insertions, 6 deletions
diff --git a/include/mysql.h b/include/mysql.h index 217725c6576..4490f850f7c 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -322,6 +322,14 @@ typedef struct st_mysql_res { } MYSQL_RES; +/* + We should not define MYSQL_CLIENT when the mysql.h is included + by the server or server plugins. + Now it is important only for the SQL service to work so we rely on + the MYSQL_SERVICE_SQL to check we're compiling the server/plugin + related file. +*/ + #if !defined(MYSQL_SERVICE_SQL) && !defined(MYSQL_CLIENT) #define MYSQL_CLIENT #endif diff --git a/mysql-test/suite/plugins/r/test_sql_service.result b/mysql-test/suite/plugins/r/test_sql_service.result index 494b1131c59..00f0411b665 100644 --- a/mysql-test/suite/plugins/r/test_sql_service.result +++ b/mysql-test/suite/plugins/r/test_sql_service.result @@ -46,6 +46,25 @@ set global test_sql_service_execute_sql_global= 'drop table test.t1'; show status like 'test_sql_query_result'; Variable_name Value Test_sql_query_result Error 1051 returned. Unknown table 'test.t1' +create table t1 (id int, time timestamp); +insert into t1 values (1, NULL), (2, NULL), (3, NULL), (4, NULL), (5, NULL); +set global test_sql_service_execute_sql_global= 'select * FROM test.t1 WHERE time < DATE_SUB(NOW(), interval 5 minute)'; +show status like 'test_sql_query_result'; +Variable_name Value +Test_sql_query_result Query returned 0 rows. +set global test_sql_service_execute_sql_global= 'select * FROM test.t1 WHERE time <= NOW()'; +show status like 'test_sql_query_result'; +Variable_name Value +Test_sql_query_result Query returned 5 rows. +set global test_sql_service_execute_sql_local= 'select * FROM test.t1 WHERE time < DATE_SUB(NOW(), interval 5 minute)'; +show status like 'test_sql_query_result'; +Variable_name Value +Test_sql_query_result Query returned 0 rows. +set global test_sql_service_execute_sql_local= 'select * FROM test.t1 WHERE time <= NOW()'; +show status like 'test_sql_query_result'; +Variable_name Value +Test_sql_query_result Query returned 5 rows. +drop table t1; uninstall plugin test_sql_service; Warnings: Warning 1620 Plugin is busy and will be uninstalled on shutdown diff --git a/mysql-test/suite/plugins/t/test_sql_service.test b/mysql-test/suite/plugins/t/test_sql_service.test index bb3dfb15bf7..b80d78fe6e5 100644 --- a/mysql-test/suite/plugins/t/test_sql_service.test +++ b/mysql-test/suite/plugins/t/test_sql_service.test @@ -44,5 +44,17 @@ show status like 'test_sql_query_result'; set global test_sql_service_execute_sql_global= 'drop table test.t1'; show status like 'test_sql_query_result'; +create table t1 (id int, time timestamp); +insert into t1 values (1, NULL), (2, NULL), (3, NULL), (4, NULL), (5, NULL); +set global test_sql_service_execute_sql_global= 'select * FROM test.t1 WHERE time < DATE_SUB(NOW(), interval 5 minute)'; +show status like 'test_sql_query_result'; +set global test_sql_service_execute_sql_global= 'select * FROM test.t1 WHERE time <= NOW()'; +show status like 'test_sql_query_result'; +set global test_sql_service_execute_sql_local= 'select * FROM test.t1 WHERE time < DATE_SUB(NOW(), interval 5 minute)'; +show status like 'test_sql_query_result'; +set global test_sql_service_execute_sql_local= 'select * FROM test.t1 WHERE time <= NOW()'; +show status like 'test_sql_query_result'; +drop table t1; + uninstall plugin test_sql_service; diff --git a/plugin/test_sql_service/test_sql_service.c b/plugin/test_sql_service/test_sql_service.c index a5e47194df6..c2dbb93bf20 100644 --- a/plugin/test_sql_service/test_sql_service.c +++ b/plugin/test_sql_service/test_sql_service.c @@ -212,8 +212,9 @@ static int run_sql_global(MYSQL_THD thd, struct st_mysql_sys_var *var, void *sav static int init_done= 0; -static int test_sql_service_plugin_init(void *p __attribute__((unused))) +static int test_sql_service_plugin_init(void *p) { + (void) p; global_mysql= mysql_init(NULL); if (!global_mysql || @@ -228,8 +229,9 @@ static int test_sql_service_plugin_init(void *p __attribute__((unused))) } -static int test_sql_service_plugin_deinit(void *p __attribute__((unused))) +static int test_sql_service_plugin_deinit(void *p) { + (void) p; if (!init_done) return 0; diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index fad11c9fbf9..e728afb4242 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -4860,8 +4860,6 @@ Prepared_statement::execute_server_runnable(Server_runnable *server_runnable) Statement stmt_backup; bool error; Query_arena *save_stmt_arena= thd->stmt_arena; - my_time_t save_query_start= thd->query_start(); - ulong save_query_sec= thd->start_time_sec_part; Item_change_list save_change_list; thd->Item_change_list::move_elements_to(&save_change_list); @@ -4871,7 +4869,6 @@ Prepared_statement::execute_server_runnable(Server_runnable *server_runnable) if (!(lex= new (mem_root) st_lex_local)) return TRUE; - thd->set_time(); thd->set_n_backup_statement(this, &stmt_backup); thd->set_n_backup_active_arena(this, &stmt_backup); thd->stmt_arena= this; @@ -4885,7 +4882,6 @@ Prepared_statement::execute_server_runnable(Server_runnable *server_runnable) thd->stmt_arena= save_stmt_arena; save_change_list.move_elements_to(thd); - thd->force_set_time(save_query_start, save_query_sec); /* Items and memory will freed in destructor */ @@ -5613,6 +5609,7 @@ public: MYSQL_FIELD *next_mysql_field; MEM_ROOT *alloc; THD *new_thd; + Security_context empty_ctx; Protocol_local(THD *thd_arg, THD *new_thd_arg, ulong prealloc) : Protocol_text(thd_arg, prealloc), @@ -6225,11 +6222,14 @@ loc_advanced_command(MYSQL *mysql, enum enum_server_command command, else { Ed_connection con(p->thd); + Security_context *ctx_orig= p->thd->security_ctx; MYSQL_LEX_STRING sql_text; DBUG_ASSERT(current_thd == p->thd); sql_text.str= (char *) arg; sql_text.length= arg_length; + p->thd->security_ctx= &p->empty_ctx; result= con.execute_direct(p, sql_text); + p->thd->security_ctx= ctx_orig; } if (skip_check) result= 0; @@ -6397,6 +6397,11 @@ extern "C" MYSQL *mysql_real_connect_local(MYSQL *mysql) p= new Protocol_local(thd_orig, new_thd, 0); if (new_thd) new_thd->protocol= p; + else + { + p->empty_ctx.init(); + p->empty_ctx.skip_grants(); + } mysql->thd= p; mysql->server_status= SERVER_STATUS_AUTOCOMMIT; |