~ubuntu-branches/ubuntu/saucy/drizzle/saucy-proposed

« back to all changes in this revision

Viewing changes to tests/randgen/conf/optimizer/optimizer_no_subquery_portable.yy

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2008-2010 Sun Microsystems, Inc. All rights reserved.
 
2
# Use is subject to license terms.
 
3
#
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; version 2 of the License.
 
7
#
 
8
# This program is distributed in the hope that it will be useful, but
 
9
# WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 
11
# General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
 
16
# USA
 
17
 
 
18
# **NOTE** Joins for this grammar are currently not working as intended.
 
19
# For example, if we have tables 1, 2, and 3, we end up with ON conditions that 
 
20
# only involve tables 2 and 3.
 
21
# This will be fixed, but initial attempts at altering this had a negative 
 
22
# impact on the coverage the test was providing.  To be fixed when scheduling 
 
23
# permits.  We are still seeing significant coverage with the grammar as-is.
 
24
 
 
25
################################################################################
 
26
# optimizer_no_subquery.yy:  Random Query Generator grammar for testing        #
 
27
#                            non-subquery optimizations.  This grammar         #
 
28
#                            *should* hit the optimizations listed here:       #
 
29
#                    https://inside.mysql.com/wiki/Optimizer_grammar_worksheet #
 
30
# see:  WL#5006 Random Query Generator testing of Azalea Optimizer- subqueries #
 
31
#       https://intranet.mysql.com/worklog/QA-Sprint/?tid=5006                 #
 
32
#                                                                              #
 
33
# recommendations:                                                             #
 
34
#       queries: 10k+.  We can see a lot with lower values, but over 10k is    #
 
35
#                best.  The intersect optimization happens with low frequency  #
 
36
#                so larger values help us to hit it at least some of the time  #
 
37
#       engines: MyISAM *and* Innodb.  Certain optimizations are only hit with #
 
38
#                one engine or another and we should use both to ensure we     #
 
39
#                are getting maximum coverage                                  #
 
40
#       Validators:  ResultsetComparatorSimplify                               #
 
41
#                      - used on server-server comparisons                     #
 
42
#                    Transformer - used on a single server                     #
 
43
#                      - creates equivalent versions of a single query         # 
 
44
#                    SelectStability - used on a single server                 #
 
45
#                      - ensures the same query produces stable result sets    #
 
46
################################################################################
 
47
 
 
48
################################################################################
 
49
# The perl code in {} helps us with bookkeeping for writing more sensible      #
 
50
# queries.  We need to keep track of these items to ensure we get interesting  #
 
51
# and stable queries that find bugs rather than wondering if our query is      #
 
52
# dodgy.                                                                       #
 
53
################################################################################
 
54
query:
 
55
        { @nonaggregates = () ; $tables = 0 ; $fields = 0 ; "" } query_type ;
 
56
 
 
57
 
 
58
query_type:
 
59
        main_select | main_select | main_select |  loose_scan ;
 
60
 
 
61
################################################################################
 
62
# The loose* rules listed below are to hit the 'Using index for group-by'       #
 
63
# optimization.  This optimization has some strict requirements, thus          #
 
64
# we needed a separate query pattern to ensure we hit it.                      #
 
65
################################################################################
 
66
loose_scan:
 
67
        SELECT distinct loose_select_clause
 
68
        FROM new_table_item
 
69
        WHERE generic_where_list;
 
70
#        group_by_clause ;
 
71
 
 
72
loose_select_clause:
 
73
        loose_select_list ;
 
74
#        MIN( _field_indexed) AS { "field".++$fields } , loose_select_list |
 
75
#        MAX( _field_indexed) AS { "field".++$fields } , loose_select_list |
 
76
#        MIN( _field_indexed[invariant] ) AS { "field".++$fields }, MAX( _field_indexed[invariant] ) AS { "field".++$fields }, loose_select_list ;
 
77
 
 
78
loose_select_list:
 
79
        loose_select_item | 
 
