Skip to content

Commit 05c002d

Browse files
author
Sergei Golubchik
committed
5.6.22
1 parent 75af0fc commit 05c002d

File tree

4 files changed

+291
-9
lines changed

4 files changed

+291
-9
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
TRUNCATE TABLE performance_schema.events_statements_summary_by_digest;
2+
ERROR 42S02: Table 'test.expect_unary' doesn't exist
3+
ERROR 42S02: Table 'test.expect_unary' doesn't exist
4+
ERROR 42S02: Table 'test.expect_unary' doesn't exist
5+
ERROR 42S02: Table 'test.expect_unary' doesn't exist
6+
ERROR 42S02: Table 'test.expect_unary' doesn't exist
7+
ERROR 42S02: Table 'test.expect_binary' doesn't exist
8+
ERROR 42S02: Table 'test.expect_binary' doesn't exist
9+
ERROR 42S02: Table 'test.expect_binary' doesn't exist
10+
ERROR 42S02: Table 'test.expect_binary' doesn't exist
11+
ERROR 42S02: Table 'test.expect_full_reduce' doesn't exist
12+
ERROR 42S02: Table 'test.expect_full_reduce' doesn't exist
13+
ERROR 42S02: Table 'test.expect_full_reduce' doesn't exist
14+
ERROR 42S02: Table 'test.expect_full_reduce' doesn't exist
15+
ERROR 42S02: Table 'test.expect_full_reduce' doesn't exist
16+
ERROR 42S02: Table 'test.expect_full_reduce' doesn't exist
17+
ERROR 42S02: Table 'test.expect_full_reduce' doesn't exist
18+
ERROR 42S02: Table 'test.expect_full_reduce' doesn't exist
19+
ERROR 42S02: Table 'test.expect_full_reduce' doesn't exist
20+
ERROR 42S02: Table 'test.expect_full_reduce' doesn't exist
21+
ERROR 42S02: Table 'test.expect_full_reduce' doesn't exist
22+
ERROR 42S02: Table 'test.expect_full_reduce' doesn't exist
23+
ERROR 42S02: Table 'test.expect_full_reduce' doesn't exist
24+
ERROR 42S02: Table 'test.expect_full_reduce' doesn't exist
25+
ERROR 42S02: Table 'test.expect_full_reduce' doesn't exist
26+
ERROR 42S02: Table 'test.expect_full_reduce' doesn't exist
27+
ERROR 42S02: Table 'test.expect_full_reduce' doesn't exist
28+
ERROR 42S02: Table 'test.expect_full_reduce' doesn't exist
29+
ERROR 42S02: Table 'test.expect_full_reduce' doesn't exist
30+
ERROR 42S02: Table 'test.expect_full_reduce' doesn't exist
31+
ERROR 42S02: Table 'test.expect_full_reduce' doesn't exist
32+
ERROR 42S02: Table 'test.expect_full_reduce' doesn't exist
33+
ERROR 42S02: Table 'test.expect_full_reduce' doesn't exist
34+
ERROR 42S02: Table 'test.expect_full_reduce' doesn't exist
35+
ERROR 42S02: Table 'test.expect_full_reduce' doesn't exist
36+
ERROR 42S02: Table 'test.expect_full_reduce' doesn't exist
37+
ERROR 42S02: Table 'test.expect_full_reduce' doesn't exist
38+
ERROR 42S02: Table 'test.expect_unchanged' doesn't exist
39+
SELECT SCHEMA_NAME, DIGEST_TEXT, COUNT_STAR
40+
FROM performance_schema.events_statements_summary_by_digest;
41+
SCHEMA_NAME DIGEST_TEXT COUNT_STAR
42+
test TRUNCATE TABLE performance_schema . events_statements_summary_by_digest 1
43+
test SELECT ? FROM expect_unary 5
44+
test SELECT ? + ? FROM expect_binary 2
45+
test SELECT ? - ? FROM expect_binary 2
46+
test INSERT INTO expect_full_reduce VALUES (...) 27
47+
test SELECT a - b , a + b , - a , - b , + a , + b FROM expect_unchanged 1
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# ----------------------------------------------------
2+
# Tests for the performance schema statement Digests.
3+
# ----------------------------------------------------
4+
5+
# Test case to show behavior of statements digest when
6+
# statement-digest-size is 0
7+
8+
--source include/not_embedded.inc
9+
--source include/have_perfschema.inc
10+
--source ../include/no_protocol.inc
11+
12+
TRUNCATE TABLE performance_schema.events_statements_summary_by_digest;
13+
14+
--disable_query_log
15+
16+
--error ER_NO_SUCH_TABLE
17+
select 1 from expect_unary;
18+
--error ER_NO_SUCH_TABLE
19+
select +1 from expect_unary;
20+
--error ER_NO_SUCH_TABLE
21+
select -1 from expect_unary;
22+
--error ER_NO_SUCH_TABLE
23+
select ++++++++++++++++++++++++++++++++++++++++++++++++1 from expect_unary;
24+
--error ER_NO_SUCH_TABLE
25+
select ------------------------------------------------1 from expect_unary;
26+
27+
--error ER_NO_SUCH_TABLE
28+
select 0+1 from expect_binary;
29+
--error ER_NO_SUCH_TABLE
30+
select 0-1 from expect_binary;
31+
--error ER_NO_SUCH_TABLE
32+
select 0 ++++++++++++++++++++++++++++++++++++++++++++++++1 from expect_binary;
33+
--error ER_NO_SUCH_TABLE
34+
select 0 ------------------------------------------------1 from expect_binary;
35+
36+
--error ER_NO_SUCH_TABLE
37+
insert into expect_full_reduce values (0, 0, 0);
38+
--error ER_NO_SUCH_TABLE
39+
insert into expect_full_reduce values (0, 0, -1);
40+
--error ER_NO_SUCH_TABLE
41+
insert into expect_full_reduce values (0, 0, +1);
42+
--error ER_NO_SUCH_TABLE
43+
insert into expect_full_reduce values (0, -1, 0);
44+
--error ER_NO_SUCH_TABLE
45+
insert into expect_full_reduce values (0, -1, -1);
46+
--error ER_NO_SUCH_TABLE
47+
insert into expect_full_reduce values (0, -1, +1);
48+
--error ER_NO_SUCH_TABLE
49+
insert into expect_full_reduce values (0, +1, 0);
50+
--error ER_NO_SUCH_TABLE
51+
insert into expect_full_reduce values (0, +1, -1);
52+
--error ER_NO_SUCH_TABLE
53+
insert into expect_full_reduce values (0, +1, +1);
54+
--error ER_NO_SUCH_TABLE
55+
insert into expect_full_reduce values (-1, 0, 0);
56+
--error ER_NO_SUCH_TABLE
57+
insert into expect_full_reduce values (-1, 0, -1);
58+
--error ER_NO_SUCH_TABLE
59+
insert into expect_full_reduce values (-1, 0, +1);
60+
--error ER_NO_SUCH_TABLE
61+
insert into expect_full_reduce values (-1, -1, 0);
62+
--error ER_NO_SUCH_TABLE
63+
insert into expect_full_reduce values (-1, -1, -1);
64+
--error ER_NO_SUCH_TABLE
65+
insert into expect_full_reduce values (-1, -1, +1);
66+
--error ER_NO_SUCH_TABLE
67+
insert into expect_full_reduce values (-1, +1, 0);
68+
--error ER_NO_SUCH_TABLE
69+
insert into expect_full_reduce values (-1, +1, -1);
70+
--error ER_NO_SUCH_TABLE
71+
insert into expect_full_reduce values (-1, +1, +1);
72+
--error ER_NO_SUCH_TABLE
73+
insert into expect_full_reduce values (+1, 0, 0);
74+
--error ER_NO_SUCH_TABLE
75+
insert into expect_full_reduce values (+1, 0, -1);
76+
--error ER_NO_SUCH_TABLE
77+
insert into expect_full_reduce values (+1, 0, +1);
78+
--error ER_NO_SUCH_TABLE
79+
insert into expect_full_reduce values (+1, -1, 0);
80+
--error ER_NO_SUCH_TABLE
81+
insert into expect_full_reduce values (+1, -1, -1);
82+
--error ER_NO_SUCH_TABLE
83+
insert into expect_full_reduce values (+1, -1, +1);
84+
--error ER_NO_SUCH_TABLE
85+
insert into expect_full_reduce values (+1, +1, 0);
86+
--error ER_NO_SUCH_TABLE
87+
insert into expect_full_reduce values (+1, +1, -1);
88+
--error ER_NO_SUCH_TABLE
89+
insert into expect_full_reduce values (+1, +1, +1);
90+
91+
--error ER_NO_SUCH_TABLE
92+
select a-b, a+b, -a, -b, +a, +b from expect_unchanged;
93+
94+
--enable_query_log
95+
96+
SELECT SCHEMA_NAME, DIGEST_TEXT, COUNT_STAR
97+
FROM performance_schema.events_statements_summary_by_digest;
98+

