~ubuntu-branches/ubuntu/vivid/drizzle/vivid-proposed

« back to all changes in this revision

Viewing changes to tests/randgen/conf/runtime/WL5004_sql.yy

  • Committer: Package Import Robot
  • Author(s): Tobias Frost
  • Date: 2013-08-22 20:18:31 UTC
  • mto: (20.1.1 sid)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: package-import@ubuntu.com-20130822201831-gn3ozsh7o7wmc5tk
Tags: upstream-7.2.3
ImportĀ upstreamĀ versionĀ 7.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
2
 
#
3
 
# This program is free software; you can redistribute it and/or modify
4
 
# it under the terms of the GNU General Public License as published by
5
 
# the Free Software Foundation; version 2 of the License.
6
 
#
7
 
# This program is distributed in the hope that it will be useful,
8
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 
# GNU General Public License for more details.
11
 
#
12
 
# You should have received a copy of the GNU General Public License
13
 
# along with this program; if not, write to the Free Software Foundation,
14
 
# 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
15
 
 
16
 
# Grammar for testing DML, DDL, FLUSH, LOCK/UNLOCK, transactions
17
 
#
18
 
# Created:
19
 
#    2009-07 Matthias Leich
20
 
#            WL#5004 Comprehensive Locking Stress Test for Azalea
21
 
#                    A few grammar rules were taken from other grammar files.
22
 
# Last Modifications:
23
 
#    2011-03 Matthias Leich
24
 
#               Prevent the generation of SHOW PROCEDURE/FUNCTION CODE in case
25
 
#               we do not have a server compiled with debug
26
 
#
27
 
# Attention:
28
 
# 1. There are modified grammar rules because of open bugs.
29
 
#    Please search case insensitive for "disable".
30
 
# 2. Some locking statements will get an syntax error as long as
31
 
#       WL#3561 transactional LOCK TABLE
32
 
#    is not pushed.
33
 
#
34
 
# TODO:
35
 
#   - Adjust grammar to new open and old fixed bugs
36
 
#   - Add TRUNCATE PARTITION and check if we are missing any other related DDL.
37
 
#     (Bug#49907 ALTER TABLE ... TRUNCATE PARTITION does not wait for locks on the table)
38
 
#     (2010-05 Analysing + should be fixed by patch for
39
 
#     (Bug#42643 InnoDB does not support replication of TRUNCATE TABLE)
40
 
#     (2010-05 Patch pending)
41
 
#   - Add the corresponding DDL when
42
 
#        WL#4445 Import/Export tables to/from partitioned tables
43
 
#     is ready for testing
44
 
#   - Check the impact of the latest modifications (use "used_select" less often) on the issues
45
 
#     reported by Philip
46
 
#        When using greater values for namespace_width
47
 
#        - the database never actually gets the expected number of objects.
48
 
#          Even if the DROPs are removed ,then still the database grows very slowly towards the namespace size.
49
 
#        - There are a lot of CREATE TABLE table2 SELECT * FROM table1 and similar constructs in order to clone
50
 
#          database objects. Unfortunately, at higher namespace values, table1 is not very likely to exist, and
51
 
#          therefore table2 is also unlikely to be created.
52
 
#   - Add subtest for
53
 
#     Bug#48315 Metadata lock is not taken for merged views that use an INFORMATION_SCHEMA table
54
 
#     Simple:
55
 
#        Philip: using an I_S in a meaningless subselect would be best, just have
56
 
#                ( SELECT user + 0 FROM INFORMATION_SCHEMA.USERS LIMIT 1)
57
 
#     Complete:
58
 
#        mleich:
59
 
#           But IS tables used in VIEWs, SELECT, DELETE/UPDATE subqueries/join,
60
 
#           PROCEDURES etc. are complete missing.
61
 
#           Could I inject this in a subquery?
62
 
#   - Simplify grammar:
63
 
#           Namespace concept is good for grammar development, avoiding failing statements,
64
 
#           understanding statement logs but bad for grammar simplification speed.
65
 
#
66
 
# General architecture rules:
67
 
# ---------------------------
68
 
# 1. Do not modify the objects created by gendata.pl within this grammar file.
69
 
#    Work on copies of these objects instead. Hereby we prevent that we totally run out of tables
70
 
#    or rows etc. This minimizes also any locks on the objects created by gendata.pl.
71
 
#    Do not
72
 
#    - have tables of "special" types (partitioned, view, merge etc.)
73
 
#    - variate the storage engine
74
 
#    within your object creation grammar file (*.zz).
75
 
# 2. Have separated namespaces for objects (tables etc.) with configurable width.
76
 
#    - This allows to reduce the likelihood of applying a statement in general or an option to
77
 
#      an object which is not allowed. Example: TRUNCATE TABLE <view>
78
 
#    - Debugging of grammar and understanding server logs becomes easier if the namespace
79
 
#      for an object of some type contains type related strings like "base","temp",.. etc.
80
 
#      Example: If there is a
81
 
#                  CREATE VIEW <name which does not belong into the VIEW namespace>
82
 
#               than something works not like intended.
83
 
#    - The configurable namespace width (-> $namespace_width) allows to influence the likelihood
84
 
#      that some statement hits an object. This gives some control over how much the system is stressed.
85
 
#    - The non default option to put all table related objects (base tables, views, etc.) allows
86
 
#      some additional increase of the stress though the likelihood of failing statement raises.
87
 
# 3. Distinct between two kinds of object namespaces and treat the corresponding objects different.
88
 
#    This is experimental and might be removed in case it does not fulfill the expectations.
89
 
#    "Sequence" ("_S"):
90
 
#       - statement sequence: CREATE object, fill in content (if applicable), COMMIT, wait some
91
 
#         random timespan (-> SLEEP( ... * rand_val * $life_time_unit )) , DROP object
92
 
#       - The COMMIT is intentional. It should ensure that the session running the sequence does
93
 
#         not hold any locks on the object during the wait phase. I am aware that CREATE ... AS SELECT
94
 
#         commits at end, but this might be changed somewhere in future.
95
 
#       - the maximum of the random wait timespan is configurable (-> $max_table_life_time).
96
 
#       - The object must be stored within a database created with the "_S" property.
97
 
#       - No other DDL on this object
98
 
#       This should ensure that other sessions have a chance to run several DML statements using this object
99
 
#       before it gets dropped. The "Sequence" objects are of nearly no value when running with only one thread.
100
 
#    "Normal" ("_N"):
101
 
#       - CREATE and DROP for these objects are not within the same sequency.
102
 
#       - Any session could run DDL (including DROP, ALTER, REPAIR etc.) on this object.
103
 
#       - The object can be stored within any database.
104
 
#       - It is assumed that they have a short lifetime.
105
 
#       This should ensure that a session running a transaction with DML on this object has a chance to meet
106
 
#       an attempt of another session to run DDL (especially ALTER) on this object.
107
 
# 4. There is some "generalization" (I am unsure if this is a good understandable term) of variables and
108
 
#    a corresponding walk up of values.
109
 
#       $database_name_*   --> $database_name
110
 
#       $base_table_name_* --> $base_table_name --> $table_name
111
 
#       $temp_table_name_* --> $temp_table_name --> $table_name
112
 
#       ...
113
 
#       $part_table_name_* --> $part_table_name --> $table_name
114
 
#    This means:
115
 
#    If you run "table_item" which picks a table of random type (base table, temp table ...) and random lifetime
116
 
#    and a corresponding database and automatically assigns values to variables ($database_*,$*_table_name_*)
117
 
#    where the name cannot be predicted, you can find the generated names at least within
118
 
#    $database_name and $table_name .
119
 
#    Please be aware that for example a succeeding call of "procedure_item" modifies the content of $database_name.
120
 
#
121
 
#
122
 
# Hints and experiences (important when extending this grammar ):
123
 
# -------------------------------------------------------------------
124
 
# 1. Any statement sequence has to be in one line.
125
 
# 2. Be aware of the dual use of ';'. It separates SQL statements in sequences and closes the definition block
126
 
#    of a grammar rules. So any ';' before some '|' has a significant impact.
127
 
# 3. Strange not intended effects might be caused by '|' or ':' instead of ';'
128
 
# 4. There is an open RQG problem with SHOW ... LIKE '<grammar rule>'.
129
 
# 5. In general: There should be spaces whenever a grammar rule is mentioned in some grammar rule component.
130
 
#    Example: "my_table" and  "where" are grammar rules.
131
 
#             SELECT MAX(f1) FROM my_table where ;
132
 
# 6. If there are needs to write some message into a server log than avoid the use of auxiliary SQL (SELECT <message> etc.).
133
 
#    Use something like:
134
 
#       /* <your text> */ <SQL statement belonging to the test> ;
135
 
#    instead.
136
 
# 7. Use uppercase characters for strings and keywords in statements. This avoids any not intended
137
 
#    treatment as grammar rule.
138
 
# 8. Use the most simple option first in lists. This makes automatic grammar simplification
139
 
#    which walks basically from right to left more efficient.
140
 
#    Example:
141
 
#    where:
142
 
#       <empty> | WHERE `pk` BETWEEN _digit AND _digit | WHERE function_name_n() = _digit ;
143
 
# 9. The RQG "Reporter" LockTableKiller can help to accelerate "deadlocked" tests.
144
 
#
145
 
#
146
 
 
147
 
# Naming conventions (default)
148
 
# ========================================================
149
 
#
150
 
# Pattern (standard configuration) | Object
151
 
# -----------------------------------------
152
 
# testdb_*                         | database
153
 
# t1_*                             | table/view
154
 
# p1_*                             | procedure
155
 
# f1_*                             | function
156
 
# p1_*                             | procedure
157
 
# tr1_*                            | trigger
158
 
 
159
 
# End of grammar rule name (default) | characteristic
160
 
# -------------------------------------------------------
161
 
# _S                                 | related to "sequence" object
162
 
# _N                                 | related to "normal" object
163
 
#
164
 
# Within grammar rule name  | characteristic
165
 
# -----------------------------------------------
166
 
# _name                     | name of the object
167
 
# _item                     | <schema name> . <name of the object>
168
 
# _list                     | either single rule (<schema name> . <name of the object>) or comma separated list
169
 
#                           | of such rules
170
 
 
171
 
#
172
 
# Missing but not really important improvements:
173
 
# - Reduce the amount of cases where "sequence" objects have "normal" objects within their definition.
174
 
#   --> views,functions,procedures
175
 
# - Reduce the amount of cases where the wrong table types occur within object definitions
176
 
#   Example: TABLE for a TRIGGER or VIEW definition. Names of temporary tables could be computed but are not allowed.
177
 
#
178
 
 
179
 
 
180
 
# Section of easy changeable rules with high impact on the test =============================================#
181
 
query_init:
182
 
        # Variant 1:
183
 
        #    Advantage: Less failing (table does not exist ...) statements within the first phase of the test.
184
 
        # init_basics1 : init_basics2 ; init_namespaces ; init_executor_table ; event_scheduler_on ; have_some_initial_objects ;
185
 
        # Variant 2:
186
 
        #    Advantage: Better performance during bug hunt, test simplification etc. because objects are created at
187
 
        #               one place (<object>_ddl) only and not also in "have_some_initial_objects".
188
 
        init_basics1 ; init_basics2 ; init_namespaces ; init_executor_table ;
189
 
 
190
 
init_executor_table:
191
 
        # This table is used in kill_query_or_session.
192
 
        CREATE TABLE IF NOT EXISTS test . executors (id BIGINT, PRIMARY KEY(id)) ENGINE = MEMORY ; INSERT HIGH_PRIORITY IGNORE INTO test.executors SET id = CONNECTION_ID() ; COMMIT ;
193
 
 
194
 
init_basics1:
195
 
        # 1. $life_time_unit = maximum lifetime of a table created within a CREATE, wait, DROP sequence.
196
 
        #
197
 
        #    A reasonable value is bigger than any "wait for <whatever> lock" timeout.
198
 
        #
199
 
        #    There are till now not sufficient experiences about the impact of different values on the outcome of the test.
200
 
        #
201
 
        #    sequence object | lifetime
202
 
        #    ------------------------------------------------
203
 
        #    database        | 2   * RAND() * $life_time_unit
204
 
        #    table (no view) | 1   * RAND() * $life_time_unit
205
 
        #    view            | 0.5 * RAND() * $life_time_unit
206
 
        #    procedure       | 0.5 * RAND() * $life_time_unit
207
 
        #    function        | 0.5 * RAND() * $life_time_unit
208
 
        #    trigger         | 0.5 * RAND() * $life_time_unit
209
 
        #
210
 
        #    A DML statement using SLEEP will use 0.5 * RAND() * $life_time_unit seconds.
211
 
        #
212
 
        #    one_thread_correction will correct $life_time_unit to 0 if we have only one "worker" thread.
213
 
        #
214
 
        # 2. $namespace_width = Width of a namespace
215
 
        #
216
 
        #    Smaller numbers cause a
217
 
        #    - lower fraction of statements failing because of missing object
218
 
        #    - higher fraction of clashes when running with multiple sessions
219
 
        #
220
 
        # Some notes:
221
 
        # - In case of one thread a $life_time_unit <> 0 does not make sense, because there is no parallel
222
 
        #   "worker" thread which could do something with the object during the "wait" period.
223
 
        { $life_time_unit = 1 ; $namespace_width = 2 ; if ( $ENV{RQG_THREADS} == 1 ) { $life_time_unit = 0 } ; return undef } avoid_bugs ; nothing_disabled ; system_table_stuff ;
224
 
 
225
 
init_basics2:
226
 
        # Store information if we have a debug server in $out_file.
227
 
        # 1. The "Home" directory of
228
 
        #    - the server would be <vardir>/master-data/
229
 
        #      <vardir> is alculated by MTR and affected by options given to runall.pl
230
 
        #    - RQG is <RQG install directory>
231
 
        # 2. The environment does not contain any variable pointing to <vardir> or RQG directories
232
 
        # Therefore we need a $outfile with absolute path.
233
 
        {$out_file='/tmp/'.$$.'.tmp' ; unlink($out_file); return undef} SELECT VERSION() LIKE '%debug%' INTO OUTFILE {return "'".$out_file."'"};
234
 
 
235
 
init_namespaces:
236
 
        # Please choose between the following alternatives
237
 
        # separate_objects         -- no_separate_objects
238
 
        # separate_normal_sequence -- no_separate_normal_sequence
239
 
        # separate_table_types     -- no_separate_table_types
240
 
        # 1. Low amount of failing statements, low risk to run into known not locking related crashes
241
 
        separate_objects ; separate_normal_sequence ; separate_table_types ;
242
 
        # 2. Higher amount of failing statements, risk to run into known temporary table related crashes
243
 
        # separate_objects ; separate_normal_sequence ; no_separate_table_types ;
244
 
        # 3. Total chaos
245
 
        # High amount of failing statements, especially risk to run into known temporary table related crashes and asserts.
246
 
        # no_separate_objects ; separate_normal_sequence ; no_separate_table_types ;
247
 
 
248
 
separate_table_types:
249
 
        # Effect: Distinction between
250
 
        #         - base, temporary, merge and partioned tables + views
251
 
        #         - tables of any type and functions,procedures,triggers,events
252
 
        #         Only statements which are applicable to this type of table will be generated.
253
 
        #         Example: ALTER VIEW <existing partitioned table> ... should be not generated.
254
 
        # Advantage: Less failing statements, logs are much easier to read
255
 
        # Disadvantage: The avoided suitations are not tested.
256
 
        { $base_piece="base" ; $temp_piece="temp" ; $merge_piece="merge" ; $part_piece="part" ; $view_piece="view" ; return undef } ;
257
 
no_separate_table_types:
258
 
        # Expected impact:
259
 
        # - maybe higher load on tables of all types in general (depends on size of namespace)
260
 
        # - a significant fraction of statements will fail with
261
 
        #   1. 1064 "You have an error in your SQL syntax ..."
262
 
        #      Example: TRUNCATE <view>
263
 
        #   2. <number <> 1064> <This option/whatever is not applicable to the current object/situation/whatever>
264
 
        #   This might look a bit ugly but it has the benefit that these statements are at least tried.
265
 
        #   The goal is not to check the parse process, but there might be temporary MDL locks or in worst
266
 
        #   case remaining permanent MDL lock. Effects of these locks should be also checked.
267
 
        #   Just as a reminder:
268
 
        #   A CREATE VIEW which fails with an error <> "You have an error in your SQL syntax" causes an implicit COMMIT
269
 
        #   of the current transaction.
270
 
        { $base_piece="" ; $temp_piece="" ; $merge_piece="" ; $part_piece="" ; $view_piece="" ; return undef } ;
271
 
separate_normal_sequence:
272
 
        # Advantages/Disadvantages: To be discovered
273
 
        { $sequence_piece="_S" ; $normal_piece="_N" ; return undef } ;
274
 
no_separate_normal_sequence:
275
 
        # Advantages/Disadvantages: To be discovered
276
 
        { $sequence_piece="" ; $normal_piece="" ; return undef } ;
277
 
separate_objects:
278
 
        # Effect: Distinction between schemas, tables, functions, triggers, procedures and events
279
 
        #         Only statements which are applicable to this type of object will be generated.
280
 
        #         Example: CALL <existing partitioned table> ... should be not generated.
281
 
        # Advantage: Less failing statements, logs are much easier to read
282
 
        # Disadvantage: The avoided suitations are not tested.
283
 
        { $database_prefix="testdb" ; $table_prefix="t1_" ; $procedure_prefix="p1_" ; $function_prefix="f1_" ; $trigger_prefix="tr1_" ; $event_prefix="e1_" ; return undef } ;
284
 
no_separate_objects:
285
 
        # Effect: At least no distinction between functions, triggers, procedures and events
286
 
        #         If no_separate_table_types is added, than also tables are no more separated.
287
 
        #         Example: CALL <existing partitioned table> ... should be not generated.
288
 
        # Advantage: More coverage
289
 
        # Disadvantage: More failing statements
290
 
        { $database_prefix="o1_1" ; $table_prefix="o1_" ; $procedure_prefix="o1_" ; $function_prefix="o1_" ; $trigger_prefix="o1_"  ; $event_prefix="o1_" ; return undef } ;
291
 
 
292
 
avoid_bugs:
293
 
        # Set this grammar rule to "empty" if for example no optimizer related server system variable has to be switched.
294
 
        ;
295
 
 
296
 
event_scheduler_on:
297
 
        SET GLOBAL EVENT_SCHEDULER = ON ;
298
 
 
299
 
event_scheduler_off:
300
 
        SET GLOBAL EVENT_SCHEDULER = OFF ;
301
 
 
302
 
have_some_initial_objects:
303
 
        # It is assumed that this reduces the likelihood of "Table does not exist" significant when running with a small number of "worker" threads.
304
 
        # The amount of create_..._table rules within the some_..._tables should depend a bit on the value in $namespace_width but I currently
305
 
        # do not know how to express this in the grammar.
306
 
        some_databases ; some_base_tables ; some_temp_tables ; some_merge_tables ; some_part_tables ; some_view_tables ; some_functions ; some_procedures ; some_trigger ; some_events ;
307
 
some_databases:
308
 
        create_database    ; create_database    ; create_database    ; create_database    ;
309
 
some_base_tables:
310
 
        create_base_table  ; create_base_table  ; create_base_table  ; create_base_table  ;
311
 
some_temp_tables:
312
 
        create_temp_table  ; create_temp_table  ; create_temp_table  ; create_temp_table  ;
313
 
some_merge_tables:
314
 
        create_merge_table ; create_merge_table ; create_merge_table ; create_merge_table ;
315
 
some_part_tables:
316
 
        create_part_table  ; create_part_table  ; create_part_table  ; create_part_table  ;
317
 
some_view_tables:
318
 
        create_view        ; create_view        ; create_view        ; create_view        ;
319
 
some_functions:
320
 
        create_function    ; create_function    ; create_function    ; create_function    ;
321
 
some_procedures:
322
 
        create_procedure   ; create_procedure   ; create_procedure   ; create_procedure   ;
323
 
some_trigger:
324
 
        create_trigger     ; create_trigger     ; create_trigger     ; create_trigger     ;
325
 
some_events:
326
 
        create_event       ; create_event       ; create_event       ; create_event       ;
327
 
 
328
 
nothing_disabled:
329
 
        { $sequence_begin = "/* Sequence start */" ; $sequence_end = "/* Sequence end */" ; return undef } ;
330
 
 
331
 
system_table_stuff:
332
 
        # This is used in "grant_revoke".
333
 
        CREATE USER otto@localhost ;
334
 
 
335
 
 
336
 
# Useful grammar rules ====================================================================================#
337
 
 
338
 
rand_val:
339
 
        { $rand_val = $prng->int(0,100) / 100 } ;
340
 
 
341
 
 
342
 
# Namespaces of objects ==========================================================================#
343
 
# An explanation of the namespace concept is on top of this file.
344
 
#
345
 
# 1. The database namespace ##########################################################################
346
 
database_name_s:
347
 
        { $database_name_s = $database_prefix . $sequence_piece ; $database_name = $database_name_s } ;
348
 
database_name_n:
349
 
        { $database_name_n = $database_prefix . $normal_piece   ; $database_name = $database_name_n } ;
350
 
database_name:
351
 
        # Get a random name from the "database" namespace.
352
 
        # $database_name gets automatically filled when database_name_s or database_name_n is executed.
353
 
        database_name_s | database_name_n ;
354
 
 
355
 
 
356
 
# 2. The base table namespace ########################################################################
357
 
base_table_name_s:
358
 
        # Get a random name from the "base table long life" namespace.
359
 
        { $base_table_name_s = $table_prefix . $base_piece   . $prng->int(1,$namespace_width) . $sequence_piece ; $base_table_name = $base_table_name_s ; $table_name = $base_table_name } ;
360
 
base_table_name_n:
361
 
        # Get a random name from the "base table short life" namespace.
362
 
        { $base_table_name_n = $table_prefix . $base_piece   . $prng->int(1,$namespace_width) . $normal_piece   ; $base_table_name = $base_table_name_n ; $table_name = $base_table_name } ;
363
 
base_table_name:
364
 
        # Get a random name from the "base table" namespace.
365
 
        base_table_name_s | base_table_name_n ;
366
 
 
367
 
# Sometimes useful stuff:
368
 
base_table_item_s:
369
 
        database_name_s . base_table_name_s { $base_table_item_s = $database_name_s . " . " . $base_table_name_s ; $base_table_item = $base_table_item_s ; return undef } ;
370
 
base_table_item_n:
371
 
        database_name   . base_table_name_n { $base_table_item_n = $database_name   . " . " . $base_table_name_n ; $base_table_item = $base_table_item_n ; return undef } ;
372
 
base_table_item:
373
 
        base_table_item_s | base_table_item_n ;
374
 
base_table_item_list_s:
375
 
        base_table_item_s | base_table_item_s , base_table_item_s ;
376
 
base_table_item_list_n:
377
 
        base_table_item_n | base_table_item_n , base_table_item_n ;
378
 
base_table_item_list:
379
 
        base_table_item   | base_table_item   , base_table_item   ;
380
 
 
381
 
 
382
 
# 3. The temp table namespace ########################################################################
383
 
# Please note that TEMPORARY merge tables will be not generated.
384
 
temp_table_name_s:
385
 
        # Get a random name from the "temp table long life" namespace.
386
 
        { $temp_table_name_s = $table_prefix . $temp_piece   . $prng->int(1,$namespace_width) . $sequence_piece ; $temp_table_name = $temp_table_name_s ; $table_name = $temp_table_name } ;
387
 
temp_table_name_n:
388
 
        # Get a random name from the "temp table short life" namespace.
389
 
        { $temp_table_name_n = $table_prefix . $temp_piece   . $prng->int(1,$namespace_width) . $normal_piece   ; $temp_table_name = $temp_table_name_n ; $table_name = $temp_table_name } ;
390
 
temp_table_name:
391
 
        # Get a random name from the "temp table" namespace.
392
 
        temp_table_name_s | temp_table_name_n ;
393
 
 
394
 
# Sometimes useful stuff:
395
 
temp_table_item_s:
396
 
        database_name_s . temp_table_name_s { $temp_table_item_s = $database_name_s . " . " . $temp_table_name_s ; $temp_table_item = $temp_table_item_s ; return undef } ;
397
 
temp_table_item_n:
398
 
        database_name   . temp_table_name_n { $temp_table_item_n = $database_name   . " . " . $temp_table_name_n ; $temp_table_item = $temp_table_item_n ; return undef } ;
399
 
temp_table_item:
400
 
        temp_table_item_s | temp_table_item_n ;
401
 
temp_table_item_list_s:
402
 
        temp_table_item_s | temp_table_item_s , temp_table_item_s ;
403
 
temp_table_item_list_n:
404
 
        temp_table_item_n | temp_table_item_n , temp_table_item_n ;
405
 
temp_table_item_list:
406
 
        temp_table_item   | temp_table_item   , temp_table_item   ;
407
 
 
408
 
 
409
 
# 4. The merge table namespace #######################################################################
410
 
# Please note that TEMPORARY merge tables will be not generated.
411
 
merge_table_name_s:
412
 
        # Get a random name from the "merge table long life" namespace.
413
 
        { $merge_table_name_s = $table_prefix . $merge_piece . $prng->int(1,$namespace_width) . $sequence_piece ; $merge_table_name = $merge_table_name_s ; $table_name = $merge_table_name } ;
414
 
merge_table_name_n:
415
 
        # Get a random name from the "merge table short life" namespace.
416
 
        { $merge_table_name_n = $table_prefix . $merge_piece . $prng->int(1,$namespace_width) . $normal_piece   ; $merge_table_name = $merge_table_name_n ; $table_name = $merge_table_name } ;
417
 
merge_table_name:
418
 
        # Get a random name from the "merge table" namespace.
419
 
        merge_table_name_s | merge_table_name_n ;
420
 
 
421
 
# Sometimes useful stuff:
422
 
merge_table_item_s:
423
 
        database_name_s . merge_table_name_s { $merge_table_item_s = $database_name_s . " . " . $merge_table_name_s ; $merge_table_item = $merge_table_item_s ; return undef } ;
424
 
merge_table_item_n:
425
 
        database_name   . merge_table_name_n { $merge_table_item_n = $database_name   . " . " . $merge_table_name_n ; $merge_table_item = $merge_table_item_n ; return undef } ;
426
 
merge_table_item:
427
 
        merge_table_item_s | merge_table_item_n ;
428
 
merge_table_item_list_s:
429
 
        merge_table_item_s | merge_table_item_s , merge_table_item_s ;
430
 
merge_table_item_list_n:
431
 
        merge_table_item_n | merge_table_item_n , merge_table_item_n ;
432
 
merge_table_item_list:
433
 
        merge_table_item   | merge_table_item   , merge_table_item   ;
434
 
 
435
 
 
436
 
# 5. The view table namespace ########################################################################
437
 
view_table_name_s:
438
 
        # Get a random name from the "view table long life" namespace.
439
 
        { $view_table_name_s = $table_prefix . $view_piece   . $prng->int(1,$namespace_width) . $sequence_piece ; $view_table_name = $view_table_name_s ; $table_name = $view_table_name } ;
440
 
view_table_name_n:
441
 
        # Get a random name from the "view table short life" namespace.
442
 
        { $view_table_name_n = $table_prefix . $view_piece   . $prng->int(1,$namespace_width) . $normal_piece   ; $view_table_name = $view_table_name_n ; $table_name = $view_table_name } ;
443
 
view_table_name:
444
 
        # Get a random name from the "view table" namespace.
445
 
        view_table_name_s | view_table_name_n ;
446
 
 
447
 
# Sometimes useful stuff:
448
 
view_table_item_s:
449
 
        database_name_s . view_table_name_s { $view_table_item_s = $database_name_s . " . " . $view_table_name_s ; $view_table_item = $view_table_item_s ; return undef };
450
 
view_table_item_n:
451
 
        database_name   . view_table_name_n { $view_table_item_n = $database_name   . " . " . $view_table_name_n ; $view_table_item = $view_table_item_n ; return undef };
452
 
view_table_item:
453
 
        view_table_item_s | view_table_item_n ;
454
 
view_table_item_list_s:
455
 
        view_table_item_s | view_table_item_s , view_table_item_s ;
456
 
view_table_item_list_n:
457
 
        view_table_item_n | view_table_item_n , view_table_item_n ;
458
 
view_table_item_list:
459
 
        view_table_item   | view_table_item   , view_table_item   ;
460
 
 
461
 
 
462
 
# 6. The partitioned table namespace #################################################################
463
 
part_table_name_s:
464
 
        # Get a random name from the "part table long life" namespace.
465
 
        { $part_table_name_s = $table_prefix . $part_piece   . $prng->int(1,$namespace_width) . $sequence_piece ; $part_table_name = $part_table_name_s ; $table_name = $part_table_name } ;
466
 
part_table_name_n:
467
 
        # Get a random name from the "part table short life" namespace.
468
 
        { $part_table_name_n = $table_prefix . $part_piece   . $prng->int(1,$namespace_width) . $normal_piece   ; $part_table_name = $part_table_name_n ; $table_name = $part_table_name } ;
469
 
part_table_name:
470
 
        # Get a random name from the "part table" namespace.
471
 
        part_table_name_s | part_table_name_n ;
472
 
 
473
 
# Sometimes useful stuff:
474
 
part_table_item_s:
475
 
        database_name_s . part_table_name_s { $part_table_item_s = $database_name_s . " . " . $part_table_name_s ; $part_table_item = $part_table_item_s ; return undef };
476
 
part_table_item_n:
477
 
        database_name   . part_table_name_n { $part_table_item_n = $database_name   . " . " . $part_table_name_n ; $part_table_item = $part_table_item_n ; return undef };
478
 
part_table_item:
479
 
        part_table_item_s | part_table_item_n ;
480
 
part_table_item_list_s:
481
 
        part_table_item_s | part_table_item_s , part_table_item_s ;
482
 
part_table_item_list_n:
483
 
        part_table_item_n | part_table_item_n , part_table_item_n ;
484
 
part_table_item_list:
485
 
        part_table_item   | part_table_item   , part_table_item   ;
486
 
 
487
 
 
488
 
# 7. Mixed namespaces of tables ################################################################
489
 
 
490
 
# 7.1 All tables ( base/temp/merge tables + views + ... #########################################
491
 
table_item_s:
492
 
        base_table_item_s | temp_table_item_s | merge_table_item_s | view_table_item_s | part_table_item_s ;
493
 
table_item_n:
494
 
        base_table_item_n | temp_table_item_n | merge_table_item_n | view_table_item_n | part_table_item_n ;
495
 
table_item:
496
 
        table_item_s | table_item_n ;
497
 
 
498
 
table_list:
499
 
        # Less likelihood for lists, because they
500
 
        # - are most probably less often used
501
 
        # - cause a higher likelihood of "table does not exist" errors.
502
 
        table_item | table_item | table_item | table_item | table_item | table_item | table_item | table_item | table_item |
503
 
        table_item , table_item ;
504
 
        
505
 
 
506
 
# 7.2 All tables but no views #######################################################################
507
 
table_no_view_item_s:
508
 
        base_table_item_s | temp_table_item_s | merge_table_item_s | part_table_item_s ;
509
 
table_no_view_item_n:
510
 
        base_table_item_n | temp_table_item_n | merge_table_item_n | part_table_item_n ;
511
 
table_no_view_item:
512
 
        table_no_view_item_s | table_no_view_item_n ;
513
 
 
514
 
 
515
 
# 7.3 All base and temp tables + views ##############################################################
516
 
#     These grammar rules could be used to avoid some partioning or merge table related bugs.
517
 
base_temp_view_table_item_s:
518
 
        base_table_item_s | temp_table_item_s | view_table_item_s | part_table_item_s ;
519
 
base_temp_view_table_item_n:
520
 
        base_table_item_n | temp_table_item_n | view_table_item_n | part_table_item_n ;
521
 
base_temp_view_table_item:
522
 
        base_temp_view_table_item_s | base_temp_view_table_item ;
523
 
 
524
 
 
525
 
# 8. Other namespaces ##############################################################a
526
 
template_table_item:
527
 
        # The disabled names are for future use. They cannot work with the current properties of .zz grammars.
528
 
        # The problem is that we get in some scenarios tables with differing numnber of columns.
529
 
        # { $template_table_item = "test.table0" }              |
530
 
        # { $template_table_item = "test.table1" }              |
531
 
        # { $template_table_item = "test.table10" }             |
532
 
        # { $template_table_item = "test.table0_int" }          |
533
 
        { $template_table_item = "test.table0_int" }          |
534
 
        { $template_table_item = "test.table1_int" }          |
535
 
        { $template_table_item = "test.table10_int" }         |
536
 
        { $template_table_item = "test.table0_int_autoinc" }  |
537
 
        { $template_table_item = "test.table1_int_autoinc" }  |
538
 
        { $template_table_item = "test.table10_int_autoinc" } ;
539
 
 
540
 
 
541
 
procedure_name_s:
542
 
        # Get a random name from the "procedure long life" namespace.
543
 
        { $procedure_name_s = $procedure_prefix . $prng->int(1,$namespace_width) . $sequence_piece ; $procedure_name = $procedure_name_s } ;
544
 
procedure_name_n:
545
 
        # Get a random name from the "procedure short life" namespace.
546
 
        { $procedure_name_n = $procedure_prefix . $prng->int(1,$namespace_width) . $normal_piece   ; $procedure_name = $procedure_name_n } ;
547
 
procedure_name:
548
 
        # Get a random name from the "procedure" namespace.
549
 
        procedure_name_s | procedure_name_n ;
550
 
 
551
 
# Sometimes useful stuff:
552
 
procedure_item_s:
553
 
        database_name_s . procedure_name_s { $procedure_item_s = $database_name_s . " . " . $procedure_name_s ; $procedure_item = $procedure_item_s ; return undef } ;
554
 
procedure_item_n:
555
 
        database_name   . procedure_name_n { $procedure_item_n = $database_name   . " . " . $procedure_name_n ; $procedure_item = $procedure_item_n ; return undef } ;
556
 
procedure_item:
557
 
        procedure_item_s | procedure_item_n ;
558
 
 
559
 
function_name_s:
560
 
        # Get a random name from the "function long life" namespace.
561
 
        { $function_name_s  = $function_prefix . $prng->int(1,$namespace_width) . $sequence_piece  ; $function_name = $function_name_s } ;
562
 
function_name_n:
563
 
        # Get a random name from the "function short life" namespace.
564
 
        { $function_name_n  = $function_prefix . $prng->int(1,$namespace_width) . $normal_piece    ; $function_name = $function_name_n } ;
565
 
function_name:
566
 
        # Get a random name from the "function" namespace.
567
 
        function_name_s | function_name_n ;
568
 
 
569
 
function_item_s:
570
 
        database_name_s . function_name_s { $function_item_s = $database_name_s . " . " . $function_name_s ; $function_item = $function_item_s ; return undef } ;
571
 
function_item_n:
572
 
        database_name   . function_name_n { $function_item_n = $database_name   . " . " . $function_name_n ; $function_item = $function_item_n ; return undef } ;
573
 
function_item:
574
 
        function_item_s | function_item_n ;
575
 
 
576
 
trigger_name_s:
577
 
        # Get a random name from the "trigger long life" namespace.
578
 
        { $trigger_name_s   = $trigger_prefix . $prng->int(1,$namespace_width) . $sequence_piece ; $trigger_name = $trigger_name_s } ;
579
 
trigger_name_n:
580
 
        # Get a random name from the "trigger short life" namespace.
581
 
        { $trigger_name_n   = $trigger_prefix . $prng->int(1,$namespace_width) . $normal_piece   ; $trigger_name = $trigger_name_n } ;
582
 
trigger_name:
583
 
        # Get a random name from the "trigger" namespace.
584
 
        trigger_name_s | trigger_name_n ;
585
 
 
586
 
trigger_item_s:
587
 
        database_name_s . trigger_name_s { $trigger_item_s = $database_name_s . " . " . $trigger_name_s ; $trigger_item = $trigger_item_s ; return undef } ;
588
 
trigger_item_n:
589
 
        database_name   . trigger_name_n { $trigger_item_n = $database_name   . " . " . $trigger_name_n ; $trigger_item = $trigger_item_n ; return undef } ;
590
 
trigger_item:
591
 
        trigger_item_s | trigger_item_n ;
592
 
 
593
 
event_name_s:
594
 
        # Get a random name from the "event long life" namespace.
595
 
        { $event_name_s   = $event_prefix . $prng->int(1,$namespace_width) . $sequence_piece ; $event_name = $event_name_s } ;
596
 
event_name_n:
597
 
        # Get a random name from the "event short life" namespace.
598
 
        { $event_name_n   = $event_prefix . $prng->int(1,$namespace_width) . $normal_piece   ; $event_name = $event_name_n } ;
599
 
event_name:
600
 
        # Get a random name from the "event" namespace.
601
 
        event_name_s | event_name_n ;
602
 
 
603
 
event_item_s:
604
 
        database_name_s . event_name_s { $event_item_s = $database_name_s . " . " . $event_name_s ; $event_item = $event_item_s ; return undef } ;
605
 
event_item_n:
606
 
        database_name   . event_name_n { $event_item_n = $database_name   . " . " . $event_name_n ; $event_item = $event_item_n ; return undef } ;
607
 
event_item:
608
 
        event_item_s | event_item_n ;
609
 
 
610
 
# Here starts the core of the test grammar ========================================================#
611
 
 
612
 
query:
613
 
        dml | dml | dml | dml | ddl | transaction | lock_unlock | lock_unlock | flush | handler ;
614
 
 
615
 
########## TRANSACTIONS ####################
616
 
 
617
 
transaction:
618
 
        start_transaction | commit | rollback |
619
 
        start_transaction | commit | rollback |
620
 
        start_transaction | commit | rollback |
621
 
        SAVEPOINT savepoint_id | RELEASE SAVEPOINT savepoint_id | ROLLBACK work_or_empty TO savepoint_or_empty savepoint_id |
622
 
        BEGIN work_or_empty | set_autocommit | kill_query_or_session ;
623
 
        # No impact on mdl.cc , lock.cc ..... set_isolation_level ;
624
 
 
625
 
savepoint_id:
626
 
        A | B ;
627
 
 
628
 
set_isolation_level:
629
 
        SET SESSION TX_ISOLATION = TRIM(' isolation_level ');
630
 
 
631
 
isolation_level:
632
 
        REPEATABLE-READ | READ-COMMITTED | SERIALIZABLE ;
633
 
 
634
 
 
635
 
start_transaction:
636
 
        START TRANSACTION with_consistent_snapshot ;
637
 
with_consistent_snapshot:
638
 
        | | | | | | | | | WITH CONSISTENT SNAPSHOT ;
639
 
 
640
 
# COMMIT/ROLLBACK
641
 
#----------------
642
 
# 1. RELEASE should be rare
643
 
# 2. AND CHAIN RELEASE is nonsense and will get an error
644
 
# 3. COMMIT [ WORK ] [ AND [ NO ] CHAIN ] [RELEASE]
645
 
#    AND NO CHAIN is the default, no RELEASE is the default
646
 
# 4. ROLLBACK [ WORK ] [ AND [ NO ] CHAIN ] [RELEASE]
647
 
#    [ TO SAVEPOINT <savepoint specifier> ]
648
 
#    You may specify only one of:
649
 
#    "[AND [NO] CHAIN]" or "RELEASE" or "TO SAVEPOINT ...".
650
 
#    AND NO CHAIN is the default, no RELEASE is the default
651
 
 
652
 
commit:
653
 
        COMMIT work_or_empty no_chain release_or_empty |
654
 
        COMMIT work_or_empty AND CHAIN                 ;
655
 
no_chain:
656
 
        | | | |
657
 
        AND NO CHAIN ;
658
 
release_or_empty:
659
 
        | | | | | | | | | RELEASE ;
660
 
 
661
 
rollback:
662
 
        ROLLBACK work_or_empty no_chain release_or_empty |
663
 
        ROLLBACK work_or_empty AND CHAIN                 ;
664
 
 
665
 
set_autocommit:
666
 
        SET AUTOCOMMIT = zero_or_one ;
667
 
 
668
 
kill_query_or_session:
669
 
#---------------------
670
 
# I expect in case
671
 
# - a query gets killed that most locks hold by this query are automatically removed.
672
 
#   Metadata locks might survive till transaction end.
673
 
# - a session gets killed that any lock hold by this session gets automatically removed.
674
 
# We will not check the removal here via SQL or sophisticated PERL code.
675
 
# We just hope that forgotten locks lead sooner or later to nice deadlocks.
676
 
#
677
 
# Attention:
678
 
#    There is some unfortunate sideeffect of KILL <session> .
679
 
#    It reduces the probability to detect deadlocks because it
680
 
#    might hit a participating session.
681
 
#
682
 
# Killing a query or session must NOT affect an
683
 
# - auxiliary RQG session (= non executor) because this can fool RQG's judgement
684
 
#   about the test outcome
685
 
# - executor session which is within the early phase when it pulls meta data (table names, column names,
686
 
#   data types, ...). This could end up with RQG exit status 255.
687
 
#   -> "Can't use an undefined value as an ARRAY reference at lib/GenTest/Generator/FromGrammar.pm line 269."
688
 
# This is ensured by the following:
689
 
# Every executor pulls meta data and runs after that "query_init".
690
 
# Within "query_init" this executor writes his own CONNECTION_ID() into the table test.executors.
691
 
# When running KILL for another session only the id's found in test.executors must be selected.
692
 
# In case it is planned to kill
693
 
# - another session             AFTER
694
 
# - own session (suicide)       BEFORE
695
 
# the KILL statement the entry within test.executors has to be removed.
696
 
#
697
 
# Depending on scenario (a session might run COMMIT/ROLLBACK RELEASE) and whatever other effects it might happen that
698
 
# 1. A session disappears but the entry is not removed.
699
 
#    This is harmless because somewhere later another session will pick the id from test.executors
700
 
#    try the kill session and remove the entry.
701
 
# 2. A session entry in test.executors does not exist but the session is alife.
702
 
#    This is harmless because somewhere later this session will try to remove its' no more existing
703
 
#    entry from test.executors and kill himself.
704
 
#
705
 
# Scenarios covered:
706
 
# 1. S1 kills S2
707
 
# 2. S1 kills S1
708
 
# 3. S1 try to kill S3 which no more exists.
709
 
# 4. Various combinations of sessions running 1., 2. or 3.
710
 
#
711
 
# The various COMMITs should ensure that locking effects caused by activity on test.executors are minimal.
712
 
        COMMIT ; own_id     ; delete_executor_entry ; COMMIT ; KILL       @kill_id                                  |
713
 
        COMMIT ; own_id     ;                       ; COMMIT ; KILL QUERY @kill_id                                  |
714
 
        COMMIT ; minimal_id ;                       ; COMMIT ; KILL       @kill_id ; delete_executor_entry ; COMMIT |
715
 
        COMMIT ; minimal_id ;                       ; COMMIT ; KILL QUERY @kill_id                                  ;
716
 
own_id:
717
 
        SET @kill_id = CONNECTION_ID() ;
718
 
minimal_id:
719
 
        SELECT MIN(id) INTO @kill_id FROM test . executors ;
720
 
delete_executor_entry:
721
 
        DELETE FROM test . executors WHERE id = @kill_id ;
722
 
 
723
 
ddl:
724
 
        database_ddl                                        |
725
 
        base_table_ddl  | base_table_ddl  | base_table_ddl  |
726
 
        temp_table_ddl  | temp_table_ddl  | temp_table_ddl  |
727
 
        merge_table_ddl | merge_table_ddl | merge_table_ddl |
728
 
        part_table_ddl  | part_table_ddl  | part_table_ddl  |
729
 
        view_ddl        | view_ddl        | view_ddl        |
730
 
        procedure_ddl   | procedure_ddl   | procedure_ddl   |
731
 
        function_ddl    | function_ddl    | function_ddl    |
732
 
        trigger_ddl     | trigger_ddl     | trigger_ddl     |
733
 
        event_ddl                  |
734
 
        truncate_table             |
735
 
        drop_table_list            |
736
 
        rename_table               |
737
 
        # Bug#54486 assert in my_seek, concurrent DROP/CREATE SCHEMA, CREATE TABLE, REPAIR
738
 
        # affects table_maintenance_ddl in mysql-5.1.
739
 
        # The problem seems to have disappeared in higher MySQL versions.
740
 
        table_maintenance_ddl      |
741
 
        dump_load_data_sequence    |
742
 
        grant_revoke               |
743
 
        rename_column              |
744
 
        sql_mode                   ;
745
 
        # "dump_load_data_sequence" with SELECT ... INTO OUTFILE ...; LOAD DATA ... INFILE
746
 
        # consists more of DML statements, but we place this here under "ddl" because the
747
 
        # statements in "dml" are often executed as prepared statements. And the text after
748
 
        # PREPARE st1 FOR must not contain multiple statements.
749
 
 
750
 
 
751
 
########## HANDLER ####################
752
 
        # The alias within HANDLER ... OPEN is optional. Unfortunately the HANDLER ... READ/CLOSE ... statements
753
 
        # do not accept SCHEMA names. Therefore the tablename must be either a table within the current SCHEMA
754
 
        # or an alias. We go with alias all time.
755
 
 
756
 
handler:
757
 
        handler_open  |
758
 
        handler_read  |
759
 
        handler_close ;
760
 
 
761
 
handler_open:
762
 
        HANDLER table_no_view_item OPEN as handler_a ;
763
 
 
764
 
handler_read:
765
 
        HANDLER handler_a READ handler_index comparison_operator ( _digit ) handler_read_part |
766
 
        HANDLER handler_a READ handler_index first_next_prev_last           handler_read_part |
767
 
        HANDLER handler_a READ               first_next                     handler_read_part ;
768
 
handler_index:
769
 
        `PRIMARY`     |
770
 
        `col_int_key` ;
771
 
handler_read_part:
772
 
        | where ;
773
 
first_next:
774
 
        FIRST |
775
 
        NEXT  ;
776
 
first_next_prev_last:
777
 
        FIRST |
778
 
        NEXT  |
779
 
        PREV  |
780
 
        LAST  ;
781
 
 
782
 
handler_close:
783
 
        HANDLER handler_a CLOSE ;
784
 
 
785
 
 
786
 
########## SHOW ####################
787
 
# We run here only object related SHOW commands except SHOW STATUS which checks counters
788
 
# of OPEN tables etc.
789
 
show:
790
 
        database_show              |
791
 
        table_show                 |
792
 
        routine_show               |
793
 
        SHOW STATUS                ;
794
 
 
795
 
database_show:
796
 
        show_databases | show_create_database ;
797
 
 
798
 
show_databases:
799
 
        SHOW databases_schemas ;
800
 
databases_schemas:
801
 
        DATABASES | SCHEMAS ;
802
 
 
803
 
show_create_database:
804
 
        SHOW CREATE database_schema database_name ;
805
 
 
806
 
#----------------------------------
807
 
 
808
 
table_show:
809
 
        show_tables       | show_tables       |
810
 
        show_table_status | show_table_status |
811
 
        show_create_table | show_create_view  |
812
 
        show_open_tables  | show_columns      ;
813
 
 
814
 
show_tables:
815
 
        SHOW TABLES ;
816
 
 
817
 
show_create_table:
818
 
        # Works also for views
819
 
        SHOW CREATE TABLE table_item ;
820
 
 
821
 
show_open_tables:
822
 
        SHOW OPEN TABLES IN database_name ;
823
 
 
824
 
show_table_status:
825
 
        # Works also for views
826
 
        SHOW TABLE STATUS ;
827
 
 
828
 
show_columns:
829
 
        SHOW full COLUMNS from_in table_item show_columns_part ;
830
 
full:
831
 
        # Only 20 %
832
 
        | | | | FULL ;
833
 
from_in:
834
 
        FROM | IN ;
835
 
show_columns_part:
836
 
        # Attention: LIKE '_field' does not work, because RQG does not expand _field.
837
 
        #            LIKE '%int%' does not work, because RQG expands it to something like LIKE '%822214656%'.
838
 
        # FIXME: Add "WHERE"
839
 
        | LIKE '%INT%' ;
840
 
 
841
 
show_create_view:
842
 
        SHOW CREATE VIEW view_table_item ;
843
 
 
844
 
#----------------------------------
845
 
routine_show:
846
 
        show_create_function  | show_function_code  | show_function_status  |
847
 
        show_create_procedure | show_procedure_code | show_procedure_status |
848
 
        show_triggers         | show_create_trigger |
849
 
        show_events           | show_create_event   ;
850
 
 
851
 
show_create_function:
852
 
        SHOW CREATE FUNCTION function_item ;
853
 
 
854
 
show_function_code:
855
 
        is_debug1 is_debug2 { return $m1 } SHOW FUNCTION CODE function_item { return $m2 };
856
 
 
857
 
show_function_status:
858
 
        SHOW FUNCTION STATUS ;
859
 
 
860
 
show_create_procedure:
861
 
        SHOW CREATE PROCEDURE procedure_item ;
862
 
 
863
 
show_procedure_code:
864
 
        is_debug1 is_debug2 { return $m1 } SHOW PROCEDURE CODE procedure_item { return $m2 };
865
 
 
866
 
is_debug1:
867
 
        # Calculate if we have a debug server.
868
 
        { $is_debug_server = -1; open($my_file,'<'.$out_file); read($my_file,$is_debug_server,1000); close($my_file); return undef };
869
 
 
870
 
is_debug2:
871
 
        # Set the marker according if we have a debug server or not.
872
 
        { $m1='/*'; $m2='*/'; if ( $is_debug_server == 1 ) { $m1=''; $m2='' }; return undef } ;
873
 
 
874
 
show_procedure_status:
875
 
        SHOW PROCEDURE STATUS ;
876
 
 
877
 
show_triggers:
878
 
        SHOW TRIGGERS ;
879
 
 
880
 
show_create_trigger:
881
 
        SHOW CREATE TRIGGER trigger_item ;
882
 
 
883
 
show_events:
884
 
        SHOW EVENTS from_in database_name ;
885
 
 
886
 
show_create_event:
887
 
        SHOW CREATE EVENT event_item_s ;
888
 
        
889
 
########## SELECTS ON THE INFORMATION_SCHEMA ####################
890
 
# We run here only object related SELECTs.
891
 
is_selects:
892
 
        is_schemata | is_tables | is_columns ;
893
 
is_schemata:
894
 
        /* database_name */ SELECT * FROM information_schema . schemata WHERE schema_name = TRIM(' $database_name ') ;
895
 
is_tables:
896
 
        /* table_item */ SELECT * FROM information_schema . tables WHERE table_schema = TRIM(' $database_name ') AND table_name = TRIM(' $table_name ') ;
897
 
is_columns:
898
 
        /* table_item */ SELECT * FROM information_schema . columns WHERE table_schema = TRIM(' $database_name ') AND table_name = TRIM(' $table_name ') AND column_name = random_field_quoted ;
899
 
# 19.1. The INFORMATION_SCHEMA SCHEMATA Table
900
 
# 19.2. The INFORMATION_SCHEMA TABLES Table
901
 
# 19.3. The INFORMATION_SCHEMA COLUMNS Table
902
 
# 19.4. The INFORMATION_SCHEMA STATISTICS Table
903
 
# 19.5. The INFORMATION_SCHEMA USER_PRIVILEGES Table
904
 
# 19.6. The INFORMATION_SCHEMA SCHEMA_PRIVILEGES Table
905
 
# 19.7. The INFORMATION_SCHEMA TABLE_PRIVILEGES Table
906
 
# 19.8. The INFORMATION_SCHEMA COLUMN_PRIVILEGES Table
907
 
# 19.9. The INFORMATION_SCHEMA CHARACTER_SETS Table
908
 
# 19.10. The INFORMATION_SCHEMA COLLATIONS Table
909
 
# 19.11. The INFORMATION_SCHEMA COLLATION_CHARACTER_SET_APPLICABILITY Table
910
 
# 19.12. The INFORMATION_SCHEMA TABLE_CONSTRAINTS Table
911
 
# 19.13. The INFORMATION_SCHEMA KEY_COLUMN_USAGE Table
912
 
# 19.14. The INFORMATION_SCHEMA ROUTINES Table
913
 
# 19.15. The INFORMATION_SCHEMA VIEWS Table
914
 
# 19.16. The INFORMATION_SCHEMA TRIGGERS Table
915
 
# 19.17. The INFORMATION_SCHEMA PLUGINS Table
916
 
# 19.18. The INFORMATION_SCHEMA ENGINES Table
917
 
# 19.19. The INFORMATION_SCHEMA PARTITIONS Table
918
 
# 19.20. The INFORMATION_SCHEMA EVENTS Table
919
 
# 19.21. The INFORMATION_SCHEMA FILES Table
920
 
# 19.22. The INFORMATION_SCHEMA TABLESPACES Table
921
 
# 19.23. The INFORMATION_SCHEMA PROCESSLIST Table
922
 
# 19.24. The INFORMATION_SCHEMA REFERENTIAL_CONSTRAINTS Table
923
 
# 19.25. The INFORMATION_SCHEMA GLOBAL_STATUS and SESSION_STATUS Tables
924
 
# 19.26. The INFORMATION_SCHEMA GLOBAL_VARIABLES and SESSION_VARIABLES Tables
925
 
# 19.27. The INFORMATION_SCHEMA PARAMETERS Table
926
 
# 19.28. The INFORMATION_SCHEMA PROFILING Table
927
 
# 19.29. Other INFORMATION_SCHEMA Tables
928
 
#
929
 
 
930
 
 
931
 
########## DATABASE ####################
932
 
database_ddl:
933
 
        create_database   | create_database | create_database |
934
 
        drop_database     | alter_database  |
935
 
        database_sequence ;
936
 
 
937
 
create_database:
938
 
        CREATE database_schema if_not_exists database_name_n database_spec ;
939
 
 
940
 
database_schema:
941
 
        DATABASE | SCHEMA ;
942
 
 
943
 
database_spec:
944
 
        # We do not want to test CHARACTER SETs and COLLATIONs, but we need something for ALTER DATABASE.
945
 
        default_word CHARACTER SET equal utf8 | default_word COLLATE equal utf8_bin ;
946
 
 
947
 
drop_database:
948
 
        DROP database_schema if_exists database_name_n ;
949
 
 
950
 
alter_database:
951
 
        ALTER database_schema database_name_n database_spec ;
952
 
 
953
 
database_sequence:
954
 
        # Have a bigger lifetime for databases because the objects with extended lifetime are stored there.
955
 
        $sequence_begin CREATE database_schema database_name_s ; wait_till_drop_database ; DROP database_schema $database_name_s $sequence_end ;
956
 
wait_till_drop_database:
957
 
        SELECT SLEEP( 2 * rand_val * $life_time_unit ) ;
958
 
 
959
 
 
960
 
########## BASE AND TEMPORARY TABLES ####################
961
 
base_table_ddl:
962
 
        create_base_table   | create_base_table | create_base_table | create_base_table | create_base_table | create_base_table |
963
 
        drop_base_table     | alter_base_table  |
964
 
        base_table_sequence ;
965
 
 
966
 
create_base_table:
967
 
        CREATE           TABLE if_not_exists base_table_item_n { $create_table_item = $base_table_item_n ; return undef } create_table_part ;
968
 
create_table_part:
969
 
        LIKE template_table_item ; ALTER TABLE $create_table_item ENGINE = engine ; INSERT INTO $create_table_item SELECT * FROM $template_table_item |
970
 
        LIKE template_table_item ; ALTER TABLE $create_table_item ENGINE = engine ; INSERT INTO $create_table_item SELECT * FROM $template_table_item |
971
 
        AS used_select           ;
972
 
 
973
 
drop_base_table:
974
 
        # DROP two tables is in "drop_table_list"
975
 
        DROP           TABLE if_exists base_table_item_n restrict_cascade ;
976
 
 
977
 
alter_base_table:
978
 
        ALTER ignore TABLE base_table_item_n alter_base_temp_table_part ;
979
 
 
980
 
alter_base_temp_table_part:
981
 
        # Reasons why "ENGINE = engine" should be rather rare:
982
 
        # 1. ALTER ... ENGINE = <engine> is rather rare within a production system running under DML load
983
 
        # 2. ALTER ... ENGINE = <engine != MyISAM> "damages" any MERGE table using the affected table as base table.
984
 
        #    As a consequence nerly all statements on the MERGE table will fail.
985
 
        COMMENT = 'UPDATED NOW()' | COMMENT = 'UPDATED NOW()' | COMMENT = 'UPDATED NOW()' | COMMENT = 'UPDATED NOW()' | COMMENT = 'UPDATED NOW()' |
986
 
        COMMENT = 'UPDATED NOW()' | COMMENT = 'UPDATED NOW()' | COMMENT = 'UPDATED NOW()' | COMMENT = 'UPDATED NOW()' |
987
 
        ENGINE = engine           ;
988
 
 
989
 
base_table_sequence:
990
 
        $sequence_begin CREATE TABLE if_not_exists base_table_item_s LIKE template_table_item ; ALTER TABLE $base_table_item_s ENGINE = engine ; INSERT INTO $base_table_item_s SELECT * FROM $template_table_item ; COMMIT ; wait_till_drop_table ; DROP TABLE $base_table_item_s $sequence_end ;
991
 
 
992
 
wait_till_drop_table:
993
 
        SELECT SLEEP( rand_val * $life_time_unit ) ;
994
 
 
995
 
temp_table_ddl:
996
 
        # Attention: temp_table_sequence is intentionally omitted, because no other session will be
997
 
        #            able to use this table.
998
 
        create_temp_table | create_temp_table | create_temp_table | create_temp_table | create_temp_table | create_temp_table |
999
 
        drop_temp_table   | alter_temp_table  ;
1000
 
 
1001
 
create_temp_table:
1002
 
        CREATE TEMPORARY TABLE if_not_exists temp_table_item_n { $create_table_item = $temp_table_item_n ; return undef } create_table_part ;
1003
 
 
1004
 
drop_temp_table:
1005
 
        # DROP two tables is in "drop_table_list"
1006
 
        # A pure DROP TABLE is allowed, but we get an implicit COMMITs for that.
1007
 
        DROP TEMPORARY TABLE if_exists temp_table_item_n |
1008
 
        DROP           TABLE if_exists temp_table_item_n ;
1009
 
 
1010
 
alter_temp_table:
1011
 
        ALTER ignore TABLE temp_table_item_n alter_base_temp_table_part ;
1012
 
 
1013
 
########## MAINTENANCE FOR ANY TABLE ####################
1014
 
# The server accepts these statements for all table types (VIEWs, base tables, ...) though they
1015
 
# should have partially no effect. We run them on all table types because everything which gets
1016
 
# accepted has to be checked even if the command should do nothing.
1017
 
# Example:
1018
 
#    OPTIMIZE ... TABLE <view> ...
1019
 
#       Table  Op Msg_type Msg_text
1020
 
#       test.v1   optimize Error Table 'test.v1' doesn't exist
1021
 
#       test.v1   optimize status   Operation failed
1022
 
#    OPTIMIZE ... TABLE <merge table> ...
1023
 
#       Table  Op      Msg_type        Msg_text
1024
 
#       test.t1m       optimize        note    The storage engine for the table doesn't support optimize
1025
 
#
1026
 
table_maintenance_ddl:
1027
 
        analyze_table | optimize_table | checksum_table | check_table | repair_table ;
1028
 
 
1029
 
analyze_table:
1030
 
        ANALYZE not_to_binlog_local TABLE table_list ;
1031
 
not_to_binlog_local:
1032
 
        | NO_WRITE_TO_BINLOG | LOCAL ;
1033
 
 
1034
 
optimize_table:
1035
 
        OPTIMIZE not_to_binlog_local TABLE table_list ;
1036
 
 
1037
 
checksum_table:
1038
 
        CHECKSUM TABLE table_list quick_extended ;
1039
 
quick_extended:
1040
 
        | quick | extended ;
1041
 
extended:
1042
 
        # Only 10 %
1043
 
        | | | | | | | | | EXTENDED ;
1044
 
 
1045
 
check_table:
1046
 
        CHECK TABLE table_list check_table_options ;
1047
 
check_table_options:
1048
 
        | FOR UPGRADE | QUICK | FAST | MEDIUM | EXTENDED | CHANGED ;
1049
 
 
1050
 
repair_table:
1051
 
        REPAIR not_to_binlog_local TABLE table_list quick extended use_frm ;
1052
 
 
1053
 
use_frm:
1054
 
        # Only 10 %
1055
 
        | | | | | | | |  | USE_FRM ;
1056
 
 
1057
 
 
1058
 
########## MIXED TABLE RELATED DDL #################################
1059
 
truncate_table:
1060
 
        TRUNCATE table_word table_no_view_item_n ;
1061
 
table_word:
1062
 
        | TABLE ;
1063
 
 
1064
 
drop_table_list:
1065
 
        # DROP one table is in "drop_*table"
1066
 
        # 1. We mix here all tables except VIEWs up.
1067
 
        # 2. We have an increased likelihood that the statement fails because of use of
1068
 
        #    - "temporary" (only correct in case of a temporary table)
