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

« back to all changes in this revision

Viewing changes to tests/randgen/conf/drizzle/outer_join_portable_drizzle.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) 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
 
################################################################################
19
 
# outer_join_portable.yy
20
 
# Purpose:  Random Query Generator grammar for testing larger (6 - 10 tables) JOINs
21
 
# Tuning:   Please tweak the rule table_or_joins ratio of table:join for larger joins
22
 
#           NOTE:  be aware that larger (15-20 tables) queries can take far too
23
 
#                  long to run to be of much interest for fast, automated testing
24
 
#
25
 
# Notes:    This grammar is designed to be used with gendata=conf/optimizer/outer_join.zz
26
 
#           It can be altered, but one will likely need field names
27
 
#           Additionally, it is not recommended to use the standard RQG-produced
28
 
#           tables as they way we pick tables can result in the use of
29
 
#           several large tables that will bog down a generated query
30
 
#
31
 
#           Please rely this variant of this grammar if
32
 
#           doing 3-way comparisons as it has altered code that will produce
33
 
#           more standards-compliant queries for use with other DBMS's
34
 
#
35
 
#           We keep the outer_join grammar as it is in order to also test 
36
 
#           certain MySQL-specific syntax variants.
37
 
################################################################################
38
 
 
39
 
################################################################################
40
 
# we have the perl code here as these variables are helpers for generating
41
 
# queries
42
 
# nonaggregates -  holds all nonaggregate fields used, stored as the alias used
43
 
#               such as field1, field2...
44
 
# tables - counter used to generate accurate table aliases - table1, table2..
45
 
# fields - same as tables
46
 
#
47
 
# NOTE:  refer to rule nonaggregate_select_item to see the next two items
48
 
#        in use.
49
 
#
50
 
# table_alias_set - we store aliases for creating standards-compliant
51
 
#                   field references in GROUP BY and HAVING clauses
52
 
# int_field_set - we only use integer fields in this grammar and we
53
 
#                 create this helper array for the same purposes as
54
 
#                 table_alias_set
55
 
################################################################################
56
 
 
57
 
query:
58
 
  { @table_alias_set = ("table1", "table1", "table1", "table1", "table2", "table2", "table2", "table3", "table4", "table5", "table1", "table1", "table2") ; "" }
59
 
  { @int_field_set = ("pk", "col_int", "col_int_key") ; "" } 
60
 
  { @nonaggregates = () ; $tables = 0 ; $fields = 0 ;  "" } query_type ;
61
 
 
62
 
################################################################################
63
 
# We have various query_type's so that we can ensure more syntactically correct
64
 
# queries are generated.  Certain mixes have different requirements
65
 
# mixed - regular fields + aggregates
66
 
# simple - regular fields only
67
 
# aggregate - aggregates only
68
 
################################################################################
69
 
 
70
 
query_type:
71
 
  simple_select | simple_select | mixed_select | mixed_select | mixed_select | aggregate_select ;
72
 
 
73
 
mixed_select:
74
 
        { $stack->push() } SELECT distinct straight_join select_option select_list FROM join WHERE where_list group_by_clause having_clause order_by_clause { $stack->pop(undef) } ;
75
 
 
76
 
simple_select:
77
 
        { $stack->push() } SELECT distinct straight_join select_option simple_select_list FROM join WHERE where_list  optional_group_by having_clause order_by_clause { $stack->pop(undef) } ;
78
 
 
79
 
aggregate_select:
80
 
        { $stack->push() } SELECT distinct straight_join select_option aggregate_select_list FROM join WHERE where_list optional_group_by having_clause order_by_clause { $stack->pop(undef) } ;
81
 
 
82
 
distinct: DISTINCT | | | |  ;
83
 
 
84
 
select_option:  | | | | | | | | | SQL_SMALL_RESULT ;
85
 
 
86
 
straight_join:  | | | | | | | | | | | STRAIGHT_JOIN ;
87
 
 
88
 
select_list:
89
 
        new_select_item |
90
 
        new_select_item , select_list |
91
 
        new_select_item , select_list ;
92
 
 
93
 
simple_select_list:
94
 
        nonaggregate_select_item |
95
 
        nonaggregate_select_item , simple_select_list |
96
 
        nonaggregate_select_item , simple_select_list ;
97
 
 
98
 
aggregate_select_list:
99
 
        aggregate_select_item | aggregate_select_item |
100
 
        aggregate_select_item, aggregate_select_list ;
101
 
 
102
 
new_select_item:
103
 
        nonaggregate_select_item |
104
 
        nonaggregate_select_item |        
105
 
        nonaggregate_select_item |
106
 
        nonaggregate_select_item |        
107
 
        nonaggregate_select_item |
108
 
        aggregate_select_item ;
109
 
 
110
 
################################################################################
111
 
# We differ from the main variant of the grammar here
112
 
# We pop from the previously populated helper arrays table_alias_set and 
113
 
# int_field_set so that we can generate and store fields in the form:
114
 
# <table_alias> . <field_name> AS field<number>
115
 
# <table_alias> . <field_name> is stored in the @nonaggregates array and
116
 
# used in the GROUP BY statements - this is standards-compliant and won't
117
 
# throw javadb or postgres for a loop
118
 
################################################################################
119
 
 
120
 
nonaggregate_select_item:
121
 
        { my $x = $prng->arrayElement(\@table_alias_set)." . ".$prng->arrayElement(\@int_field_set); push @nonaggregates , $x ; $x } AS {my $f = "field".++$fields ; $f };
122
 
 
123
 
aggregate_select_item:
124
 
        aggregate table_alias . int_field_name ) AS {"field".++$fields } ; 
125
 
 
126
 
################################################################################
127
 
# We make use of the new RQG stack in order to generate more interesting
128
 
# queries.  Please refer to the RQG documentation for a more in-depth discussion
129
 
# of how the stack functions
130
 
################################################################################
131
 
        
132
 
join:
133
 
       { $stack->push() }      
134
 
       table_or_join 
135
 
       { $stack->set("left",$stack->get("result")); }
136
 
       left_right outer JOIN table_or_join 
137
 
       ON 
138
 
       join_condition ;
139
 
 
140
 
join_condition:
141
 
   int_condition | varchar_condition ;
142
 
 
143
 
int_condition: 
144
 
   { my $left = $stack->get("left"); my %s=map{$_=>1} @$left; my @r=(keys %s); my $table_string = $prng->arrayElement(\@r); my @table_array = split(/AS/, $table_string); $table_array[1] } . int_indexed = 
145
 
   { my $right = $stack->get("result"); my %s=map{$_=>1} @$right; my @r=(keys %s); my $table_string = $prng->arrayElement(\@r); my @table_array = split(/AS/, $table_string); $table_array[1] } . int_indexed
146
 
   { my $left = $stack->get("left");  my $right = $stack->get("result"); my @n = (); push(@n,@$right); push(@n,@$left); $stack->pop(\@n); return undef } |
147
 
   { my $left = $stack->get("left"); my %s=map{$_=>1} @$left; my @r=(keys %s); my $table_string = $prng->arrayElement(\@r); my @table_array = split(/AS/, $table_string); $table_array[1] } . int_indexed =
148
 
   { my $right = $stack->get("result"); my %s=map{$_=>1} @$right; my @r=(keys %s); my $table_string = $prng->arrayElement(\@r); my @table_array = split(/AS/, $table_string); $table_array[1] } . int_field_name
149
 
   { my $left = $stack->get("left");  my $right = $stack->get("result"); my @n = (); push(@n,@$right); push(@n,@$left); $stack->pop(\@n); return undef } |
150
 
   { my $left = $stack->get("left"); my %s=map{$_=>1} @$left; my @r=(keys %s); my $table_string = $prng->arrayElement(\@r); my @table_array = split(/AS/, $table_string); $table_array[1] } . int_field_name =
151
 
   { my $right = $stack->get("result"); my %s=map{$_=>1} @$right; my @r=(keys %s); my $table_string = $prng->arrayElement(\@r); my @table_array = split(/AS/,
152
 
 $table_string); $table_array[1] } . int_indexed
153
 
   { my $left = $stack->get("left");  my $right = $stack->get("result"); my @n = (); push(@n,@$right); push(@n,@$left); $stack->pop(\@n); return undef } |
154
 
   { my $left = $stack->get("left"); my %s=map{$_=>1} @$left; my @r=(keys %s); my $table_string = $prng->arrayElement(\@r); my @table_array = split(/AS/, $table_string); $table_array[1] } . int_field_name =
155
 
   { my $right = $stack->get("result"); my %s=map{$_=>1} @$right; my @r=(keys %s); my $table_string = $prng->arrayElement(\@r); my @table_array = split(/AS/,
156
 
 $table_string); $table_array[1] } . int_field_name
157
 
   { my $left = $stack->get("left");  my $right = $stack->get("result"); my @n = (); push(@n,@$right); push(@n,@$left); $stack->pop(\@n); return undef } ;
158
 
 
159
 
