-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
sql_parse.cc
7283 lines (6431 loc) · 241 KB
/
sql_parse.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is also distributed with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have included with MySQL.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#include "sql_parse.h"
#include "auth_common.h" // acl_authenticate
#include "binlog.h" // purge_master_logs
#include "debug_sync.h" // DEBUG_SYNC
#include "events.h" // Events
#include "item_timefunc.h" // Item_func_unix_timestamp
#include "log.h" // query_logger
#include "log_event.h" // slave_execute_deferred_events
#include "mysys_err.h" // EE_CAPACITY_EXCEEDED
#include "opt_explain.h" // mysql_explain_other
#include "opt_trace.h" // Opt_trace_start
#include "partition_info.h" // partition_info
#include "probes_mysql.h" // MYSQL_COMMAND_START
#include "rpl_filter.h" // rpl_filter
#include "rpl_master.h" // register_slave
#include "rpl_rli.h" // mysql_show_relaylog_events
#include "rpl_slave.h" // change_master_cmd
#include "sp.h" // sp_create_routine
#include "sp_cache.h" // sp_cache_enforce_limit
#include "sp_head.h" // sp_head
#include "sql_admin.h" // mysql_assign_to_keycache
#include "sql_analyse.h" // Query_result_analyse
#include "sql_audit.h" // MYSQL_AUDIT_NOTIFY_CONNECTION_CHANGE_USER
#include "sql_base.h" // find_temporary_table
#include "sql_binlog.h" // mysql_client_binlog_statement
#include "sql_cache.h" // query_cache
#include "sql_connect.h" // decrease_user_connections
#include "sql_db.h" // mysql_change_db
#include "sql_delete.h" // mysql_delete
#include "sql_do.h" // mysql_do
#include "sql_handler.h" // mysql_ha_rm_tables
#include "sql_help.h" // mysqld_help
#include "sql_insert.h" // Query_result_create
#include "sql_load.h" // mysql_load
#include "sql_prepare.h" // mysql_stmt_execute
#include "partition_info.h" // has_external_data_or_index_dir
#include "sql_reload.h" // reload_acl_and_cache
#include "sql_rename.h" // mysql_rename_tables
#include "sql_select.h" // handle_query
#include "sql_show.h" // find_schema_table
#include "sql_table.h" // mysql_create_table
#include "sql_tablespace.h" // mysql_alter_tablespace
#include "sql_test.h" // mysql_print_status
#include "sql_select.h" // handle_query
#include "sql_load.h" // mysql_load
#include "sql_servers.h" // create_servers, alter_servers,
// drop_servers, servers_reload
#include "sql_handler.h" // mysql_ha_open, mysql_ha_close,
// mysql_ha_read
#include "sql_binlog.h" // mysql_client_binlog_statement
#include "sql_do.h" // mysql_do
#include "sql_help.h" // mysqld_help
#include "rpl_constants.h" // Incident, INCIDENT_LOST_EVENTS
#include "log_event.h"
#include "rpl_slave.h"
#include "rpl_master.h"
#include "rpl_msr.h" /* Multisource replication */
#include "rpl_filter.h"
#include <m_ctype.h>
#include <myisam.h>
#include <my_dir.h>
#include <dur_prop.h>
#include "rpl_handler.h"
#include "sp_head.h"
#include "sp.h"
#include "sp_cache.h"
#include "events.h"
#include "sql_trigger.h" // mysql_create_or_drop_trigger
#include "transaction.h"
#include "xa.h"
#include "sql_audit.h"
#include "sql_prepare.h"
#include "debug_sync.h"
#include "probes_mysql.h"
#include "set_var.h"
#include "opt_trace.h"
#include "mysql/psi/mysql_statement.h"
#include "opt_explain.h"
#include "sql_rewrite.h"
#include "sql_analyse.h"
#include "table_cache.h" // table_cache_manager
#include "sql_timer.h" // thd_timer_set, thd_timer_reset
#include "sp_rcontext.h"
#include "parse_location.h"
#include "sql_digest.h"
#include "sql_timer.h" // thd_timer_set
#include "sql_trigger.h" // add_table_for_trigger
#include "sql_update.h" // mysql_update
#include "sql_view.h" // mysql_create_view
#include "table_cache.h" // table_cache_manager
#include "transaction.h" // trans_commit_implicit
#include "sql_query_rewrite.h"
#include "rpl_group_replication.h"
#include <algorithm>
using std::max;
/**
@defgroup Runtime_Environment Runtime Environment
@{
*/
/* Used in error handling only */
#define SP_COM_STRING(LP) \
((LP)->sql_command == SQLCOM_CREATE_SPFUNCTION || \
(LP)->sql_command == SQLCOM_ALTER_FUNCTION || \
(LP)->sql_command == SQLCOM_SHOW_CREATE_FUNC || \
(LP)->sql_command == SQLCOM_DROP_FUNCTION ? \
"FUNCTION" : "PROCEDURE")
static void sql_kill(THD *thd, my_thread_id id, bool only_kill_query);
const LEX_STRING command_name[]={
{ C_STRING_WITH_LEN("Sleep") },
{ C_STRING_WITH_LEN("Quit") },
{ C_STRING_WITH_LEN("Init DB") },
{ C_STRING_WITH_LEN("Query") },
{ C_STRING_WITH_LEN("Field List") },
{ C_STRING_WITH_LEN("Create DB") },
{ C_STRING_WITH_LEN("Drop DB") },
{ C_STRING_WITH_LEN("Refresh") },
{ C_STRING_WITH_LEN("Shutdown") },
{ C_STRING_WITH_LEN("Statistics") },
{ C_STRING_WITH_LEN("Processlist") },
{ C_STRING_WITH_LEN("Connect") },
{ C_STRING_WITH_LEN("Kill") },
{ C_STRING_WITH_LEN("Debug") },
{ C_STRING_WITH_LEN("Ping") },
{ C_STRING_WITH_LEN("Time") },
{ C_STRING_WITH_LEN("Delayed insert") },
{ C_STRING_WITH_LEN("Change user") },
{ C_STRING_WITH_LEN("Binlog Dump") },
{ C_STRING_WITH_LEN("Table Dump") },
{ C_STRING_WITH_LEN("Connect Out") },
{ C_STRING_WITH_LEN("Register Slave") },
{ C_STRING_WITH_LEN("Prepare") },
{ C_STRING_WITH_LEN("Execute") },
{ C_STRING_WITH_LEN("Long Data") },
{ C_STRING_WITH_LEN("Close stmt") },
{ C_STRING_WITH_LEN("Reset stmt") },
{ C_STRING_WITH_LEN("Set option") },
{ C_STRING_WITH_LEN("Fetch") },
{ C_STRING_WITH_LEN("Daemon") },
{ C_STRING_WITH_LEN("Binlog Dump GTID") },
{ C_STRING_WITH_LEN("Reset Connection") },
{ C_STRING_WITH_LEN("Error") } // Last command number
};
#ifdef HAVE_REPLICATION
/**
Returns true if all tables should be ignored.
*/
bool all_tables_not_ok(THD *thd, TABLE_LIST *tables)
{
return rpl_filter->is_on() && tables && !thd->sp_runtime_ctx &&
!rpl_filter->tables_ok(thd->db().str, tables);
}
/**
Checks whether the event for the given database, db, should
be ignored or not. This is done by checking whether there are
active rules in ignore_db or in do_db containers. If there
are, then check if there is a match, if not then check the
wild_do rules.
NOTE: This means that when using this function replicate-do-db
and replicate-ignore-db take precedence over wild do
rules.
@param thd Thread handle.
@param db Database name used while evaluating the filtering
rules.
@param sql_cmd Represents the current query that needs to be
verified against the database filter rules.
@return TRUE Query should not be filtered out from the execution.
FALSE Query should be filtered out from the execution.
*/
inline bool check_database_filters(THD *thd, const char* db, enum_sql_command sql_cmd)
{
DBUG_ENTER("check_database_filters");
assert(thd->slave_thread);
if (!db)
DBUG_RETURN(TRUE);
switch (sql_cmd)
{
case SQLCOM_BEGIN:
case SQLCOM_COMMIT:
case SQLCOM_SAVEPOINT:
case SQLCOM_ROLLBACK:
case SQLCOM_ROLLBACK_TO_SAVEPOINT:
DBUG_RETURN(TRUE);
default:
break;
}
bool db_ok= rpl_filter->db_ok(db);
/*
No filters exist in ignore/do_db ? Then, just check
wild_do_table filtering for 'DATABASE' related
statements (CREATE/DROP/ATLER DATABASE)
*/
if (db_ok &&
(rpl_filter->get_do_db()->is_empty() &&
rpl_filter->get_ignore_db()->is_empty()))
{
switch (sql_cmd)
{
case SQLCOM_CREATE_DB:
case SQLCOM_ALTER_DB:
case SQLCOM_ALTER_DB_UPGRADE:
case SQLCOM_DROP_DB:
db_ok= rpl_filter->db_ok_with_wild_table(db);
default:
break;
}
}
DBUG_RETURN(db_ok);
}
#endif
bool some_non_temp_table_to_be_updated(THD *thd, TABLE_LIST *tables)
{
for (TABLE_LIST *table= tables; table; table= table->next_global)
{
assert(table->db && table->table_name);
/*
Update on performance_schema and temp tables are allowed
in readonly mode.
*/
if (table->updating && !find_temporary_table(thd, table) &&
!is_perfschema_db(table->db, table->db_length))
return 1;
}
return 0;
}
/*
Implicitly commit a active transaction if statement requires so.
@param thd Thread handle.
@param mask Bitmask used for the SQL command match.
*/
bool stmt_causes_implicit_commit(const THD *thd, uint mask)
{
const LEX *lex= thd->lex;
bool skip= FALSE;
DBUG_ENTER("stmt_causes_implicit_commit");
if (!(sql_command_flags[lex->sql_command] & mask))
DBUG_RETURN(FALSE);
switch (lex->sql_command) {
case SQLCOM_DROP_TABLE:
skip= lex->drop_temporary;
break;
case SQLCOM_ALTER_TABLE:
case SQLCOM_CREATE_TABLE:
/* If CREATE TABLE of non-temporary table, do implicit commit */
skip= (lex->create_info.options & HA_LEX_CREATE_TMP_TABLE);
break;
case SQLCOM_SET_OPTION:
/* Implicitly commit a transaction started by a SET statement */
skip= lex->autocommit ? FALSE : TRUE;
break;
default:
break;
}
DBUG_RETURN(!skip);
}
/**
Mark all commands that somehow changes a table.
This is used to check number of updates / hour.
sql_command is actually set to SQLCOM_END sometimes
so we need the +1 to include it in the array.
See COMMAND_FLAG_xxx for different type of commands
2 - query that returns meaningful ROW_COUNT() -
a number of modified rows
*/
uint sql_command_flags[SQLCOM_END+1];
uint server_command_flags[COM_END+1];
void init_update_queries(void)
{
/* Initialize the server command flags array. */
memset(server_command_flags, 0, sizeof(server_command_flags));
server_command_flags[COM_SLEEP]= CF_ALLOW_PROTOCOL_PLUGIN;
server_command_flags[COM_INIT_DB]= CF_ALLOW_PROTOCOL_PLUGIN;
server_command_flags[COM_QUERY]= CF_ALLOW_PROTOCOL_PLUGIN;
server_command_flags[COM_FIELD_LIST]= CF_ALLOW_PROTOCOL_PLUGIN;
server_command_flags[COM_REFRESH]= CF_ALLOW_PROTOCOL_PLUGIN;
server_command_flags[COM_SHUTDOWN]= CF_ALLOW_PROTOCOL_PLUGIN;
server_command_flags[COM_STATISTICS]= CF_SKIP_QUESTIONS;
server_command_flags[COM_PROCESS_KILL]= CF_ALLOW_PROTOCOL_PLUGIN;
server_command_flags[COM_PING]= CF_SKIP_QUESTIONS;
server_command_flags[COM_STMT_PREPARE]= CF_SKIP_QUESTIONS |
CF_ALLOW_PROTOCOL_PLUGIN;
server_command_flags[COM_STMT_EXECUTE]= CF_ALLOW_PROTOCOL_PLUGIN;
server_command_flags[COM_STMT_SEND_LONG_DATA]= CF_ALLOW_PROTOCOL_PLUGIN;
server_command_flags[COM_STMT_CLOSE]= CF_SKIP_QUESTIONS |
CF_ALLOW_PROTOCOL_PLUGIN;
server_command_flags[COM_STMT_RESET]= CF_SKIP_QUESTIONS |
CF_ALLOW_PROTOCOL_PLUGIN;
server_command_flags[COM_STMT_FETCH]= CF_ALLOW_PROTOCOL_PLUGIN;
server_command_flags[COM_END]= CF_ALLOW_PROTOCOL_PLUGIN;
/* Initialize the sql command flags array. */
memset(sql_command_flags, 0, sizeof(sql_command_flags));
/*
In general, DDL statements do not generate row events and do not go
through a cache before being written to the binary log. However, the
CREATE TABLE...SELECT is an exception because it may generate row
events. For that reason, the SQLCOM_CREATE_TABLE which represents
a CREATE TABLE, including the CREATE TABLE...SELECT, has the
CF_CAN_GENERATE_ROW_EVENTS flag. The distinction between a regular
CREATE TABLE and the CREATE TABLE...SELECT is made in other parts of
the code, in particular in the Query_log_event's constructor.
*/
sql_command_flags[SQLCOM_CREATE_TABLE]= CF_CHANGES_DATA | CF_REEXECUTION_FRAGILE |
CF_AUTO_COMMIT_TRANS |
CF_CAN_GENERATE_ROW_EVENTS;
sql_command_flags[SQLCOM_CREATE_INDEX]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_ALTER_TABLE]= CF_CHANGES_DATA | CF_WRITE_LOGS_COMMAND |
CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_TRUNCATE]= CF_CHANGES_DATA | CF_WRITE_LOGS_COMMAND |
CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_DROP_TABLE]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_LOAD]= CF_CHANGES_DATA | CF_REEXECUTION_FRAGILE |
CF_CAN_GENERATE_ROW_EVENTS;
sql_command_flags[SQLCOM_CREATE_DB]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_DROP_DB]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_ALTER_DB_UPGRADE]= CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_ALTER_DB]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_RENAME_TABLE]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_DROP_INDEX]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_CREATE_VIEW]= CF_CHANGES_DATA | CF_REEXECUTION_FRAGILE |
CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_DROP_VIEW]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_CREATE_TRIGGER]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_DROP_TRIGGER]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_CREATE_EVENT]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_ALTER_EVENT]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_DROP_EVENT]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_UPDATE]= CF_CHANGES_DATA | CF_REEXECUTION_FRAGILE |
CF_CAN_GENERATE_ROW_EVENTS |
CF_OPTIMIZER_TRACE |
CF_CAN_BE_EXPLAINED;
sql_command_flags[SQLCOM_UPDATE_MULTI]= CF_CHANGES_DATA | CF_REEXECUTION_FRAGILE |
CF_CAN_GENERATE_ROW_EVENTS |
CF_OPTIMIZER_TRACE |
CF_CAN_BE_EXPLAINED;
// This is INSERT VALUES(...), can be VALUES(stored_func()) so we trace it
sql_command_flags[SQLCOM_INSERT]= CF_CHANGES_DATA | CF_REEXECUTION_FRAGILE |
CF_CAN_GENERATE_ROW_EVENTS |
CF_OPTIMIZER_TRACE |
CF_CAN_BE_EXPLAINED;
sql_command_flags[SQLCOM_INSERT_SELECT]= CF_CHANGES_DATA | CF_REEXECUTION_FRAGILE |
CF_CAN_GENERATE_ROW_EVENTS |
CF_OPTIMIZER_TRACE |
CF_CAN_BE_EXPLAINED;
sql_command_flags[SQLCOM_DELETE]= CF_CHANGES_DATA | CF_REEXECUTION_FRAGILE |
CF_CAN_GENERATE_ROW_EVENTS |
CF_OPTIMIZER_TRACE |
CF_CAN_BE_EXPLAINED;
sql_command_flags[SQLCOM_DELETE_MULTI]= CF_CHANGES_DATA | CF_REEXECUTION_FRAGILE |
CF_CAN_GENERATE_ROW_EVENTS |
CF_OPTIMIZER_TRACE |
CF_CAN_BE_EXPLAINED;
sql_command_flags[SQLCOM_REPLACE]= CF_CHANGES_DATA | CF_REEXECUTION_FRAGILE |
CF_CAN_GENERATE_ROW_EVENTS |
CF_OPTIMIZER_TRACE |
CF_CAN_BE_EXPLAINED;
sql_command_flags[SQLCOM_REPLACE_SELECT]= CF_CHANGES_DATA | CF_REEXECUTION_FRAGILE |
CF_CAN_GENERATE_ROW_EVENTS |
CF_OPTIMIZER_TRACE |
CF_CAN_BE_EXPLAINED;
sql_command_flags[SQLCOM_SELECT]= CF_REEXECUTION_FRAGILE |
CF_CAN_GENERATE_ROW_EVENTS |
CF_OPTIMIZER_TRACE |
CF_CAN_BE_EXPLAINED;
// (1) so that subquery is traced when doing "SET @var = (subquery)"
/*
@todo SQLCOM_SET_OPTION should have CF_CAN_GENERATE_ROW_EVENTS
set, because it may invoke a stored function that generates row
events. /Sven
*/
sql_command_flags[SQLCOM_SET_OPTION]= CF_REEXECUTION_FRAGILE |
CF_AUTO_COMMIT_TRANS |
CF_CAN_GENERATE_ROW_EVENTS |
CF_OPTIMIZER_TRACE; // (1)
// (1) so that subquery is traced when doing "DO @var := (subquery)"
sql_command_flags[SQLCOM_DO]= CF_REEXECUTION_FRAGILE |
CF_CAN_GENERATE_ROW_EVENTS |
CF_OPTIMIZER_TRACE; // (1)
sql_command_flags[SQLCOM_SHOW_STATUS_PROC]= CF_STATUS_COMMAND | CF_REEXECUTION_FRAGILE;
sql_command_flags[SQLCOM_SHOW_STATUS]= CF_STATUS_COMMAND | CF_REEXECUTION_FRAGILE;
sql_command_flags[SQLCOM_SHOW_DATABASES]= CF_STATUS_COMMAND | CF_REEXECUTION_FRAGILE;
sql_command_flags[SQLCOM_SHOW_TRIGGERS]= CF_STATUS_COMMAND | CF_REEXECUTION_FRAGILE;
sql_command_flags[SQLCOM_SHOW_EVENTS]= CF_STATUS_COMMAND | CF_REEXECUTION_FRAGILE;
sql_command_flags[SQLCOM_SHOW_OPEN_TABLES]= CF_STATUS_COMMAND | CF_REEXECUTION_FRAGILE;
sql_command_flags[SQLCOM_SHOW_PLUGINS]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_FIELDS]= CF_STATUS_COMMAND | CF_REEXECUTION_FRAGILE;
sql_command_flags[SQLCOM_SHOW_KEYS]= CF_STATUS_COMMAND | CF_REEXECUTION_FRAGILE;
sql_command_flags[SQLCOM_SHOW_VARIABLES]= CF_STATUS_COMMAND | CF_REEXECUTION_FRAGILE;
sql_command_flags[SQLCOM_SHOW_CHARSETS]= CF_STATUS_COMMAND | CF_REEXECUTION_FRAGILE;
sql_command_flags[SQLCOM_SHOW_COLLATIONS]= CF_STATUS_COMMAND | CF_REEXECUTION_FRAGILE;
sql_command_flags[SQLCOM_SHOW_BINLOGS]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_SLAVE_HOSTS]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_BINLOG_EVENTS]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_STORAGE_ENGINES]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_PRIVILEGES]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_WARNS]= CF_STATUS_COMMAND | CF_DIAGNOSTIC_STMT;
sql_command_flags[SQLCOM_SHOW_ERRORS]= CF_STATUS_COMMAND | CF_DIAGNOSTIC_STMT;
sql_command_flags[SQLCOM_SHOW_ENGINE_STATUS]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_ENGINE_MUTEX]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_ENGINE_LOGS]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_PROCESSLIST]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_GRANTS]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_CREATE_DB]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_CREATE]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_MASTER_STAT]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_SLAVE_STAT]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_CREATE_PROC]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_CREATE_FUNC]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_CREATE_TRIGGER]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_STATUS_FUNC]= CF_STATUS_COMMAND | CF_REEXECUTION_FRAGILE;
sql_command_flags[SQLCOM_SHOW_PROC_CODE]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_FUNC_CODE]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_CREATE_EVENT]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_PROFILES]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_PROFILE]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_BINLOG_BASE64_EVENT]= CF_STATUS_COMMAND |
CF_CAN_GENERATE_ROW_EVENTS;
sql_command_flags[SQLCOM_SHOW_TABLES]= (CF_STATUS_COMMAND |
CF_SHOW_TABLE_COMMAND |
CF_REEXECUTION_FRAGILE);
sql_command_flags[SQLCOM_SHOW_TABLE_STATUS]= (CF_STATUS_COMMAND |
CF_SHOW_TABLE_COMMAND |
CF_REEXECUTION_FRAGILE);
sql_command_flags[SQLCOM_CREATE_USER]= CF_CHANGES_DATA;
sql_command_flags[SQLCOM_RENAME_USER]= CF_CHANGES_DATA;
sql_command_flags[SQLCOM_DROP_USER]= CF_CHANGES_DATA;
sql_command_flags[SQLCOM_ALTER_USER]= CF_CHANGES_DATA;
sql_command_flags[SQLCOM_GRANT]= CF_CHANGES_DATA;
sql_command_flags[SQLCOM_REVOKE]= CF_CHANGES_DATA;
sql_command_flags[SQLCOM_REVOKE_ALL]= CF_CHANGES_DATA;
sql_command_flags[SQLCOM_OPTIMIZE]= CF_CHANGES_DATA;
sql_command_flags[SQLCOM_ALTER_INSTANCE]= CF_CHANGES_DATA;
sql_command_flags[SQLCOM_CREATE_FUNCTION]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_CREATE_PROCEDURE]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_CREATE_SPFUNCTION]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_DROP_PROCEDURE]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_DROP_FUNCTION]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_ALTER_PROCEDURE]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_ALTER_FUNCTION]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_INSTALL_PLUGIN]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_UNINSTALL_PLUGIN]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS;
/* Does not change the contents of the Diagnostics Area. */
sql_command_flags[SQLCOM_GET_DIAGNOSTICS]= CF_DIAGNOSTIC_STMT;
/*
(1): without it, in "CALL some_proc((subq))", subquery would not be
traced.
*/
sql_command_flags[SQLCOM_CALL]= CF_REEXECUTION_FRAGILE |
CF_CAN_GENERATE_ROW_EVENTS |
CF_OPTIMIZER_TRACE; // (1)
sql_command_flags[SQLCOM_EXECUTE]= CF_CAN_GENERATE_ROW_EVENTS;
/*
The following admin table operations are allowed
on log tables.
*/
sql_command_flags[SQLCOM_REPAIR]= CF_WRITE_LOGS_COMMAND | CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_OPTIMIZE]|= CF_WRITE_LOGS_COMMAND | CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_ANALYZE]= CF_WRITE_LOGS_COMMAND | CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_CHECK]= CF_WRITE_LOGS_COMMAND | CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_CREATE_USER]|= CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_DROP_USER]|= CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_RENAME_USER]|= CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_ALTER_USER]|= CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_REVOKE]|= CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_REVOKE_ALL]|= CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_GRANT]|= CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_ASSIGN_TO_KEYCACHE]= CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_PRELOAD_KEYS]= CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_ALTER_INSTANCE]|= CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_FLUSH]= CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_RESET]= CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_CREATE_SERVER]= CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_ALTER_SERVER]= CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_DROP_SERVER]= CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_CHANGE_MASTER]= CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_CHANGE_REPLICATION_FILTER]= CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_SLAVE_START]= CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_SLAVE_STOP]= CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_ALTER_TABLESPACE]|= CF_AUTO_COMMIT_TRANS;
/*
The following statements can deal with temporary tables,
so temporary tables should be pre-opened for those statements to
simplify privilege checking.
There are other statements that deal with temporary tables and open
them, but which are not listed here. The thing is that the order of
pre-opening temporary tables for those statements is somewhat custom.
*/
sql_command_flags[SQLCOM_CREATE_TABLE]|= CF_PREOPEN_TMP_TABLES;
sql_command_flags[SQLCOM_DROP_TABLE]|= CF_PREOPEN_TMP_TABLES;
sql_command_flags[SQLCOM_CREATE_INDEX]|= CF_PREOPEN_TMP_TABLES;
sql_command_flags[SQLCOM_ALTER_TABLE]|= CF_PREOPEN_TMP_TABLES;
sql_command_flags[SQLCOM_TRUNCATE]|= CF_PREOPEN_TMP_TABLES;
sql_command_flags[SQLCOM_LOAD]|= CF_PREOPEN_TMP_TABLES;
sql_command_flags[SQLCOM_DROP_INDEX]|= CF_PREOPEN_TMP_TABLES;
sql_command_flags[SQLCOM_UPDATE]|= CF_PREOPEN_TMP_TABLES;
sql_command_flags[SQLCOM_UPDATE_MULTI]|= CF_PREOPEN_TMP_TABLES;
sql_command_flags[SQLCOM_INSERT_SELECT]|= CF_PREOPEN_TMP_TABLES;
sql_command_flags[SQLCOM_DELETE]|= CF_PREOPEN_TMP_TABLES;
sql_command_flags[SQLCOM_DELETE_MULTI]|= CF_PREOPEN_TMP_TABLES;
sql_command_flags[SQLCOM_REPLACE_SELECT]|= CF_PREOPEN_TMP_TABLES;
sql_command_flags[SQLCOM_SELECT]|= CF_PREOPEN_TMP_TABLES;
sql_command_flags[SQLCOM_SET_OPTION]|= CF_PREOPEN_TMP_TABLES;
sql_command_flags[SQLCOM_DO]|= CF_PREOPEN_TMP_TABLES;
sql_command_flags[SQLCOM_CALL]|= CF_PREOPEN_TMP_TABLES;
sql_command_flags[SQLCOM_CHECKSUM]|= CF_PREOPEN_TMP_TABLES;
sql_command_flags[SQLCOM_ANALYZE]|= CF_PREOPEN_TMP_TABLES;
sql_command_flags[SQLCOM_CHECK]|= CF_PREOPEN_TMP_TABLES;
sql_command_flags[SQLCOM_OPTIMIZE]|= CF_PREOPEN_TMP_TABLES;
sql_command_flags[SQLCOM_REPAIR]|= CF_PREOPEN_TMP_TABLES;
sql_command_flags[SQLCOM_PRELOAD_KEYS]|= CF_PREOPEN_TMP_TABLES;
sql_command_flags[SQLCOM_ASSIGN_TO_KEYCACHE]|= CF_PREOPEN_TMP_TABLES;
/*
DDL statements that should start with closing opened handlers.
We use this flag only for statements for which open HANDLERs
have to be closed before emporary tables are pre-opened.
*/
sql_command_flags[SQLCOM_CREATE_TABLE]|= CF_HA_CLOSE;
sql_command_flags[SQLCOM_DROP_TABLE]|= CF_HA_CLOSE;
sql_command_flags[SQLCOM_ALTER_TABLE]|= CF_HA_CLOSE;
sql_command_flags[SQLCOM_TRUNCATE]|= CF_HA_CLOSE;
sql_command_flags[SQLCOM_REPAIR]|= CF_HA_CLOSE;
sql_command_flags[SQLCOM_OPTIMIZE]|= CF_HA_CLOSE;
sql_command_flags[SQLCOM_ANALYZE]|= CF_HA_CLOSE;
sql_command_flags[SQLCOM_CHECK]|= CF_HA_CLOSE;
sql_command_flags[SQLCOM_CREATE_INDEX]|= CF_HA_CLOSE;
sql_command_flags[SQLCOM_DROP_INDEX]|= CF_HA_CLOSE;
sql_command_flags[SQLCOM_PRELOAD_KEYS]|= CF_HA_CLOSE;
sql_command_flags[SQLCOM_ASSIGN_TO_KEYCACHE]|= CF_HA_CLOSE;
/*
Mark statements that always are disallowed in read-only
transactions. Note that according to the SQL standard,
even temporary table DDL should be disallowed.
*/
sql_command_flags[SQLCOM_CREATE_TABLE]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_ALTER_TABLE]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_DROP_TABLE]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_RENAME_TABLE]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_CREATE_INDEX]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_DROP_INDEX]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_CREATE_DB]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_DROP_DB]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_ALTER_DB_UPGRADE]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_ALTER_DB]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_CREATE_VIEW]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_DROP_VIEW]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_CREATE_TRIGGER]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_DROP_TRIGGER]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_CREATE_EVENT]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_ALTER_EVENT]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_DROP_EVENT]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_CREATE_USER]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_RENAME_USER]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_ALTER_USER]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_DROP_USER]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_CREATE_SERVER]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_ALTER_SERVER]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_DROP_SERVER]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_CREATE_FUNCTION]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_CREATE_PROCEDURE]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_CREATE_SPFUNCTION]|=CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_DROP_PROCEDURE]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_DROP_FUNCTION]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_ALTER_PROCEDURE]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_ALTER_FUNCTION]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_TRUNCATE]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_ALTER_TABLESPACE]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_REPAIR]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_OPTIMIZE]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_GRANT]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_REVOKE]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_REVOKE_ALL]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_INSTALL_PLUGIN]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_UNINSTALL_PLUGIN]|= CF_DISALLOW_IN_RO_TRANS;
sql_command_flags[SQLCOM_ALTER_INSTANCE]|= CF_DISALLOW_IN_RO_TRANS;
/*
Mark statements that are allowed to be executed by the plugins.
*/
sql_command_flags[SQLCOM_SELECT]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_CREATE_TABLE]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_CREATE_INDEX]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_ALTER_TABLE]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_UPDATE]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_INSERT]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_INSERT_SELECT]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_DELETE]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_TRUNCATE]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_DROP_TABLE]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_DROP_INDEX]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_DATABASES]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_TABLES]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_FIELDS]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_KEYS]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_VARIABLES]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_STATUS]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_ENGINE_LOGS]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_ENGINE_STATUS]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_ENGINE_MUTEX]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_PROCESSLIST]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_MASTER_STAT]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_SLAVE_STAT]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_GRANTS]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_CREATE]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_CHARSETS]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_COLLATIONS]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_CREATE_DB]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_TABLE_STATUS]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_TRIGGERS]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_LOAD]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SET_OPTION]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_LOCK_TABLES]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_UNLOCK_TABLES]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_GRANT]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_CHANGE_DB]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_CREATE_DB]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_DROP_DB]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_ALTER_DB]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_REPAIR]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_REPLACE]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_REPLACE_SELECT]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_CREATE_FUNCTION]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_DROP_FUNCTION]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_REVOKE]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_OPTIMIZE]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_CHECK]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_ASSIGN_TO_KEYCACHE]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_PRELOAD_KEYS]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_FLUSH]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_KILL]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_ANALYZE]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_ROLLBACK]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_ROLLBACK_TO_SAVEPOINT]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_COMMIT]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SAVEPOINT]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_RELEASE_SAVEPOINT]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SLAVE_START]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SLAVE_STOP]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_BEGIN]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_CHANGE_MASTER]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_CHANGE_REPLICATION_FILTER]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_RENAME_TABLE]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_RESET]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_PURGE]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_PURGE_BEFORE]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_BINLOGS]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_OPEN_TABLES]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_HA_OPEN]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_HA_CLOSE]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_HA_READ]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_SLAVE_HOSTS]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_DELETE_MULTI]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_UPDATE_MULTI]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_BINLOG_EVENTS]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_DO]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_WARNS]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_EMPTY_QUERY]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_ERRORS]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_STORAGE_ENGINES]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_PRIVILEGES]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_HELP]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_CREATE_USER]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_DROP_USER]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_RENAME_USER]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_REVOKE_ALL]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_CHECKSUM]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_CREATE_PROCEDURE]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_CREATE_SPFUNCTION]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_CALL]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_DROP_PROCEDURE]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_ALTER_PROCEDURE]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_ALTER_FUNCTION]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_CREATE_PROC]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_CREATE_FUNC]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_STATUS_PROC]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_STATUS_FUNC]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_PREPARE]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_EXECUTE]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_DEALLOCATE_PREPARE]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_CREATE_VIEW]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_DROP_VIEW]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_CREATE_TRIGGER]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_DROP_TRIGGER]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_XA_START]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_XA_END]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_XA_PREPARE]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_XA_COMMIT]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_XA_ROLLBACK]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_XA_RECOVER]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_PROC_CODE]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_FUNC_CODE]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_ALTER_TABLESPACE]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_BINLOG_BASE64_EVENT]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_PLUGINS]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_CREATE_SERVER]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_DROP_SERVER]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_ALTER_SERVER]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_CREATE_EVENT]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_ALTER_EVENT]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_DROP_EVENT]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_CREATE_EVENT]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_EVENTS]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_CREATE_TRIGGER]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_ALTER_DB_UPGRADE]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_PROFILE]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_PROFILES]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SIGNAL]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_RESIGNAL]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_RELAYLOG_EVENTS]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_GET_DIAGNOSTICS]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_ALTER_USER]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_EXPLAIN_OTHER]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_SHOW_CREATE_USER]|= CF_ALLOW_PROTOCOL_PLUGIN;
sql_command_flags[SQLCOM_END]|= CF_ALLOW_PROTOCOL_PLUGIN;
}
bool sqlcom_can_generate_row_events(enum enum_sql_command command)
{
return (sql_command_flags[command] & CF_CAN_GENERATE_ROW_EVENTS);
}
bool is_update_query(enum enum_sql_command command)
{
assert(command >= 0 && command <= SQLCOM_END);
return (sql_command_flags[command] & CF_CHANGES_DATA) != 0;
}
bool is_explainable_query(enum enum_sql_command command)
{
assert(command >= 0 && command <= SQLCOM_END);
return (sql_command_flags[command] & CF_CAN_BE_EXPLAINED) != 0;
}
/**
Check if a sql command is allowed to write to log tables.
@param command The SQL command
@return true if writing is allowed
*/
bool is_log_table_write_query(enum enum_sql_command command)
{
assert(command >= 0 && command <= SQLCOM_END);
return (sql_command_flags[command] & CF_WRITE_LOGS_COMMAND) != 0;
}
void execute_init_command(THD *thd, LEX_STRING *init_command,
mysql_rwlock_t *var_lock)
{
Protocol_classic *protocol= thd->get_protocol_classic();
Vio* save_vio;
ulong save_client_capabilities;
COM_DATA com_data;
mysql_rwlock_rdlock(var_lock);
if (!init_command->length)
{
mysql_rwlock_unlock(var_lock);
return;
}
/*
copy the value under a lock, and release the lock.
init_command has to be executed without a lock held,
as it may try to change itself
*/
size_t len= init_command->length;
char *buf= thd->strmake(init_command->str, len);
mysql_rwlock_unlock(var_lock);
#if defined(ENABLED_PROFILING)
thd->profiling.start_new_query();
thd->profiling.set_query_source(buf, len);
#endif
THD_STAGE_INFO(thd, stage_execution_of_init_command);
save_client_capabilities= protocol->get_client_capabilities();
protocol->add_client_capability(CLIENT_MULTI_QUERIES);
/*
We don't need return result of execution to client side.
To forbid this we should set thd->net.vio to 0.
*/
save_vio= protocol->get_vio();
protocol->set_vio(NULL);
protocol->create_command(&com_data, COM_QUERY, (uchar *) buf, len);
dispatch_command(thd, &com_data, COM_QUERY);
protocol->set_client_capabilities(save_client_capabilities);
protocol->set_vio(save_vio);
#if defined(ENABLED_PROFILING)
thd->profiling.finish_current_query();
#endif
}
/* This works because items are allocated with sql_alloc() */
void free_items(Item *item)
{
Item *next;
DBUG_ENTER("free_items");
for (; item ; item=next)
{
next=item->next;
item->delete_self();
}
DBUG_VOID_RETURN;
}
/**
This works because items are allocated with sql_alloc().
@note The function also handles null pointers (empty list).
*/
void cleanup_items(Item *item)
{
DBUG_ENTER("cleanup_items");
for (; item ; item=item->next)
item->cleanup();
DBUG_VOID_RETURN;
}
#ifndef EMBEDDED_LIBRARY
/**
Read one command from connection and execute it (query or simple command).
This function is called in loop from thread function.
For profiling to work, it must never be called recursively.
@retval
0 success
@retval
1 request of thread shutdown (see dispatch_command() description)
*/
bool do_command(THD *thd)
{
bool return_value;
int rc;
const bool classic=
(thd->get_protocol()->type() == Protocol::PROTOCOL_TEXT ||
thd->get_protocol()->type() == Protocol::PROTOCOL_BINARY);
NET *net= NULL;
enum enum_server_command command;
COM_DATA com_data;
DBUG_ENTER("do_command");
/*
indicator of uninitialized lex => normal flow of errors handling
(see my_message_sql)
*/
thd->lex->set_current_select(0);
/*
XXX: this code is here only to clear possible errors of init_connect.
Consider moving to prepare_new_connection_state() instead.
That requires making sure the DA is cleared before non-parsing statements
such as COM_QUIT.
*/
thd->clear_error(); // Clear error message
thd->get_stmt_da()->reset_diagnostics_area();
if (classic)
{
/*
This thread will do a blocking read from the client which
will be interrupted when the next command is received from
the client, the connection is closed or "net_wait_timeout"
number of seconds has passed.
*/
net= thd->get_protocol_classic()->get_net();
my_net_set_read_timeout(net, thd->variables.net_wait_timeout);
net_new_transaction(net);
}
/*
Synchronization point for testing of KILL_CONNECTION.
This sync point can wait here, to simulate slow code execution
between the last test of thd->killed and blocking in read().
The goal of this test is to verify that a connection does not
hang, if it is killed at this point of execution.
(Bug#37780 - main.kill fails randomly)
Note that the sync point wait itself will be terminated by a
kill. In this case it consumes a condition broadcast, but does
not change anything else. The consumed broadcast should not
matter here, because the read/recv() below doesn't use it.
*/
DEBUG_SYNC(thd, "before_do_command_net_read");
/*
Because of networking layer callbacks in place,
this call will maintain the following instrumentation:
- IDLE events
- SOCKET events
- STATEMENT events
- STAGE events
when reading a new network packet.
In particular, a new instrumented statement is started.
See init_net_server_extension()
*/
thd->m_server_idle= true;
rc= thd->get_protocol()->get_command(&com_data, &command);
thd->m_server_idle= false;
if (rc)
{
if (classic)
{
DBUG_PRINT("info",("Got error %d reading command from socket %s",
net->error,
vio_description(net->vio)));
}
else
{
DBUG_PRINT("info",("Got error %d reading command from %s protocol",
rc,
(thd->get_protocol()->type() ==
Protocol::PROTOCOL_LOCAL) ? "local" : "plugin"));
}
/* Instrument this broken statement as "statement/com/error" */
thd->m_statement_psi= MYSQL_REFINE_STATEMENT(thd->m_statement_psi,
com_statement_info[COM_END].m_key);
/* Check if we can continue without closing the connection */
/* The error must be set. */
assert(thd->is_error());
thd->send_statement_status();
/* Mark the statement completed. */
MYSQL_END_STATEMENT(thd->m_statement_psi, thd->get_stmt_da());
thd->m_statement_psi= NULL;