storage/perfschema/gen_pfs_lex_token.cc

Lines changed: 91 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -36,10 +36,13 @@
3636
See also YYMAXUTOK.
3737
*/
3838
#define MY_MAX_TOKEN 1000
39+
/** Generated token. */
3940
struct gen_lex_token_string
4041
{
4142
const char *m_token_string;
4243
int m_token_length;
44+
bool m_append_space;
45+
bool m_start_expr;
4346
};
4447

4548
gen_lex_token_string compiled_token_array[MY_MAX_TOKEN];
@@ -76,6 +79,13 @@ void set_token(int tok, const char *str)
7679

7780
compiled_token_array[tok].m_token_string= str;
7881
compiled_token_array[tok].m_token_length= strlen(str);
82+
compiled_token_array[tok].m_append_space= true;
83+
compiled_token_array[tok].m_start_expr= false;
84+
}
85+
86+
void set_start_expr_token(int tok)
87+
{
88+
compiled_token_array[tok].m_start_expr= true;
7989
}
8090

8191
void compute_tokens()
@@ -91,6 +101,8 @@ void compute_tokens()
91101
{
92102
compiled_token_array[tok].m_token_string= "(unknown)";
93103
compiled_token_array[tok].m_token_length= 9;
104+
compiled_token_array[tok].m_append_space= true;
105+
compiled_token_array[tok].m_start_expr= false;
94106
}
95107