varchar_condition:
160
 
   { my $left = $stack->get("left"); my %s=map{$_=>1} @$left; my @r=(keys %s); my $table_string = $prng->arrayElement(\@r); my @table_array = split(/AS/, $table_string); $table_array[1] } . varchar_field_name =
161
 
   { my $right = $stack->get("result"); my %s=map{$_=>1} @$right; my @r=(keys %s); my $table_string = $prng->arrayElement(\@r); my @table_array = split(/AS/, $table_string); $table_array[1] } . varchar_field_name 
162
 
   { my $left = $stack->get("left");  my $right = $stack->get("result"); my @n = (); push(@n,@$right); push(@n,@$left); $stack->pop(\@n); return undef } |
163
 
   { my $left = $stack->get("left"); my %s=map{$_=>1} @$left; my @r=(keys %s); my $table_string = $prng->arrayElement(\@r); my @table_array = split(/AS/, $table_string); $table_array[1] } . varchar_indexed  =
164
 
   { my $right = $stack->get("result"); my %s=map{$_=>1} @$right; my @r=(keys %s); my $table_string = $prng->arrayElement(\@r); my @table_array = split(/AS/, $table_string); $table_array[1] } . varchar_field_name 
165
 
   { my $left = $stack->get("left");  my $right = $stack->get("result"); my @n = (); push(@n,@$right); push(@n,@$left); $stack->pop(\@n); return undef } |
166
 
   { my $left = $stack->get("left"); my %s=map{$_=>1} @$left; my @r=(keys %s); my $table_string = $prng->arrayElement(\@r); my @table_array = split(/AS/, $table_string); $table_array[1] } . varchar_field_name =
167
 
   { my $right = $stack->get("result"); my %s=map{$_=>1} @$right; my @r=(keys %s); my $table_string = $prng->arrayElement(\@r); my @table_array = split(/AS/, $table_string); $table_array[1] } . varchar_indexed 
168
 
   { my $left = $stack->get("left");  my $right = $stack->get("result"); my @n = (); push(@n,@$right); push(@n,@$left); $stack->pop(\@n); return undef } ;
169
 
 
170
 
where_list:
171
 
        where_item | where_item |
172
 
        ( where_list and_or where_item ) ;
173
 
 
174
 
where_item:
175
 
        existing_table_item . `pk` comparison_operator _digit  |
176
 
        existing_table_item . `pk` comparison_operator existing_table_item . int_field_name  |
177
 
        existing_table_item . int_field_name comparison_operator _digit  |
178
 
        existing_table_item . int_field_name comparison_operator existing_table_item . int_field_name |
179
 
        existing_table_item . int_field_name IS not NULL |
180
 
        existing_table_item . int_field_name not IN (number_list) |
181
 
        existing_table_item . int_field_name  not BETWEEN _digit[invariant] AND ( _digit[invariant] + _digit );
182
 
 
183
 
number_list:
184
 
        _digit | number_list, _digit ;
185
 
 
186
 
################################################################################
187
 
# We ensure that a GROUP BY statement includes all nonaggregates.              #
188
 
# This helps to ensure the query is more useful in detecting real errors /     #
189
 
# that the query doesn't lend itself to variable result sets                   #
190
 
################################################################################
191
 
group_by_clause:
192
 
        { scalar(@nonaggregates) > 0 ? " GROUP BY ".join (', ' , @nonaggregates ) : "" }  ;
193
 
 
194
 
optional_group_by:
195
 
        | | | | | | | | group_by_clause ;
196
 
 
197
 
having_clause:
198
 
  | ;
199
 
 
200
 
having_clause_disabled:
201
 
        | | | | HAVING having_list;
202
 
 
203
 
having_list:
204
 
        having_item |
205
 
        having_item |
206
 
        (having_list and_or having_item)  ;
207
 
 
208
 
################################################################################
209
 
# NOTE:  It would be nice if we also had aggregates in the pool for HAVING 
210
 
#        clause items, but the code overhead isn't necessarily worth it in the 
211
 
#        portable grammar - we do test this more thoroughly in the regular 
212
 
#        version of the grammar
213
 
################################################################################
214
 
 
215
 
having_item:
216
 
        { my $y = $prng->arrayElement(\@nonaggregates) ; $y  }  comparison_operator _digit ;
217
 
 
218
 
################################################################################
219
 
# We use the total_order_by rule when using the LIMIT operator to ensure that  #
220
 
# we have a consistent result set - server1 and server2 should not differ      #
221
 
################################################################################
222
 
 
223
 
order_by_clause:
224
 
        | | | 