80
        loose_select_item , loose_select_list ;
 
81
 
 
82
loose_select_item:
 
83
        _field AS { my $f = "field".++$fields ; push @nonaggregates , $f ; $f } ;                
 
84
        
 
85
################################################################################
 
86
# The bulk of interesting things happen with this main rule                    #
 
87
################################################################################
 
88
main_select:
 
89
        SELECT distinct select_option select_list
 
90
        FROM join_list
 
91
        where_clause
 
92
#       group_by_clause
 
93
#        having_clause
 
94
        order_by_clause ;
 
95
 
 
96
distinct: ;
 
97
# DISTINCT | | | |  ;
 
98
 
 
99
select_option:  | | | | | | | | | SQL_SMALL_RESULT ;
 
100
 
 
101
select_list:
 
102
        new_select_item |
 
103
        new_select_item , select_list |
 
104
        new_select_item , select_list ;
 
105
 
 
106
join_list:
 
107
################################################################################
 
108
# this limits us to 2 and 3 table joins / can use it if we hit                 #
 
109
# too many mega-join conditions which take too long to run                     #
 
110
################################################################################
 
111
        ( new_table_item join_type new_table_item ON (join_condition_list ) ) |
 
112
        ( new_table_item join_type ( ( new_table_item join_type new_table_item ON (join_condition_list ) ) ) ON (join_condition_list ) ) ;
 
113
 
 
114
join_list_disabled:
 
115
################################################################################
 
116
# preventing deep join nesting for run time / table access methods are more    #
 
117
# important here - join.yy can provide deeper join coverage                    #
 
118
# Enabling this / swapping out with join_list above can produce some           #
 
119
# time-consuming queries.                                                      #
 
120
################################################################################
 
121
 
 
122
        new_table_item |
 
123
        ( new_table_item join_type join_list ON (join_condition_list ) ) ;
 
124
 
 
125
join_type:
 
126
        INNER JOIN | left_right outer JOIN | STRAIGHT_JOIN ;  
 
127
 
 
128
join_condition_list:
 
129
    join_condition_item | 
 
130
    ( join_condition_item ) and_or ( join_condition_item ) |
 
131
    ( current_table_item  .`pk` arithmetic_operator previous_table_item . int_field_name ) AND (current_table_item  .`pk` arithmetic_operator previous_table_item . int_field_name ) ;    
 
132
join_condition_item:
 
133
     current_table_item . int_indexed = previous_table_item . int_field_name  |
 
134
     current_table_item . int_field_name = previous_table_item . int_indexed  |
 
135
     current_table_item . `col_varchar_key` = previous_table_item . char_field_name |
 
136
     current_table_item . char_field_name = previous_table_item . `col_varchar_key` |
 
137
     current_table_item . int_indexed arithmetic_operator previous_table_item . int_field_name  |
 
138
     current_table_item . int_field_name arithmetic_operator previous_table_item . int_indexed  |
 
139
     current_table_item . `col_varchar_key` arithmetic_operator previous_table_item . char_field_name |
 
140
     current_table_item . char_field_name arithmetic_operator previous_table_item . `col_varchar_key`;
 
141
 
 
142
 
 
143
left_right:
 
144
        LEFT | RIGHT ;
 
145
 
 
146
outer:
 
147
        | OUTER ;
 
148
 
 
149
where_clause:
 
150
        | WHERE where_list ;
 
151
 
 
152
 
 
153
where_list:
 
154
        generic_where_list |
 
155
        range_predicate1_list | range_predicate2_list |
 
156
        range_predicate1_list and_or generic_where_list |
 
157
        range_predicate2_list and_or generic_where_list ;
 
158
 
 
159
 
 
160
generic_where_list:
 
161
        where_item |
 
162
        ( where_list and_or where_item ) ;
 
163
 
 
164
not:
 
165
        | | | NOT;
 
166
 
 
167
################################################################################
 
168
# The IS not NULL values in where_item are to hit the ref_or_null and          #
 
