File: index_stat_partitions.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 (122 lines) | stat: -rw-r--r-- 4,055 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
-- source include/have_ndb.inc

set @is_enable_default = @@global.ndb_index_stat_enable;

set @is_enable = 1;
source index_stat_enable.inc;

create table record_in_range(no int primary key auto_increment,
query varchar(256), part_count int, 
explain_rows int, count_rows int) engine = innodb;

CREATE TABLE t1(
  K INT NOT NULL AUTO_INCREMENT,
  I INT,
  J INT,
  L INT,
  PRIMARY KEY(K),
  KEY(I,J),
  KEY(L)
) ENGINE=ndbcluster
  partition by key (K) partitions 1;

INSERT INTO t1(I,J,L) VALUES
(1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5),
(6,6,6),(7,7,7),(8,8,8),(9,9,9),(0,0,0);

INSERT INTO t1(I,J,L) SELECT I,1,I FROM t1;
INSERT INTO t1(I,J,L) SELECT I,2,I FROM t1;
INSERT INTO t1(I,J,L) SELECT I,3,I FROM t1;
INSERT INTO t1(I,J,L) SELECT I,4,I FROM t1;
INSERT INTO t1(I,J,L) SELECT I,5,I FROM t1;
INSERT INTO t1(I,J,L) SELECT I,6,I FROM t1;
INSERT INTO t1(I,J,L) SELECT I,7,I FROM t1;
INSERT INTO t1(I,J,L) SELECT I,8,I FROM t1;
INSERT INTO t1(I,J,L) SELECT I,9,I FROM t1;

select i, count(*) from t1 group by 1 order by 1;
select l, count(*) from t1 group by 1 order by 1;

ANALYZE TABLE t1;

--disable_query_log
let $i = 10;
let $p = 1;
while ($i)
{
  --let $q=SELECT count(*) as Count FROM t1 WHERE i = $i
  --let $explain_type= query_get_value(EXPLAIN $q, type, 1)
  --let $explain_rows= query_get_value(EXPLAIN $q, rows, 1)
  --let $count_rows= query_get_value($q, Count, 1)
  --eval insert into record_in_range(query,part_count,explain_rows,count_rows) values ('$q',$p,$explain_rows,$count_rows);
  dec $i;
}

let $l = 10;
while ($l)
{
  --let $q=SELECT count(*) as Count FROM t1 WHERE l = $l
  --let $explain_type= query_get_value(EXPLAIN $q, type, 1)
  --let $explain_rows= query_get_value(EXPLAIN $q, rows, 1)
  --let $count_rows= query_get_value($q, Count, 1)
  --eval insert into record_in_range(query,part_count,explain_rows,count_rows) values ('$q',$p,$explain_rows,$count_rows);
  dec $l;
}

alter table t1 partition by key() partitions 8;
analyze table t1;

let $p = 8;
let $i = 10;
while ($i)
{
  --let $q=SELECT count(*) as Count FROM t1 WHERE i = $i
  --let $explain_type= query_get_value(EXPLAIN $q, type, 1)
  --let $explain_rows= query_get_value(EXPLAIN $q, rows, 1)
  --let $count_rows= query_get_value($q, Count, 1)
  --eval insert into record_in_range(query,part_count,explain_rows,count_rows) values ('$q',$p,$explain_rows,$count_rows);
  dec $i;
}

let $l = 10;
while ($l)
{
  --let $q=SELECT count(*) as Count FROM t1 WHERE l = $l
  --let $explain_type= query_get_value(EXPLAIN $q, type, 1)
  --let $explain_rows= query_get_value(EXPLAIN $q, rows, 1)
  --let $count_rows= query_get_value($q, Count, 1)
  --eval insert into record_in_range(query,part_count,explain_rows,count_rows) values ('$q',$p,$explain_rows,$count_rows);
  dec $l;
}

--enable_query_log

# Change sql_mode to allow the reporting query below
# which uses "DISTINCT with an ORDER BY on column which
# is not in the select list"
--source include/turn_off_only_full_group_by.inc

select distinct 
       substring(rr.query from INSTR(rr.query, 'WHERE')) as 'WHERE', 
       count_rows, 
       p1.val as p1_val, 
       if(p8.err_pct is not null and abs(p8.err_pct)<45,'-',p8.val) p8_val,
       case when p1.err_pct is null then '-' when abs(p1.err_pct)<45 then '<45' else p1.err_pct end p1_err_pct,
       case when p8.err_pct is null then '-' when abs(p8.err_pct)<45 then '<45' else p8.err_pct end p8_err_pct
from record_in_range rr,
     (select query, explain_rows as val, if(count_rows>0,floor(100*(explain_rows - count_rows) / count_rows),NULL) err_pct
      from record_in_range p where part_count = 1) p1,
     (select query, explain_rows as val, if(count_rows>0,floor(100*(explain_rows - count_rows) / count_rows),NULL) err_pct
      from record_in_range p where part_count = 8) p8
where rr.query = p1.query
  and rr.query = p8.query
order by rr.no;

--source include/restore_sql_mode_after_turn_off_only_full_group_by.inc

DROP TABLE t1, record_in_range;

--echo End of 5.1 tests

set @is_enable = @is_enable_default;
source index_stat_enable.inc;