File: digest_collision.test

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (74 lines) | stat: -rw-r--r-- 2,373 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
--echo #
--echo # Test of the case when two rewrite rule pattern have the same digest.
--echo #

SET sql_mode = concat ( @@sql_mode, ',PIPES_AS_CONCAT' );

--source suite/query_rewrite_plugins/include/have_plugin_rewriter.inc

CREATE TABLE t1 ( a VARCHAR(10) );

--source suite/query_rewrite_plugins/include/install_rewriter_with_optional_columns.inc

--echo # This will supposedly fill up the token buffer.
--echo # We have to keep entries in the error log unique, we can't clear it.
SET @query_term = 'SELECT * FROM test.t1 WHERE a = "digest_collision.test"';
SET @a_union_branch = ' UNION ' || @query_term;
SET @tail1 = 'UNION SELECT 1';
SET @tail2 = 'UNION SELECT 2';

SELECT character_maximum_length INTO @max_pattern_length
FROM information_schema.columns
WHERE table_name = 'rewrite_rules'
AND column_name = 'pattern';

SET @no_unions_that_fit =
  floor(
    ( @max_pattern_length - char_length(@query_term) - char_length(@tail1) ) /
    char_length(@a_union_branch));

SELECT @query_term, @a_union_branch, @max_pattern_length, @no_unions_that_fit;

SET @pattern1 = @query_term || repeat( @a_union_branch, @no_unions_that_fit);

SET @pattern2 = concat ( @pattern1, @tail1 );

SET @nonmatching_query = concat ( @pattern1, @tail2 );

INSERT INTO query_rewrite.rewrite_rules ( pattern, replacement  )
VALUES ( @pattern1, 'SELECT "Rewrite rule #1"' ),
       ( @pattern2, 'SELECT "Rewrite rule #2"' );

CALL query_rewrite.flush_rewrite_rules();

SELECT group_concat(replacement) =
  'SELECT "Rewrite rule #1",SELECT "Rewrite rule #2"'
AS digests_indeed_collide
FROM query_rewrite.rewrite_rules
GROUP BY pattern_digest;

SELECT char_length(pattern) FROM query_rewrite.rewrite_rules;

PREPARE pattern1_stmt FROM @pattern1;
EXECUTE pattern1_stmt;

PREPARE pattern2_stmt FROM @pattern2;
EXECUTE pattern2_stmt;

SET @@global.rewriter_verbose = 2;

PREPARE nonmatching_stmt FROM @nonmatching_query;
EXECUTE nonmatching_stmt;

SET @@global.rewriter_verbose = DEFAULT;

--source suite/query_rewrite_plugins/include/load_error_log.inc

SELECT search_error_log( '[Note]', '%Plugin Rewriter reported: ''Statement "SELECT * FROM test.t1 ' ||
                           'WHERE a = "digest_collision.test"%' );

DROP TABLE t1;

--source suite/query_rewrite_plugins/include/uninstall_rewriter.inc
--source suite/query_rewrite_plugins/include/drop_error_log.inc
SET sql_mode = DEFAULT;