169
# the not_exists optimizations.  The LIKE '%a%' rule is to try to hit the      #
 
170
# rnd_pos optimization                                                         #
 
171
################################################################################
 
172
where_item:
 
173
        table1 .`pk` arithmetic_operator existing_table_item . int_field_name  |
 
174
        table1 .`pk` arithmetic_operator existing_table_item . int_field_name  |
 
175
        existing_table_item . int_field_name arithmetic_operator existing_table_item . int_field_name |
 
176
        existing_table_item . char_field_name arithmetic_operator existing_table_item . char_field_name |
 
177
        existing_table_item . int_field_name arithmetic_operator int_value  |
 
178
        existing_table_item . char_field_name arithmetic_operator char_value  |
 
179
        table1 .`pk` IS not NULL |
 
180
        table1 . _field IS not NULL |
 
181
        table1 . int_indexed arithmetic_operator int_value AND ( table1 . char_field_name LIKE '%a%' OR table1.char_field_name LIKE '%b%') ;
 
182
 
 
183
################################################################################
 
184
# The range_predicate_1* rules below are in place to ensure we hit the         #
 
185
# index_merge/sort_union optimization.                                         #
 
186
# NOTE: combinations of the predicate_1 and predicate_2 rules tend to hit the  #
 
187
# index_merge/intersect optimization                                           #
 
188
################################################################################
 
189
 
 
190
range_predicate1_list:
 
191
      range_predicate1_item | 
 
192
      ( range_predicate1_item OR range_predicate1_list ) ;
 
193
 
 
194
range_predicate1_item:
 
195
         table1 . int_indexed not BETWEEN _tinyint_unsigned[invariant] AND ( _tinyint_unsigned[invariant] + _tinyint_unsigned ) |
 
196
         table1 . `col_varchar_key` arithmetic_operator _char[invariant] |
 
197
         table1 . int_indexed not IN (number_list) |
 
198
         table1 . `col_varchar_key` not IN (char_list) |
 
199
         table1 . `pk` > _tinyint_unsigned[invariant] AND table1 . `pk` < ( _tinyint_unsigned[invariant] + _tinyint_unsigned ) |
 
200
         table1 . `col_int_key` > _tinyint_unsigned[invariant] AND table1 . `col_int_key` < ( _tinyint_unsigned[invariant] + _tinyint_unsigned ) ;
 
201
 
 
202
################################################################################
 
203
# The range_predicate_2* rules below are in place to ensure we hit the         #
 
204
# index_merge/union optimization.                                              #
 
205
# NOTE: combinations of the predicate_1 and predicate_2 rules tend to hit the  #
 
206
# index_merge/intersect optimization                                           #
 
207
################################################################################
 
208
 
 
209
range_predicate2_list:
 
210
      range_predicate2_item | 
 
211
      ( range_predicate2_item and_or range_predicate2_list ) ;
 
212
 
 
213
range_predicate2_item:
 
214
        table1 . `pk` = _tinyint_unsigned |
 
215
        table1 . `col_int_key` = _tinyint_unsigned |
 
216
        table1 . `col_varchar_key` = _char |
 
217
        table1 . int_indexed = _tinyint_unsigned |
 
218
        table1 . `col_varchar_key` = _char |
 
219
        table1 . int_indexed = existing_table_item . int_indexed |
 
220
        table1 . `col_varchar_key` = existing_table_item . `col_varchar_key` ;
 
221
 
 
222
################################################################################
 
223
# The number and char_list rules are for creating WHERE conditions that test   #
 
224
# 'field' IN (list_of_items)                                                   #
 
225
################################################################################
 
226
number_list:
 
227
        _tinyint_unsigned | number_list, _tinyint_unsigned ;
 
228
 
 
229
char_list: 
 
230
        _char | char_list, _char ;
 
231
 
 
232
################################################################################
 
233
# We ensure that a GROUP BY statement includes all nonaggregates.              #
 
