Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
585d88a2
Commit
585d88a2
authored
Sep 13, 2021
by
Alexey Botchkov
Committed by
Oleksandr Byelkin
Oct 19, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-19275 SQL service for plugins.
review fixes.
parent
e1f9a809
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
52 additions
and
6 deletions
+52
-6
include/mysql.h
include/mysql.h
+8
-0
mysql-test/suite/plugins/r/test_sql_service.result
mysql-test/suite/plugins/r/test_sql_service.result
+19
-0
mysql-test/suite/plugins/t/test_sql_service.test
mysql-test/suite/plugins/t/test_sql_service.test
+12
-0
plugin/test_sql_service/test_sql_service.c
plugin/test_sql_service/test_sql_service.c
+4
-2
sql/sql_prepare.cc
sql/sql_prepare.cc
+9
-4
No files found.
include/mysql.h
View file @
585d88a2
...
...
@@ -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
...
...
mysql-test/suite/plugins/r/test_sql_service.result
View file @
585d88a2
...
...
@@ -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
mysql-test/suite/plugins/t/test_sql_service.test
View file @
585d88a2
...
...
@@ -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
;
plugin/test_sql_service/test_sql_service.c
View file @
585d88a2
...
...
@@ -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
;
...
...
sql/sql_prepare.cc
View file @
585d88a2
...
...
@@ -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 @@ class Protocol_local : public Protocol_text
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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment