1
# Copyright (C) 2008-2010 Sun Microsystems, Inc. All rights reserved.
2
# Use is subject to license terms.
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.
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.
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
18
################################################################################
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
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
31
# Please rely largely on the _portable 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
35
# We keep the grammar here as it is in order to also test certain
36
# MySQL-specific syntax variants.
37
################################################################################
41
normal_query | normal_query | normal_query | normal_query | data_dictionary ;
44
show_command | data_dictionary_query ;
47
SHOW PROCESSLIST | SHOW PROCESSLIST | SHOW PROCESSLIST | SHOW PROCESSLIST |
48
SHOW TABLE STATUS | SHOW TABLE STATUS | SHOW TABLE STATUS |
49
SHOW TABLES | SHOW TABLES | SHOW TABLES |
51
SHOW TEMPORARY TABLES ;
53
data_dictionary_query:
54
SELECT * FROM `data_dictionary` . data_dictionary_table ;
56
data_dictionary_table:
59
MYSQL_PROTOCOL_STATUS |
60
CURRENT_SQL_COMMANDS |
62
SHOW_TEMPORARY_TABLES |
66
DRIZZLE_PROTOCOL_STATUS |
74
CUMULATIVE_SQL_COMMANDS |
76
SCOREBOARD_STATISTICS |
79
TABLE_DEFINITION_CACHE |
83
REFERENTIAL_CONSTRAINTS |
84
INNODB_INTERNAL_TABLES |
101
CUMULATIVE_USER_STATS ;
105
{ @nonaggregates = () ; $tables = 0 ; $fields = 0 ; "" } query_type ;
108
simple_select | simple_select | mixed_select | mixed_select | mixed_select | aggregate_select ;
111
{ $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) } ;
114
{ $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) } ;
117
{ $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) } ;
119
distinct: DISTINCT | | | | ;
121
select_option: | | | | | | | | | SQL_SMALL_RESULT ;
123
straight_join: | | | | | | | | | | | STRAIGHT_JOIN ;
127
new_select_item , select_list |
128
new_select_item , select_list ;
131
nonaggregate_select_item |
132
nonaggregate_select_item , simple_select_list |
133
nonaggregate_select_item , simple_select_list ;
135
aggregate_select_list:
136
aggregate_select_item | aggregate_select_item |
137
aggregate_select_item, aggregate_select_list ;
140
nonaggregate_select_item |
141
nonaggregate_select_item |
142
nonaggregate_select_item |
143
nonaggregate_select_item |
144
nonaggregate_select_item |
145
aggregate_select_item ;
147
nonaggregate_select_item:
148
table_alias . int_field_name AS { my $f = "field".++$fields ; push @nonaggregates , $f ; $f } ;
150
aggregate_select_item:
151
aggregate table_alias . int_field_name ) AS {"field".++$fields } ;
156
{ $stack->set("left",$stack->get("result")); }
157
left_right outer JOIN table_or_join
162
int_condition | char_condition ;
165
{ 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 =
166
{ 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
167
{ my $left = $stack->get("left"); my $right = $stack->get("result"); my @n = (); push(@n,@$right); push(@n,@$left); $stack->pop(\@n); return undef } |
168
{ 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 =
169
{ 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
170
{ my $left = $stack->get("left"); my $right = $stack->get("result"); my @n = (); push(@n,@$right); push(@n,@$left); $stack->pop(\@n); return undef } |
171
{ 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 =
172
{ 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/,
173
$table_string); $table_array[1] } . int_indexed
174
{ my $left = $stack->get("left"); my $right = $stack->get("result"); my @n = (); push(@n,@$right); push(@n,@$left); $stack->pop(\@n); return undef } |
175
{ 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 =
176
{ 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/,
177
$table_string); $table_array[1] } . int_field_name
178
{ my $left = $stack->get("left"); my $right = $stack->get("result"); my @n = (); push(@n,@$right); push(@n,@$left); $stack->pop(\@n); return undef } ;
181
{ 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] } . char_field_name =
182
{ 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] } . char_field_name
183
{ my $left = $stack->get("left"); my $right = $stack->get("result"); my @n = (); push(@n,@$right); push(@n,@$left); $stack->pop(\@n); return undef } |
184
{ 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] } . char_indexed =
185
{ 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] } . char_field_name
186
{ my $left = $stack->get("left"); my $right = $stack->get("result"); my @n = (); push(@n,@$right); push(@n,@$left); $stack->pop(\@n); return undef } |
187
{ 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] } . char_field_name =
188
{ 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] } . char_indexed
189
{ my $left = $stack->get("left"); my $right = $stack->get("result"); my @n = (); push(@n,@$right); push(@n,@$left); $stack->pop(\@n); return undef } ;
192
where_item | where_item |
193
( where_list and_or where_item ) ;
196
existing_table_item . `pk` comparison_operator _digit |
197
existing_table_item . `pk` comparison_operator existing_table_item . int_field_name |
198
existing_table_item . int_field_name comparison_operator _digit |
199
existing_table_item . int_field_name comparison_operator existing_table_item . int_field_name |
200
existing_table_item . int_field_name IS not NULL |
201
existing_table_item . int_field_name not IN (number_list) |
202
existing_table_item . int_field_name not BETWEEN _digit[invariant] AND ( _digit[invariant] + _digit );
205
_digit | number_list, _digit ;
207
################################################################################
208
# We ensure that a GROUP BY statement includes all nonaggregates. #
209
# This helps to ensure the query is more useful in detecting real errors / #
210
# that the query doesn't lend itself to variable result sets #
211
################################################################################
213
{ scalar(@nonaggregates) > 0 ? " GROUP BY ".join (', ' , @nonaggregates ) : "" } ;
216
| | | | | | | | group_by_clause ;
219
| HAVING having_list;
224
(having_list and_or having_item) ;
227
existing_select_item comparison_operator _digit ;
229
################################################################################
230
# We use the total_order_by rule when using the LIMIT operator to ensure that #
231
# we have a consistent result set - server1 and server2 should not differ #
232
################################################################################
236
ORDER BY total_order_by desc limit |
237
ORDER BY order_by_list ;
240
{ join(', ', map { "field".$_ } (1..$fields) ) };
244
order_by_item , order_by_list ;
247
existing_select_item desc ;
252
################################################################################
253
# We mix digit and _digit here. We want to alter the possible values of LIMIT #
254
# To ensure we hit varying EXPLAIN plans, but the OFFSET can be smaller #
255
################################################################################
258
| | LIMIT limit_size | LIMIT limit_size OFFSET _digit;
260
################################################################################
261
# recommend 8 tables : 2 joins for smaller queries, 6:2 for larger ones
262
################################################################################
265
table | table | table | table | table |
266
table | table | table | join | join ;
269
# We use the "AS table" bit here so we can have unique aliases if we use the same table many times
270
{ $stack->push(); my $x = $prng->arrayElement(\@table_set)." AS table".++$tables; my @s=($x); $stack->pop(\@s); $x } ;
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 } ;
278
`pk` | `col_int_key` | `col_int` ;
281
`pk` | `col_int_key` ;
285
`col_varchar_1024_key` |
287
`col_varchar_10_key` ;
290
`col_varchar_10_key` | `col_varchar_10_key` |
291
`col_varchar_1024_key` |`col_varchar_1024_key` ;
295
table1 | table1 | table1 | table1 | table1 | table1 | table1 | table1 | table1 | table1 |
296
table2 | table2 | table2 | table2 | table2 | table2 | table2 | table2 | table2 | other_table ;
299
table3 | table3 | table3 | table3 | table3 | table4 | table4 | table5 ;
302
{ "table".$prng->int(1,$tables) };
304
existing_select_item:
305
{ "field".$prng->int(1,$fields) };
308
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
309
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | _tinyint_unsigned ;
316
= | > | < | != | <> | <= | >= ;
319
COUNT( distinct | SUM( distinct | MIN( distinct | MAX( distinct ;
325
LEFT | LEFT | LEFT | RIGHT ;
330
################################################################################
331
# We define LIMIT_rows in this fashion as LIMIT values can differ depending on #
332
# how large the LIMIT is - LIMIT 2 = LIMIT 9 != LIMIT 19 #
333
################################################################################
336
1 | 2 | 10 | 100 | 1000;