1069
 
        #    - two tables (some might not exist)
1070
 
        DROP temporary TABLE if_exists table_no_view_item_n , table_no_view_item_n restrict_cascade ;
1071
 
 
1072
 
rename_table:
1073
 
        # RENAME TABLE works also on all types of tables (includes VIEWs)
1074
 
        RENAME TABLE rename_item_list ;
1075
 
rename_item_list:
1076
 
        rename_item | rename_item , rename_item ;
1077
 
rename_item:
1078
 
        # Preserve the object type (base,temp,....) and type (Normal) otherwise debugging becomes difficult and
1079
 
        # the concept with different lifetimes gets broken.
1080
 
        base_table_item_n  TO base_table_item_n  |
1081
 
        temp_table_item_n  TO temp_table_item_n  |
1082
 
        merge_table_item_n TO merge_table_item_n |
1083
 
        part_table_item_n  TO part_table_item_n  ;
1084
 
 
1085
 
rename_column:
1086
 
        ALTER TABLE table_no_view_item_s CHANGE COLUMN column_to_change my_column INT |
1087
 
        ALTER TABLE table_no_view_item_s CHANGE COLUMN my_column column_to_change INT ;
1088
 
 
1089
 
column_to_change:
1090
 
        `col_int` | `col_int_key` | `pk` ;
1091
 
 
1092
 
 
1093
 
########## MERGE TABLE DDL ####################
1094
 
merge_table_ddl:
1095
 
        create_merge_table   | create_merge_table | create_merge_table | create_merge_table   | create_merge_table |  create_merge_table |
1096
 
        drop_merge_table     | alter_merge_table  |
1097
 
        merge_table_sequence ;
1098
 
 
1099
 
create_merge_table:
1100
 
        # There is a high risk that the tables which we pick for merging do not fit together because they
1101
 
        # have different structures. We try to reduce this risk to end up with no merge table at all
1102
 
        # by the following:
1103
 
        # 1. Let the merge table have the structure of the first base table.
1104
 
        #    CREATE TABLE <merge table> LIKE <first base table>
1105
 
        # 2. Let the merge table be based on the first base table.
1106
 
        #    ALTER TABLE <merge table> ENGINE = MERGE UNION(<first base table>)
1107
 
        # 3. Add the second base table to the merge table.
1108
 
        #    ALTER TABLE <merge table> UNION(<first base table>, <second merge table>)
1109
 
        merge_init_n build_partner1 ; build_partner2 ; create_merge ;
1110
 
 
1111
 
insert_method:
1112
 
        | INSERT_METHOD = insert_method_value | INSERT_METHOD = insert_method_value | INSERT_METHOD = insert_method_value ;
1113
 
insert_method_value:
1114
 
        NO | FIRST | LAST ;
1115
 
 
1116
 
drop_merge_table:
1117
 
        # DROP two tables is in "drop_table_list"
1118
 
        DROP TABLE if_exists merge_table_item_n ;
1119
 
 
1120
 
merge_table_sequence:
1121
 
        # Notes:
1122
 
        # There is a significant likelihood that random picked table names as base for the merge table cannot
1123
 
        # be used for the creation of a merge table because the corresponding tables
1124
 
        # - must exist
1125
 
        # - use the storage engine MyISAM
1126
 
        # - have the same layout
1127
 
        # Therefore we create here all we need.
1128
 
        # The use of "base_table_name_n" for the tables to be merged guarantees that these tables
1129
 
        # are under full DDL/DML load.
1130
 
        # I do not DROP the underlying tables at sequence end because I hope that "drop_base_table" or similar will do this sooner or later.
1131
 
        $sequence_begin merge_init_s build_partner1 ; build_partner2 ; create_merge ; wait_till_drop_table ; DROP TABLE $mt $sequence_end ;
1132
 
 
1133
 
alter_merge_table:
1134
 
        # We do not change here the UNION because of the high risk that this fails.
1135
 
        # It is intentional that we use merge_table_name and not merge_table_name_n.
1136
 
        ALTER ignore TABLE merge_table_item_n COMMENT = 'UPDATED NOW()'           |
1137
 
        ALTER        TABLE merge_table_item_n INSERT_METHOD = insert_method_value ;
1138
 
 
1139
 
merge_init_s:
1140
 
        /* merge_table_item_s { $mt = $merge_table_item_s ; return undef } consists of ( base_table_item_s { $mp1 = $base_table_item_s ; return undef } , base_table_item_s { $mp2 = $base_table_item_s ; return undef } ) based on template_table_item */ ;
1141
 
merge_init_n:
1142
 
        /* merge_table_item_n { $mt = $merge_table_item_n ; return undef } consists of ( base_table_item_n { $mp1 = $base_table_item_n ; return undef } , base_table_item_n { $mp2 = $base_table_item_n ; return undef } ) based on template_table_item */ ;
1143
 
build_partner1:
1144
 
        # This also initializes $database_name and $base_table_name which gets used by the other commands within the sequence.
1145
 
        CREATE TABLE if_not_exists $mp1 LIKE $template_table_item ; ALTER TABLE $mp1 ENGINE = MyISAM ; INSERT INTO $mp1 SELECT * FROM $template_table_item ;
1146
 
build_partner2:
1147
 
        # This also initializes $database_name and $base_table_name which gets used by the other commands within the sequence.
1148
 
        CREATE TABLE if_not_exists $mp2 LIKE $template_table_item ; ALTER TABLE $mp2 ENGINE = MyISAM ; INSERT INTO $mp2 SELECT * FROM $template_table_item ;
1149
 
create_merge:
1150
 
        CREATE TABLE if_not_exists $mt LIKE $template_table_item ; ALTER TABLE $mt ENGINE = MERGE UNION ( $mp1 , $mp2 ); COMMIT ;
1151
 
 
1152
 
 
1153
 
########## PARTITIONED TABLE DDL ####################
1154
 
part_table_ddl:
1155
 
        create_part_table   | create_part_table | create_part_table | create_part_table | create_part_table | create_part_table |
1156
 
        drop_part_table     |
1157
 
        alter_part_table    |
1158
 
        part_table_sequence ;
1159
 
 
1160
 
create_part_table:
1161
 
        CREATE TABLE if_not_exists part_table_item_n ENGINE = MyISAM partition_algorithm AS SELECT * FROM template_table_item |
1162
 
        CREATE TABLE if_not_exists part_table_item_n ENGINE = MyISAM partition_algorithm AS SELECT * FROM template_table_item |
1163
 
        CREATE TABLE if_not_exists part_table_item_n ENGINE = MyISAM partition_algorithm AS used_select                       ;
1164
 
 
1165
 
partition_algorithm:
1166
 
        # We do not need sophisticated partitioning here.
1167
 
        PARTITION BY KEY (pk) PARTITIONS 2        |
1168
 
        PARTITION BY LINEAR HASH(pk) PARTITIONS 3 ;
1169
 
 
1170
 
drop_part_table:
1171
 
        # DROP two tables is in "drop_table_list"
1172
 
        DROP TABLE if_exists part_table_item_n ;
1173
 
 
1174
 
alter_part_table:
1175
 
        ALTER ignore TABLE part_table_item_n alter_part_table_part ;
1176
 
 
1177
 
alter_part_table_part:
1178
 
        partition_algorithm       |
1179
 
        COMMENT = 'UPDATED NOW()' ;
1180
 
 
1181
 
part_table_sequence:
1182
 
        $sequence_begin CREATE TABLE if_not_exists part_table_item_s ENGINE = MyISAM partition_algorithm AS SELECT * FROM template_table_item ; COMMIT ; wait_till_drop_table ; DROP TABLE $part_table_item_s $sequence_end ;
1183
 
 
1184
 
 
1185
 
########## VIEW DDL ####################
1186
 
view_ddl:
1187
 
        create_view   | create_view | create_view | create_view | create_view | create_view | create_view | create_view |
1188
 
        drop_view     | alter_view  |
1189
 
        view_sequence ;
1190
 
        
1191
 
create_view:
1192
 
        CREATE view_replace ALGORITHM = view_algoritm VIEW view_table_item_n AS used_select ;
1193
 
view_replace:
1194
 
        # Only 20 %
1195
 
        | | | | OR REPLACE ;
1196
 
view_algoritm:
1197
 
        UNDEFINED | MERGE | TEMPTABLE ;
1198
 
 
1199
 
drop_view:
1200
 
        DROP VIEW if_exists view_table_item_n restrict_cascade ;
1201
 
 
1202
 
restrict_cascade:
1203
 
        # RESTRICT and CASCADE, if given, are parsed and ignored.
1204
 
        | RESTRICT | CASCADE ;
1205
 
 
1206
 
alter_view:
1207
 
        # Attention: Only changing the algorithm is not allowed.
1208
 
        ALTER ALGORITHM = view_algoritm VIEW view_table_item_n AS used_select ;
1209
 
 
1210
 
view_sequence:
1211
 
        $sequence_begin CREATE ALGORITHM = view_algoritm VIEW view_table_item_s AS used_select ; COMMIT ; SELECT wait_short ; DROP VIEW $view_table_item_s $sequence_end ;
1212
 
 
1213
 
 
1214
 
########## STORED PROCEDURE DDL ####################
1215
 
procedure_ddl:
1216
 
        create_procedure   | create_procedure |
1217
 
        drop_procedure     | alter_procedure  |
1218
 
        procedure_sequence ;
1219
 
 
1220
 
create_procedure:
1221
 
        CREATE PROCEDURE procedure_item_n () BEGIN proc_stmt ; proc_stmt ; END ;
1222
 
proc_stmt:
1223
 
        select | update ;
1224
 
 
1225
 
drop_procedure:
1226
 
        DROP PROCEDURE if_exists procedure_item_n ;
1227
 
 
1228
 
alter_procedure:
1229
 
        ALTER PROCEDURE procedure_item_n COMMENT 'UPDATED NOW()' ;
1230
 
 
1231
 
procedure_sequence:
1232
 
        # FIXME: The PROCEDURE should touch base_table_name_s only .
1233
 
        $sequence_begin CREATE PROCEDURE procedure_item_s () BEGIN proc_stmt ; proc_stmt ; END ; COMMIT ; SELECT wait_short ; DROP PROCEDURE $procedure_item_s $sequence_end ;
1234
 
 
1235
 
 
1236
 
########## STORED FUNCTION DDL ####################
1237
 
function_ddl:
1238
 
        create_function   | create_function |
1239
 
        drop_function     | alter_function  |
1240
 
        function_sequence ;
1241
 
 
1242
 
create_function:
1243
 
        CREATE FUNCTION function_item_n () RETURNS INTEGER BEGIN func_statement ; func_statement ; RETURN 1 ; END ;
1244
 
func_statement:
1245
 
        # All result sets of queries within a function must be processed within the function.
1246
 
        # -> Use a CURSOR or SELECT ... INTO ....
1247
 
        SET @my_var = 1 | SELECT MAX( random_field_quoted1 ) FROM table_item INTO @my_var | insert | delete ;
1248
 
 
1249
 
drop_function:
1250
 
        DROP FUNCTION if_exists function_item_n ;
1251
 
 
1252
 
alter_function:
1253
 
        ALTER FUNCTION function_item_n COMMENT 'UPDATED NOW()' ;
1254
 
 
1255
 
function_sequence:
1256
 
        $sequence_begin CREATE FUNCTION function_item_s () RETURNS INTEGER RETURN ( SELECT MOD( COUNT( DISTINCT random_field_quoted1 ) , 10 ) FROM table_item_s ) ; COMMIT ; SELECT wait_short ; DROP FUNCTION $function_item_s $sequence_end ;
1257
 
 
1258
 
 
1259
 
########## TRIGGER DDL ####################
1260
 
trigger_ddl:
1261
 
        create_trigger   | create_trigger |
1262
 
        drop_trigger     |
1263
 
        trigger_sequence ;
1264
 
        
1265
 
create_trigger:
1266
 
        CREATE TRIGGER trigger_item_n trigger_time trigger_event ON base_table_name_n FOR EACH ROW BEGIN trigger_action ; END ;
1267
 
trigger_time:
1268
 
        BEFORE | AFTER ;
1269
 
trigger_event:
1270
 
        INSERT | DELETE | UPDATE ;
1271
 
trigger_action:
1272
 
        insert | replace | delete | update | CALL procedure_item ;
1273
 
 
1274
 
drop_trigger:
1275
 
        DROP TRIGGER if_exists trigger_item_n ;