234
# This helps to ensure the query is more useful in detecting real errors /     #
 
235
# that the query doesn't lend itself to variable result sets                   #
 
236
################################################################################
 
237
group_by_clause:
 
238
        |
 
239
        { scalar(@nonaggregates) > 0 ? " GROUP BY ".join (', ' , @nonaggregates ) : "" }  ;
 
240
 
 
241
having_clause:
 
242
        | HAVING having_list;
 
243
 
 
244
having_list:
 
245
        having_item |
 
246
        having_item |
 
247
        (having_list and_or having_item)  ;
 
248
 
 
249
having_item:
 
250
        existing_select_item arithmetic_operator value ;
 
251
 
 
252
################################################################################
 
253
# We use the total_order_by rule when using the LIMIT operator to ensure that  #
 
254
# we have a consistent result set - server1 and server2 should not differ      #
 
255
################################################################################
 
256
 
 
257
order_by_clause:
 
258
        |
 
259
        ORDER BY table1 . _field_indexed desc , total_order_by  limit |
 
260
        ORDER BY order_by_list |
 
261
        ORDER BY  order_by_list, total_order_by limit ;
 
262
 
 
263
total_order_by:
 
264
        { join(', ', map { "field".$_ } (1..$fields) ) };
 
265
 
 
266
order_by_list:
 
267
        order_by_item  |
 
268
        order_by_item  , order_by_list ;
 
269
 
 
270
order_by_item:
 
271
        table1 . _field_indexed , existing_table_item .`pk` desc  |
 
272
        table1 . _field_indexed desc |
 
273
        existing_select_item desc |
 
274
        CONCAT ( existing_table_item . char_field_name, existing_table_item . char_field_name );
 
275
desc:
 
276
        ASC | | DESC ; 
 
277
 
 
278
################################################################################
 
279
# We mix digit and _digit here.  We want to alter the possible values of LIMIT #
 
280
# To ensure we hit varying EXPLAIN plans, but the OFFSET can be smaller        #
 
281
################################################################################
 
282
 
 
283
limit:
 
284
        | ;
 
285
#| LIMIT limit_size | LIMIT limit_size OFFSET _digit;
 
286
 
 
287
new_select_item:
 
288
        nonaggregate_select_item |
 
289
        nonaggregate_select_item |
 
290
#       aggregate_select_item |
 
291
        combo_select_item ;
 
292
 
 
293
################################################################################
 
294
# We have the perl code here to help us write more sensible queries            #
 
295
# It allows us to use field1...fieldn in the WHERE, ORDER BY, and GROUP BY     #
 
296
# clauses so that the queries will produce more stable and interesting results #
 
297
################################################################################
 
298
 
 
299
nonaggregate_select_item:
 
300
        table_one_two . _field_indexed AS { my $f = "field".++$fields ; push @nonaggregates , $f ; $f } |
 
301
        table_one_two . _field_indexed AS { my $f = "field".++$fields ; push @nonaggregates , $f ; $f } |
 
302
        table_one_two . _field AS { my $f = "field".++$fields ; push @nonaggregates , $f ; $f } ;
 
303
 
 
304
aggregate_select_item:
 
305
        aggregate table_one_two . _field ) AS { "field".++$fields };
 
306
 
 
307
################################################################################
 
308
# The combo_select_items are for 'spice' - we actually found                   #
 
309
################################################################################
 
310
 
 
311
combo_select_item:
 
312
    ( ( table_one_two . int_field_name ) math_operator ( table_one_two . int_field_name ) ) AS { my $f = "field".++$fields ; push @nonaggregates , $f ; $f } |
 
313
    CONCAT ( table_one_two . char_field_name , table_one_two . char_field_name ) AS { my $f = "field".++$fields ; push @nonaggregates , $f ; $f } ;
 
314
 
 
315
table_one_two:
 
316
        table1 | table2 ;
 
317
 
 
318
aggregate:
 