96108
/*
@@ -102,6 +114,7 @@ void compute_tokens()
102114
str[0]= (char) tok;
103115
compiled_token_array[tok].m_token_string= str;
104116
compiled_token_array[tok].m_token_length= 1;
117+
compiled_token_array[tok].m_append_space= true;
105118
}
106119

107120
max_token_seen= 255;
@@ -202,6 +215,71 @@ void compute_tokens()
202215
max_token_seen++;
203216
tok_pfs_unused= max_token_seen;
204217
set_token(tok_pfs_unused, "UNUSED");
218+
219+
/*
220+
Fix whitespace for some special tokens.
221+
*/
222+
223+
/*
224+
The lexer parses "@@variable" as '@', '@', 'variable',
225+
returning a token for '@' alone.
226+
227+
This is incorrect, '@' is not really a token,
228+
because the syntax "@ @ variable" (with spaces) is not accepted:
229+
The lexer keeps some internal state after the '@' fake token.
230+
231+
To work around this, digest text are printed as "@@variable".
232+
*/
233+
compiled_token_array[(int) '@'].m_append_space= false;
234+
235+
/*
236+
Define additional properties for tokens.
237+
238+
List all the token that are followed by an expression.
239+
This is needed to differentiate unary from binary
240+
'+' and '-' operators, because we want to:
241+
- reduce <unary +> <NUM> to <?>,
242+
- preserve <...> <binary +> <NUM> as is.
243+
*/
244+
set_start_expr_token('(');
245+
set_start_expr_token(',');
246+
set_start_expr_token(EVERY_SYM);
247+
set_start_expr_token(AT_SYM);
248+
set_start_expr_token(STARTS_SYM);
249+
set_start_expr_token(ENDS_SYM);
250+
set_start_expr_token(DEFAULT);
251+
set_start_expr_token(RETURN_SYM);
252+
set_start_expr_token(IF);
253+
set_start_expr_token(ELSEIF_SYM);
254+
set_start_expr_token(CASE_SYM);
255+
set_start_expr_token(WHEN_SYM);
256+
set_start_expr_token(WHILE_SYM);
257+
set_start_expr_token(UNTIL_SYM);
258+
set_start_expr_token(SELECT_SYM);
259+
260+
set_start_expr_token(OR_SYM);
261+
set_start_expr_token(OR2_SYM);
262+
set_start_expr_token(XOR);
263+
set_start_expr_token(AND_SYM);
264+
set_start_expr_token(AND_AND_SYM);
265+
set_start_expr_token(NOT_SYM);
266+
set_start_expr_token(BETWEEN_SYM);
267+
set_start_expr_token(LIKE);
268+
set_start_expr_token(REGEXP);
269+
270+
set_start_expr_token('|');
271+
set_start_expr_token('&');
272+
set_start_expr_token(SHIFT_LEFT);
273+
set_start_expr_token(SHIFT_RIGHT);
274+
set_start_expr_token('+');
275+
set_start_expr_token('-');
276+
set_start_expr_token(INTERVAL_SYM);
277+
set_start_expr_token('*');
278+
set_start_expr_token('/');
279+
set_start_expr_token('%');
280+
set_start_expr_token(DIV_SYM);
281+
set_start_expr_token(MOD_SYM);
282+
set_start_expr_token('^');
205283
}
206284

207285
void print_tokens()
@@ -214,20 +292,26 @@ void print_tokens()
214292