1276
 
 
1277
 
trigger_sequence:
1278
 
        # FIXME: The action within the trigger should touch base_table_name_s only.
1279
 
        $sequence_begin CREATE TRIGGER trigger_item_s trigger_time trigger_event ON table_item_s FOR EACH ROW BEGIN trigger_action ; END ; COMMIT ; SELECT wait_short ; DROP TRIGGER $trigger_item_s $sequence_end ;
1280
 
 
1281
 
 
1282
 
########## EVENT DDL ####################
1283
 
event_ddl:
1284
 
        create_event | create_event | create_event | create_event | create_event | create_event | create_event | create_event |
1285
 
        drop_event   | alter_event  | drop_event   | alter_event  | drop_event   | alter_event  | drop_event   | alter_event  |
1286
 
        event_scheduler_on | event_scheduler_off ;
1287
 
create_event:
1288
 
        CREATE EVENT if_not_exists event_item_s ON SCHEDULE EVERY 10 SECOND STARTS NOW() ENDS NOW() + INTERVAL 21 SECOND completion_handling DO SELECT * FROM table_item LIMIT 1 ;
1289
 
completion_handling:
1290
 
        ON COMPLETION not_or_empty PRESERVE ;
1291
 
drop_event:
1292
 
        DROP EVENT if_exists event_item_s ;
1293
 
alter_event:
1294
 
        ALTER EVENT event_item_s COMMENT 'UPDATED NOW()';
1295
 
 
1296
 
########## DML ####################
1297
 
 
1298
 
dml:
1299
 
        # Have only 10 % prepared statements.
1300
 
        #    SQL Statements to be handled via PREPARE, EXECUTE and DEALLOCATE cause a bigger amount of
1301
 
        #    failing statements than SQL statements which are executed in non prepared mode.
1302
 
        #    The reason is that we run the EXECUTE and DEALLOCATE independent of the outcome of the
1303
 
        #    PREPARE. So if the PREPARE fails because some table is missing, we loose the old
1304
 
        #    prepared statement handle, if there was any, and get no new one. Therefore the succeeding
1305
 
        #    EXECUTE and DEALLOCATE will also failcw because of missing statement handle.
1306
 
        dml2 | dml2 | dml2 | dml2 | dml2 | dml2 | dml2 | dml2 | dml2 |
1307
 
        PREPARE st1 FROM " dml2 " ; EXECUTE st1 ; DEALLOCATE PREPARE st1 ;
1308
 
 
1309
 
dml2:
1310
 
        select | select | select  |
1311
 
        do     | insert | replace | delete | update | CALL procedure_item | show | is_selects ;
1312
 
 
1313
 
########## DO ####################
1314
 
do:
1315
 
        DO 1                                                                                                   |
1316
 
        # A lot options like HIGH_PRIORITY (after SELECT ) etc. are not allowed in connection with DO.
1317
 
        # The SELECT must give one column.
1318
 
        DO ( SELECT COUNT(*) FROM table_item WHERE `pk` BETWEEN _digit[invariant] AND _digit[invariant] + 20 ) |
1319
 
        DO user_lock_action                                                                                    ;
1320
 
 
1321
 
user_lock_action:
1322
 
        IS_FREE_LOCK(TRIM(' _digit '))                                |
1323
 
        IS_USED_LOCK(TRIM(' _digit '))                                |
1324
 
        RELEASE_LOCK(TRIM(' _digit '))                                |
1325
 
        GET_LOCK(TRIM(' _digit '), 0.5 * rand_val * $life_time_unit ) ;
1326
 
 
1327
 
########## SELECT ####################
1328
 
select:
1329
 
        select_normal | select_normal | select_normal | select_normal | select_with_sleep ;
1330
 
 
1331
 
select_normal:
1332
 
        # select = Just a query = A statement starting with "SELECT".
1333
 
        select_part1 addition into for_update_lock_in_share_mode ;
1334
 
 
1335
 
select_with_sleep:
1336
 
        # Run a SELECT which holds locks (if there are any) longer.
1337
 
        SELECT 1 FROM table_item WHERE wait_short = 0 LIMIT 1 ;
1338
 
 
1339
 
used_select:
1340
 
        # used_select = The SELECT used in CREATE VIEW/TABLE ... AS SELECT, INSERT INTO ... SELECT
1341
 
        # "PROCEDURE ANALYSE" and "INTO DUMPFILE/OUTFILE/@var" are not generated because they
1342
 
        # are partially disallowed or cause garbage (PROCEDURE).
1343
 
        select_part1 addition_no_procedure ;
1344
 
 
1345
 
select_part1:
1346
 
        SELECT high_priority cache_results table_field_list_or_star FROM table_in_select as A ;
1347
 
 
1348
 
cache_results:
1349
 
        | sql_no_cache | sql_cache ;
1350
 
sql_no_cache:
1351
 
        # Only 10 %
1352
 
        | | | | | | | | |
1353
 
        SQL_NO_CACHE ;
1354
 
sql_cache:
1355
 
        # Only 10 %
1356
 
        | | | | | | | | |
1357
 
        SQL_CACHE ;
1358
 
 
1359
 
table_in_select:
1360
 
        # Attention: In case of CREATE VIEW a subquery in the FROM clause (derived table) is disallowed.
1361
 
        #            Therefore they should be rare.
1362
 
        table_item | table_item | table_item | table_item | table_item |
1363
 
        ( SELECT table_field_list_or_star FROM table_item )            ;
1364
 
 
1365
 
addition:
1366
 
        # Involve one (simple where condition) or two tables (subquery | join | union)
1367
 
        where procedure_analyze       |
1368
 
        subquery procedure_analyze    |
1369
 
        join where procedure_analyze  |
1370
 
        procedure_analyze union where ;
1371
 
 
1372
 
addition_no_procedure:
1373
 
        # Involve one (simple where condition) or two tables (subquery | join | union)
1374
 
        # Don't add procedure_analyze.
1375
 
        where | where | where | where | where | where | where |
1376
 
        subquery    |
1377
 
        join where  |
1378
 
        union where ;
1379
 
 
1380
 
where:
1381
 
        # The very selective condition is intentional.
1382
 
        # It should ensure that
1383
 
        # - result sets (just SELECT) do not become too big because this affects the performance in general and
1384
 
        #   the memery consumption of RQG (I had a ~ 3.5 GB virt memory RQG perl process during some simplifier run!)
1385
 
        # - tables (INSERT ... SELECT, REPLACE) do not become too big
1386
 
        # - tables (DELETE) do not become permanent empty
1387
 
        # Please note that there are some cases where LIMIT cannot be used.
1388
 
        WHERE `pk` BETWEEN _digit[invariant] AND _digit[invariant] + 1 |
1389
 
        WHERE function_item () = _digit AND `pk` = _digit              ;
1390
 
 
1391
 
union:
1392
 
        UNION SELECT * FROM table_in_select as B ;
1393
 
 
1394
 
join:
1395
 
        # Do not place a where condition here.
1396
 
        NATURAL JOIN table_item B ;
1397
 
 
1398
 
subquery:
1399
 
        correlated     |
1400
 
        non_correlated ;
1401
 
subquery_part1:
1402
 
        WHERE A.`pk` IN ( SELECT `pk` FROM table_item AS B WHERE B.`pk` = ;
1403
 
correlated:
1404
 
        subquery_part1 A.`pk` ) ;
1405
 
non_correlated:
1406
 
        subquery_part1 _digit ) ;
1407
 
 
1408
 
procedure_analyze:
1409
 
        # Correct place of PROCEDURE ANALYSE( 10 , 2000 )
1410
 
        # 0. Attention: The result set of the SELECT gets replaced  by PROCEDURE ANALYSE output.
1411
 
        # 1. WHERE ... PROCEDURE (no UNION of JOIN)
1412
 
        # 2. SELECT ... PROCEDURE UNION SELECT ... (never after UNION)
1413
 
        # 3. SELECT ... FROM ... PROCEDURE ... JOIN (never at statement end)
1414
 
        # 4. Never in a SELECT which does not use a table
1415
 
        # 5. Any INTO DUMPFILE/OUTFILE/@var must be after PROCEDURE ANALYSE.
1416
 
        #    The content of DUMPFILE/OUTFILE/@var is from the PROCEDURE ANALYSE result set.
1417
 
        # 6. CREATE TABLE ... AS SELECT PROCEDURE -> The table contains the PROCEDURE result set.
1418
 
        # 7. INSERT ... SELECT ... PROCEDURE -> It's tried to INSERT the PROCEDURE result set.
1419
 
        #    High likelihood of ER_WRONG_VALUE_COUNT_ON_ROW
1420
 
        # Only 10 %
1421
 
        | | | | | | | |  |
1422
 
        PROCEDURE ANALYSE( 10 , 2000 ) ;
1423
 
 
1424
 
into:
1425
 
        # Only 10 %
1426
 
        | | | | | | | | |
1427
 
        INTO into_object ;
1428
 
 
1429
 
into_object:
1430
 
        # INSERT ... SELECT ... INTO DUMPFILE/OUTFILE/@var is not allowed
1431
 
        # This also applies to CREATE TABLE ... AS SELECT ... INTO DUMPFILE/OUTFILE/@var
1432
 
        # 1. @_letter is in average not enough variables compared to the column list.
1433
 
        #    -> @_letter disabled till I find a solution.
1434
 
        # 2. DUMPFILE requires a result set of one row
1435
 
        #    Therefore 1172 Result consisted of more than one row is very likely.
1436
 
        # OUTFILE _tmpnam | DUMPFILE _tmpnam | @_letter ;
1437
 
        OUTFILE _tmpnam ;
1438
 
 
1439
 
for_update_lock_in_share_mode:
1440
 
        | for_update | lock_share ;
1441
 
for_update:
1442
 
        # Only 10 %
1443
 
        | | | | | | | | |
1444
 
        FOR UPDATE ;
1445
 
lock_share:
1446
 
        # Only 10 %
1447
 
        | | | | | | | | |
1448
 
        LOCK IN SHARE MODE ;
1449
 
 
1450
 
 
1451
 
########## INSERT ####################
1452
 
insert:
1453
 
        insert_normal | insert_normal | insert_normal | insert_normal | insert_with_sleep ;
1454
 
insert_normal:
1455
 
        INSERT low_priority_delayed_high_priority ignore into_word table_item simple_or_complicated on_duplicate_key_update ;
1456
 
simple_or_complicated:
1457
 
        ( random_field_quoted1 ) VALUES ( digit_or_null ) |
1458
 
        braced_table_field_list used_select LIMIT 1       ;
1459
 
on_duplicate_key_update:
1460
 
        # Only 10 %
1461
 
        | | | | | | | | |
1462
 
        ON DUPLICATE KEY UPDATE random_field_quoted1 = _digit ;
1463
 
insert_with_sleep:
1464
 
        INSERT ignore INTO table_item ( table_field_list ) SELECT $table_field_list FROM table_item WHERE wait_short = 0 LIMIT 1 ;
1465
 
 
1466
 
 
1467
 
########## REPLACE ####################
1468
 
replace:
1469
 
        # 1. No ON DUPLICATE .... option. In case of DUPLICATE key it runs DELETE old row INSERT new row.
1470
 
        # 2. HIGH_PRIORITY is not allowed
1471
 
        REPLACE low_priority_delayed into_word table_item simple_or_complicated ;
1472
 
 
1473
 
 
1474
 
########## DUMP_LOAD_DATA ####################
1475
 
dump_load_data_sequence:
1476
 
        # We omit a lot stuff which could be assigned after the table name. This stuff should
1477
 
        # be important for locking tests.
1478
 
        # We generate an outfile so that we have a chance to find an infile.
1479
 
        # Go with the next command as soon as "LOCAL" is supported. (not supported in 5.4)
1480
 
        # generate_outfile ; LOAD DATA low_priority_concurrent local_or_empty INFILE tmpnam replace_ignore INTO TABLE table_item ;
1481
 
        generate_outfile ; LOAD DATA low_priority_concurrent INFILE tmpnam replace_ignore INTO TABLE table_item ;
1482
 
generate_outfile:
1483
 
        SELECT * FROM template_table_item INTO OUTFILE _tmpnam ;
1484
 
low_priority_concurrent:
1485
 
        | low_priority | concurrent ;
1486
 
concurrent:
1487
 
        # Only 20 % <> empty.
1488
 
        | | | | CONCURRENT ;
1489
 