319
        COUNT( distinct | SUM( distinct | MIN( distinct | MAX( distinct ;
 
320
 
 
321
################################################################################
 
322
# The following rules are for writing more sensible queries - that we don't    #
 
323
# reference tables / fields that aren't present in the query and that we keep  #
 
324
# track of what we have added.  You shouldn't need to touch these ever         #
 
325
################################################################################
 
326
new_table_item:
 
327
        _table AS { "table".++$tables };
 
328
 
 
329
current_table_item:
 
330
        { "table".$tables };
 
331
 
 
332
previous_table_item:
 
333
        { "table".($tables - 1) };
 
334
 
 
335
existing_table_item:
 
336
        { "table".$prng->int(1,$tables) };
 
337
 
 
338
existing_select_item:
 
339
        { "field".$prng->int(1,$fields) };
 
340
################################################################################
 
341
# end of utility rules                                                         #
 
342
################################################################################
 
343
 
 
344
arithmetic_operator:
 
345
        = | > | < | != | <> | <= | >= ;
 
346
 
 
347
################################################################################
 
348
# We are trying to skew the ON condition for JOINs to be largely based on      #
 
349
# equalities, but to still allow other arithmetic operators                    #
 
350
################################################################################
 
351
join_condition_operator:
 
352
    arithmetic_operator | = | = | = ;
 
353
 
 
354
################################################################################
 
355
# Used for creating combo_items - ie (field1 + field2) AS fieldX               #
 
356
# We ignore division to prevent division by zero errors                        #
 
357
################################################################################
 
358
math_operator:
 
359
    + | - | * ;
 
360
 
 
361
################################################################################
 
362
# We stack AND to provide more interesting options for the optimizer           #
 
363
# Alter these percentages at your own risk / look for coverage regressions     #
 
364
# with --debug if you play with these.  Those optimizations that require an    #
 
365
# OR-only list in the WHERE clause are specifically stacked in another rule    #
 
366
################################################################################
 
367
and_or:
 
368
   AND | AND | OR ;
 
369
 
 
370
        
 
371
value:
 
372
        _digit | _digit | _digit | _digit | _tinyint_unsigned|
 
373
        _char(2) | _char(2) | _char(2) | _char(2) | _char(2) ;
 
374
 
 
375
int_value:
 
376
        _digit | _digit | _digit | _digit | _tinyint_unsigned ;
 
377
 
 
378
char_value:
 
379
        _char(2);
 
380
 
 
381
date_value:
 
382
        _date;
 
383
 
 
384
_table:
 
385
     A | B | C | BB | CC | B | C | BB | CC | 
 
386
     C | C | C | C  | C  | C | C | C  | C  |
 
387
     CC | CC | CC | CC | CC | CC | CC | CC |
 
388
     D ;
 
389
 
 
390
################################################################################
 
391
# Add a possibility for 'view' to occur at the end of the previous '_table' rule
 
392
# to allow a chance to use views (when running the RQG with --views)
 
393
################################################################################
 
394
 
 
395
view:
 
396
    view_A | view_B | view_C | view_BB | view_CC ;
 
397
 
 
398
_field:
 
399
    int_field_name | char_field_name ;
 
400
 
 
401
_digit:
 
402
    1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | _tinyint_unsigned ;
 
403
 
 
404
 
 
405
int_field_name:
 
406
    `pk` | `col_int_key` | `col_int_nokey` ;
 
407
 
 
408
int_indexed:
 
409
    `pk` | `col_int_key` ;
 
410
 
 
411
 
 
412
char_field_name:
 
413
    `col_varchar_key` | `col_varchar_nokey` ;
 
414
 
 
415
################################################################################
 
416
# We define LIMIT_rows in this fashion as LIMIT values can differ depending on      #
 
417
# how large the LIMIT is - LIMIT 2 = LIMIT 9 != LIMIT 19                       #
 
418
################################################################################
 
419
 
 
420
limit_size:
 
421
    1 | 2 | 10 | 100 | 1000;