215293
for (tok= 0; tok<256; tok++)
216294
{
217-
printf("/* %03d */ { \"\\x%02x\", 1},\n", tok, tok);
295+
printf("/* %03d */ { \"\\x%02x\", 1, %s, %s},\n",
296+
tok,
297+
tok,
298+
compiled_token_array[tok].m_append_space ? "true" : "false",
299+
compiled_token_array[tok].m_start_expr ? "true" : "false");
218300
}
219301

220302
printf("/* PART 2: named tokens. */\n");
221303

222304
for (tok= 256; tok<= max_token_seen; tok++)
223305
{
224-
printf("/* %03d */ { \"%s\", %d},\n",
306+
printf("/* %03d */ { \"%s\", %d, %s, %s},\n",
225307
tok,
226308
compiled_token_array[tok].m_token_string,
227-
compiled_token_array[tok].m_token_length);
309+
compiled_token_array[tok].m_token_length,
310+
compiled_token_array[tok].m_append_space ? "true" : "false",
311+
compiled_token_array[tok].m_start_expr ? "true" : "false");
228312
}
229313

230-
printf("/* DUMMY */ { \"\", 0}\n");
314+
printf("/* DUMMY */ { \"\", 0, false, false}\n");
231315
printf("};\n");
232316

233317
printf("/* PFS specific tokens. */\n");
@@ -254,6 +338,8 @@ int main(int argc,char **argv)
254338
printf("{\n");
255339
printf(" const char *m_token_string;\n");
256340
printf(" int m_token_length;\n");
341+
printf(" bool m_append_space;\n");
342+
printf(" bool m_start_expr;\n");
257343
printf("};\n");
258344
printf("typedef struct lex_token_string lex_token_string;\n");
259345

storage/perfschema/pfs_digest.cc

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -602,16 +602,67 @@ PSI_digest_locker* pfs_digest_add_token_v1(PSI_digest_locker *locker,
602602

603603
switch (token)
604604
{
605-
case BIN_NUM:
605+
case NUM:
606+
case LONG_NUM:
607+
case ULONGLONG_NUM:
606608
case DECIMAL_NUM:
607609
case FLOAT_NUM:
610+
case BIN_NUM:
608611
case HEX_NUM:
612+
{
613+
bool found_unary;
614+
do
615+
{
616+
found_unary= false;
617+
peek_last_two_tokens(digest_storage, state->m_last_id_index,
618+
&last_token, &last_token2);
619+
620+
if ((last_token == '-') || (last_token == '+'))
621+
{
622+
/*
623+
We need to differentiate:
624+
- a <unary minus> operator
625+
- a <unary plus> operator
626+
from
627+
- a <binary minus> operator
628+
- a <binary plus> operator
629+
to only reduce "a = -1" to "a = ?", and not change "b - 1" to "b ?"
630+
631+
Binary operators are found inside an expression,
632+
while unary operators are found at the beginning of an expression, or after operators.
633+
634+
To achieve this, every token that is followed by an <expr> expression
635+
in the SQL grammar is flagged.
636+
See sql/sql_yacc.yy
637+
See sql/gen_lex_token.cc
638+
639+
For example,
640+
"(-1)" is parsed as "(", "-", NUM, ")", and lex_token_array["("].m_start_expr is true,
641+
so reduction of the "-" NUM is done, the result is "(?)".
642+
"(a-1)" is parsed as "(", ID, "-", NUM, ")", and lex_token_array[ID].m_start_expr is false,
643+
so the operator is binary, no reduction is done, and the result is "(a-?)".
644+
*/
645+
if (lex_token_array[last_token2].m_start_expr)
646+
{
647+
/*
648+
REDUCE:
649+
TOK_PFS_GENERIC_VALUE := (UNARY_PLUS | UNARY_MINUS) (NUM | LOG_NUM | ... | FLOAT_NUM)
650+
651+
REDUCE:
652+
TOK_PFS_GENERIC_VALUE := (UNARY_PLUS | UNARY_MINUS) TOK_PFS_GENERIC_VALUE
653+
*/
654+
token= TOK_PFS_GENERIC_VALUE;
655+
digest_storage->m_byte_count-= PFS_SIZE_OF_A_TOKEN;
656+
found_unary= true;
657+
}
658+
}
659+
} while (found_unary);
660+
}
661+
/* fall through, for case NULL_SYM below */
609662
case LEX_HOSTNAME:
610-
case LONG_NUM:
611-
case NUM:
612663
case TEXT_STRING:
613664
case NCHAR_STRING:
614-
case ULONGLONG_NUM:
665+
case PARAM_MARKER:
615666
{
616667
/*
617668
REDUCE:

0 commit comments

Comments
 (0)