replace_ignore:
1490
 
        | replace_option | ignore ;
1491
 
 
1492
 
 
1493
 
########## GRANT_REVOKE ####################
1494
 
# We mix here some trouble I can imagine on mysql.tables_priv.  It's basically how we access it's content.
1495
 
grant_revoke:
1496
 
        GRANT  ALL ON table_item TO otto@localhost                                           |
1497
 
        REVOKE ALL ON table_item FROM otto@localhost                                         |
1498
 
        SELECT COUNT(*) FROM mysql.tables_priv WHERE user = LOWER('OTTO')                    |
1499
 
        DELETE FROM mysql.tables_priv WHERE user = LOWER('OTTO') ; FLUSH PRIVILEGES          |
1500
 
        /* table_item */ INSERT INTO mysql.tables_priv (host,db,user,table_name,grantor,table_priv) VALUES (LOWER('LOCALHOST'),TRIM(' $database '),LOWER('OTTO'),TRIM(' $table_name '),LOWER('ROOT@LOCALHOST'),'Select') ; FLUSH PRIVILEGES |
1501
 
        SELECT COUNT(*) FROM information_schema.table_privileges WHERE grantee LIKE '%OTTO%' |
1502
 
        SHOW GRANTS FOR otto@localhost                                                       ;
1503
 
 
1504
 
########## SQL MODE ########################
1505
 
sql_mode:
1506
 
        empty_mode | empty_mode | empty_mode | empty_mode |
1507
 
        empty_mode | empty_mode | empty_mode | empty_mode |
1508
 
        empty_mode | empty_mode | empty_mode | empty_mode |
1509
 
        traditional_mode ;
1510
 
empty_mode:
1511
 
        SET SESSION SQL_MODE='' ;
1512
 
traditional_mode:
1513
 
        SET SESSION SQL_MODE=LOWER('TRADITIONAL');
1514
 
 
1515
 
 
1516
 
########## DELETE ####################
1517
 
# FIXME: DELETE IGNORE is missing
1518
 
delete:
1519
 
        delete_normal | delete_normal | delete_normal | delete_normal | delete_with_sleep ;
1520
 
delete_normal:
1521
 
        # LIMIT row_count is disallowed in case we have a multi table delete.
1522
 
        # Example: DELETE low_priority quick ignore A , B FROM table_item AS A join where LIMIT _digit |
1523
 
        # DELETE is ugly because a table alias is not allowed.
1524
 
        DELETE low_priority quick ignore       FROM table_item      WHERE `pk` > _digit LIMIT 1 |
1525
 
        DELETE low_priority quick ignore A , B FROM table_item AS A join where                  |
1526
 
        DELETE low_priority quick ignore A     FROM table_item AS A where_subquery              ;
1527
 
where_subquery:
1528
 
        where | subquery ;
1529
 
delete_with_sleep:
1530
 
        DELETE low_priority quick       FROM table_item      WHERE   `pk` + wait_short = _digit ;
1531
 
 
1532
 
 
1533
 
########## UPDATE ####################
1534
 
update:
1535
 
        update_normal | update_normal | update_normal | update_normal | update_with_sleep ;
1536
 
update_normal:
1537
 
        UPDATE low_priority ignore table_item SET random_field_quoted1 = _digit WHERE `pk` > _digit LIMIT _digit                |
1538
 
        UPDATE low_priority ignore table_item AS A join SET A. random_field_quoted1 = _digit , B. random_field_quoted1 = _digit ;
1539
 
update_with_sleep:
1540
 
        UPDATE low_priority ignore table_item SET random_field_quoted1 = _digit WHERE wait_short = 0 LIMIT 1 ;
1541
 
 
1542
 
 
1543
 
########## LOCK/UNLOCK ####################
1544
 
lock_unlock:
1545
 
        lock | unlock | unlock | unlock | unlock ;
1546
 
lock:
1547
 
        LOCK TABLES lock_list ;
1548
 
lock_list:
1549
 
        # Less likelihood for lists, because they
1550
 
        # - are most probably less often used
1551
 
        # - cause a higher likelihood of "table does not exist" errors.
1552
 
        lock_item | lock_item | lock_item | lock_item | lock_item | lock_item | lock_item | lock_item | lock_item |
1553
 
        lock_item , lock_item ;
1554
 
lock_item:
1555
 
        # Have a low risk to get a clash of same table alias.
1556
 
        table_item AS _letter lock_type ;
1557
 
lock_type:
1558
 
        READ local_or_empty      |
1559
 
        low_priority WRITE       |
1560
 
        IN SHARE MODE nowait     |
1561
 
        IN SHARE MODE nowait     |
1562
 
        IN SHARE MODE nowait     |
1563
 
        IN EXCLUSIVE MODE nowait |
1564
 
        IN EXCLUSIVE MODE nowait |
1565
 
        IN EXCLUSIVE MODE nowait ;
1566
 
nowait:
1567
 
        NOWAIT | ;
1568
 
 
1569
 
unlock:
1570
 
        UNLOCK TABLES ;
1571
 
 
1572
 
 
1573
 
########## FLUSH ####################
1574
 
flush:
1575
 
        # WITH READ LOCK causes that nearly all following statements will fail with
1576
 
        # Can't execute the query because you have a conflicting read lock
1577
 
        # Therefore it should
1578
 
        # - be rare
1579
 
        # - last only very short time
1580
 
        # So I put it into a sequence with FLUSH ... ; wait a bit ; UNLOCK TABLES
1581
 
        FLUSH TABLE table_list | FLUSH TABLE table_list | FLUSH TABLE table_list |
1582
 
        FLUSH TABLE table_list | FLUSH TABLE table_list | FLUSH TABLE table_list |
1583
 
        FLUSH TABLE table_list | FLUSH TABLE table_list | FLUSH TABLE table_list |
1584
 
        FLUSH TABLE table_list | FLUSH TABLE table_list | FLUSH TABLE table_list |
1585
 
        FLUSH TABLES | FLUSH TABLES | FLUSH TABLES |
1586
 
        FLUSH TABLES | FLUSH TABLES | FLUSH TABLES |
1587
 
        FLUSH TABLES table_list WITH READ LOCK | UNLOCK TABLES | UNLOCK TABLES |
1588
 
        FLUSH TABLES WITH READ LOCK ; SELECT wait_short ; UNLOCK TABLES ;
1589
 
 
1590
 
 
1591
 
########## TINY GRAMMAR ITEMS USED AT MANY PLACES ###########
1592
 
as:
1593
 
        | AS ;
1594
 
 
1595
 
braced_table_field_list:
1596
 
        # In case of <empty> for braced_table_field_list we have a significant fraction of
1597
 
        # INSERT/REPLACE INTO <table> <no field list>
1598
 
        # failing with: 1394 Can not insert into join view 'test.t1_view_0_S' without fields list
1599
 
        # Therefore <empty> is only 20 %.
1600
 
        ( table_field_list ) | ( table_field_list ) | ( table_field_list ) | ( table_field_list ) | ;
1601
 
 
1602
 
comparison_operator:
1603
 
        =  |
1604
 
        <= |
1605
 
        >= |
1606
 
        <  |
1607
 
        >  ;
1608
 
 
1609
 
 
1610
 
default_word:
1611
 
        | DEFAULT ;
1612
 
 
1613
 
digit_or_null:
1614
 
        _digit | _digit | _digit | _digit | _digit | _digit | _digit | _digit | _digit |
1615
 
        NULL ;
1616
 
 
1617
 
engine:
1618
 
        MEMORY | MyISAM | InnoDB ;
1619
 
 
1620
 
equal:
1621
 
        | = ;
1622
 
 
1623
 
delayed:
1624
 
        # Only 10 %
1625
 
        | | | | | | | | | DELAYED ;
1626
 
 
1627
 
high_priority:
1628
 
        # Only 20 %
1629
 
        | | | | HIGH_PRIORITY ;
1630
 
 
1631
 
ignore:
1632
 
        # Only 10 %
1633
 
        | | | | | | | | |
1634
 
        IGNORE ;
1635
 
 
1636
 
if_exists:
1637
 
        # 90 %, this reduces the amount of failing DROPs
1638
 
        | IF EXISTS | IF EXISTS | IF EXISTS | IF EXISTS | IF EXISTS | IF EXISTS | IF EXISTS | IF EXISTS | IF EXISTS ;
1639
 
 
1640
 
if_not_exists:
1641
 
        # 90 %, this reduces the amount of failing CREATEs
1642
 
        | IF NOT EXISTS | IF NOT EXISTS | IF NOT EXISTS | IF NOT EXISTS | IF NOT EXISTS | IF NOT EXISTS | IF NOT EXISTS | IF NOT EXISTS | IF NOT EXISTS ;
1643
 
 
1644
 
into_word:
1645
 
        # Only 50 %
1646
 
        | INTO ;
1647
 
 
1648
 
local_or_empty:
1649
 
        # Only 20%
1650
 
        | | | | LOCAL ;
1651
 
 
1652
 
low_priority_delayed_high_priority:
1653
 
        | low_priority | delayed | high_priority ;
1654
 
 
1655
 
low_priority_delayed:
1656
 
        | low_priority | delayed ;
1657
 
 
1658
 
low_priority:
1659
 
        # Only 10 %
1660
 
        | | | | | | | | |
1661
 
        LOW_PRIORITY ;
1662
 
 
1663
 
no_or_empty:
1664
 
        | NO ;
1665
 
 
1666
 
not_or_empty:
1667
 
        | NOT ;
1668
 
 
1669
 
quick:
1670
 
        # Only 10 %
1671
 
        | | | | | | | | |
1672
 
        QUICK ;
1673
 
 
1674
 
random_field_quoted:
1675
 
        'int_key' | 'int' | 'pk' ;
1676
 
 
1677
 
random_field_quoted1:
1678
 
        `col_int_key` | `col_int` | `pk` ;
1679
 
 
1680
 
replace_option:
1681
 
        # Only 20 % <> empty.
1682
 
        | | | | REPLACE ;
1683
 
 
1684
 
savepoint_or_empty:
1685
 
        SAVEPOINT | ;
1686
 
 
1687
 
sql_buffer_result:
1688
 
        # Only 50%
1689
 
        | SQL_BUFFER_RESULT ;
1690
 
 
1691
 
table_field_list_or_star:
1692
 
        table_field_list | table_field_list | table_field_list | table_field_list |
1693
 
        { $table_field_list = "*" }                                               ;
1694
 
 
1695
 
table_field_list:
1696
 
        # It is intentional that the next line will lead to ER_FIELD_SPECIFIED_TWICE
1697
 
        # in case it is used in INSERT INTO <table> ( table_field_list )
1698
 
        { $table_field_list = "`pk`      , `col_int_key` , `pk`          "} |
1699
 
        { $table_field_list = "`col_int_key` , `col_int`     , `pk`      "} |
1700
 
        { $table_field_list = "`col_int_key` , `pk`      , `col_int`     "} |
1701
 
        { $table_field_list = "`col_int`     , `pk`      , `col_int_key` "} |
1702
 
        { $table_field_list = "`col_int`     , `col_int_key` , `pk`      "} |
1703
 
        { $table_field_list = "`pk`      , `col_int`     , `col_int_key` "} |
1704
 
        { $table_field_list = "`pk`      , `col_int_key` , `col_int`     "} ;
1705
 
 
1706
 
temporary:
1707
 
        # Attention:
1708
 
        # Do not apply CREATE/DROP TEMPORARY on "long life" whatever tables.
1709
 
        # Use "short life" (-> <whatever>_n) tables only.
1710
 
        # 1. In case of "long life" (-> <whatever>_s) tables the CREATE and DROP must be within
1711
 
        #    a sequence with some "wait_till_drop_table" between. TEMPORARY tables are session specific.
1712
 
        #    So no other session can use this table.
1713
 
        # 2. In case of "short life" tables the CREATE and DROP are isolated. So the session
1714
 
        #    which created the table will pick a random statement and maybe do something on
1715
 
        #    the table <> DROP.
1716
 
        # Only 10 % because no other session can use this table.
1717
 
        | | | | | | | | |
1718
 
        TEMPORARY ;
1719
 
 
1720
 
wait_short:
1721
 
        SLEEP( 0.5 * rand_val * $life_time_unit ) ;
1722
 
 
1723
 
work_or_empty:
1724
 
        | WORK ;
1725
 
 
1726
 
zero_or_one:
1727
 
        0 | 1 ;
1728