225
 
        ORDER BY total_order_by desc /*+javadb:postgres: NULLS FIRST*/ limit  |
226
 
        ORDER BY order_by_list /*+javadb:postgres: NULLS FIRST*/ ;
227
 
 
228
 
total_order_by:
229
 
        { join(', ', map { "field".$_ } (1..$fields) ) };
230
 
 
231
 
order_by_list:
232
 
        order_by_item  |
233
 
        order_by_item  , order_by_list ;
234
 
 
235
 
order_by_item:
236
 
        existing_select_item desc ;
237
 
 
238
 
desc:
239
 
        ASC | | | | | DESC ; 
240
 
 
241
 
################################################################################
242
 
# We mix digit and _digit here.  We want to alter the possible values of LIMIT #
243
 
# To ensure we hit varying EXPLAIN plans, but the OFFSET can be smaller        #
244
 
################################################################################
245
 
 
246
 
limit:
247
 
        | | LIMIT limit_size | LIMIT limit_size OFFSET _digit;
248
 
 
249
 
################################################################################
250
 
# Recommend 8 table : 2 join for smaller queries, 6 : 2 for larger ones
251
 
################################################################################
252
 
 
253
 
table_or_join:
254
 
           table | table | table | table | table | 
255
 
           table | table | table | join | join ;
256
 
 
257
 
################################################################################
258
 
# We stack the probabilities regarding table size via how we create tables
259
 
# with the gendata config file (conf/optimizer/outer_join.zz)
260
 
# If for some reason, you ever decide to change this, it is also possible to
261
 
# stack probabilities by creating a @table_set array and simply listing
262
 
# certain tables more often.  It is less elegant and adaptable, but we document
263
 
# it here just in case.
264
 
# EX:  @table_set = ("A","A","A","A","B","C")
265
 
#      replace the $executors->[0]->tables() in the rule below with
266
 
#      \@table_set as well
267
 
#
268
 
#      see the nonaggregate_select_item rule
269
 
#      plus the initial query rule for examples
270
 
################################################################################
271
 
 
272
 
 
273
 
table:
274
 
# We use the "AS table" bit here so we can have unique aliases if we use the same table many times
275
 
       { $stack->push(); my $x = $prng->arrayElement($executors->[0]->tables())." AS table".++$tables;  my @s=($x); $stack->pop(\@s); $x } ;
276
 
 
277
 
int_field_name:
278
 
  `pk` | `col_int_key` | `col_int` ;
279
 
 
280
 
int_indexed:
281
 
   `pk` | `col_int_key` ;
282
 
 
283
 
varchar_field_name:
284
 
  `col_varchar_10_key` | 
285
 
  `col_varchar_10`| 
286
 
  `col_varchar_1024_key` | 
287
 
  `col_varchar_1024` ; 
288
 
 
289
 
varchar_indexed:
290
 
  `col_varchar_10_key` | `col_varchar_1024_key` ; 
291
 
 
292
 
table_alias:
293
 
  table1 | table1 | table1 | table1 | table1 | table1 | table1 | table1 | table1 | table1 |
294
 
  table2 | table2 | table2 | table2 | table2 | table2 | table2 | table2 | table2 | other_table ;
295
 
 
296
 
other_table:
297
 
  table3 | table3 | table3 | table3 | table3 | table4 | table4 | table5 ;
298
 
 
299
 
existing_table_item:
300
 
        { "table".$prng->int(1,$tables) };
301
 
 
302
 
existing_select_item:
303
 
        { "field".$prng->int(1,$fields) };
304
 
 
305
 
_digit:
306
 
    1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
307
 
    1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | _tinyint_unsigned ;
308
 
 
309
 
 
310
 
and_or:
311
 
   AND | AND | OR ;
312
 
 
313
 
comparison_operator:
314
 
        = | > | < | != | <> | <= | >= ;
315
 
 
316
 
aggregate:
317
 
        COUNT( distinct | SUM( distinct | MIN( distinct | MAX( distinct ;
318
 
 
319
 
not:
320
 
        | | | NOT;
321
 
 
322
 
left_right:
323
 
        LEFT | LEFT | LEFT | RIGHT ;
324
 
 
325
 
outer:
326
 
        | | | | OUTER ;
327
 
 
328
 
################################################################################
329
 
# We define LIMIT_rows in this fashion as LIMIT values can differ depending on      #
330
 
# how large the LIMIT is - LIMIT 2 = LIMIT 9 != LIMIT 19                       #
331
 
################################################################################
332
 
 
333
 
limit_size:
334
 
    1 | 2 | 10 | 100 | 1000;
335