Merge 5.5 -> 5.5-mwl248.

This commit is contained in:
Igor Babaev 2012-11-02 20:38:05 -07:00
commit 8d612adf70
86 changed files with 8317 additions and 126 deletions

View File

@ -73,7 +73,8 @@ SET(SQL_EMBEDDED_SOURCES emb_qcache.cc libmysqld.c lib_sql.cc
../sql/debug_sync.cc ../sql/opt_table_elimination.cc
../sql/sql_prepare.cc ../sql/sql_rename.cc ../sql/sql_repl.cc
../sql/sql_select.cc ../sql/sql_servers.cc
../sql/sql_show.cc ../sql/sql_state.c ../sql/sql_string.cc
../sql/sql_show.cc ../sql/sql_state.c
../sql/sql_statistics.cc ../sql/sql_string.cc
../sql/sql_tablespace.cc ../sql/sql_table.cc ../sql/sql_test.cc
../sql/sql_trigger.cc ../sql/sql_udf.cc ../sql/sql_union.cc
../sql/sql_update.cc ../sql/sql_view.cc ../sql/sql_profile.cc

View File

@ -0,0 +1,5 @@
if (`select count(*) < 3 from information_schema.tables
where table_schema = 'mysql' and table_name in ('table_stat','column_stat','index_stat')`)
{
--skip Needs stat tables
}

View File

@ -0,0 +1 @@
--use-stat-tables='complementary'

View File

@ -16,3 +16,6 @@ show create table proc;
show create table event;
show create table general_log;
show create table slow_log;
show create table table_stat;
show create table column_stat;
show create table index_stat;

View File

@ -0,0 +1,25 @@
CREATE TABLE Country (
Code char(3) NOT NULL default '',
Name char(52) NOT NULL default '',
SurfaceArea float(10,2) NOT NULL default '0.00',
Population int(11) NOT NULL default '0',
Capital int(11) default NULL,
PRIMARY KEY (Code),
UNIQUE INDEX (Name)
) CHARACTER SET utf8 COLLATE utf8_bin;
CREATE TABLE City (
ID int(11) NOT NULL auto_increment,
Name char(35) NOT NULL default '',
Country char(3) NOT NULL default '',
Population int(11) NOT NULL default '0',
PRIMARY KEY (ID),
INDEX (Population),
INDEX (Country)
) CHARACTER SET utf8 COLLATE utf8_bin;
CREATE TABLE CountryLanguage (
Country char(3) NOT NULL default '',
Language char(30) NOT NULL default '',
Percentage float(3,1) NOT NULL default '0.0',
PRIMARY KEY (Country, Language),
INDEX (Percentage)
) CHARACTER SET utf8 COLLATE utf8_bin;

View File

@ -7,6 +7,7 @@ performance_schema
test
show tables in mysql;
Tables_in_mysql
column_stat
columns_priv
db
event
@ -17,6 +18,7 @@ help_keyword
help_relation
help_topic
host
index_stat
ndb_binlog_index
plugin
proc
@ -24,6 +26,7 @@ procs_priv
proxies_priv
servers
slow_log
table_stat
tables_priv
time_zone
time_zone_leap_second

View File

@ -1,6 +1,7 @@
drop table if exists t1,t2;
show tables;
Tables_in_mysql
column_stat
columns_priv
db
event
@ -11,6 +12,7 @@ help_keyword
help_relation
help_topic
host
index_stat
ndb_binlog_index
plugin
proc
@ -18,6 +20,7 @@ procs_priv
proxies_priv
servers
slow_log
table_stat
tables_priv
time_zone
time_zone_leap_second
@ -35,6 +38,7 @@ grant ALL on *.* to test@localhost identified by "gambling";
grant ALL on *.* to test@127.0.0.1 identified by "gambling";
show tables;
Tables_in_mysql
column_stat
columns_priv
db
event
@ -45,6 +49,7 @@ help_keyword
help_relation
help_topic
host
index_stat
ndb_binlog_index
plugin
proc
@ -52,6 +57,7 @@ procs_priv
proxies_priv
servers
slow_log
table_stat
tables_priv
time_zone
time_zone_leap_second
@ -77,6 +83,7 @@ ERROR HY000: Password hash should be a 41-digit hexadecimal number
set password=old_password('gambling3');
show tables;
Tables_in_mysql
column_stat
columns_priv
db
event
@ -87,6 +94,7 @@ help_keyword
help_relation
help_topic
host
index_stat
ndb_binlog_index
plugin
proc
@ -94,6 +102,7 @@ procs_priv
proxies_priv
servers
slow_log
table_stat
tables_priv
time_zone
time_zone_leap_second

View File

@ -81,6 +81,7 @@ TRIGGERS
USER_PRIVILEGES
USER_STATISTICS
VIEWS
column_stat
columns_priv
db
event
@ -91,6 +92,7 @@ help_keyword
help_relation
help_topic
host
index_stat
plugin
proc
procs_priv
@ -102,6 +104,7 @@ t2
t3
t4
t5
table_stat
tables_priv
time_zone
time_zone_leap_second
@ -120,6 +123,7 @@ TABLE_CONSTRAINTS TABLE_CONSTRAINTS
TABLE_PRIVILEGES TABLE_PRIVILEGES
TABLE_STATISTICS TABLE_STATISTICS
TRIGGERS TRIGGERS
table_stat table_stat
tables_priv tables_priv
time_zone time_zone
time_zone_leap_second time_zone_leap_second
@ -141,6 +145,7 @@ TABLE_CONSTRAINTS TABLE_CONSTRAINTS
TABLE_PRIVILEGES TABLE_PRIVILEGES
TABLE_STATISTICS TABLE_STATISTICS
TRIGGERS TRIGGERS
table_stat table_stat
tables_priv tables_priv
time_zone time_zone
time_zone_leap_second time_zone_leap_second
@ -162,6 +167,7 @@ TABLE_CONSTRAINTS TABLE_CONSTRAINTS
TABLE_PRIVILEGES TABLE_PRIVILEGES
TABLE_STATISTICS TABLE_STATISTICS
TRIGGERS TRIGGERS
table_stat table_stat
tables_priv tables_priv
time_zone time_zone
time_zone_leap_second time_zone_leap_second

View File

@ -418,4 +418,4 @@ Wildcard: inf_rmation_schema
SELECT table_schema, count(*) FROM information_schema.TABLES WHERE table_schema IN ('mysql', 'INFORMATION_SCHEMA', 'test', 'mysqltest') AND table_name<>'ndb_binlog_index' AND table_name<>'ndb_apply_status' GROUP BY TABLE_SCHEMA;
table_schema count(*)
information_schema 58
mysql 23
mysql 26

View File

@ -19,6 +19,7 @@ mtr
mtr.global_suppressions OK
mtr.test_suppressions OK
mysql
mysql.column_stat OK
mysql.columns_priv OK
mysql.db OK
mysql.event OK
@ -28,6 +29,7 @@ mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.host OK
mysql.index_stat OK
mysql.ndb_binlog_index OK
mysql.plugin OK
mysql.proc OK
@ -35,6 +37,7 @@ mysql.procs_priv OK
mysql.proxies_priv OK
mysql.renamed_general_log OK
mysql.servers OK
mysql.table_stat OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK

View File

@ -0,0 +1,21 @@
CREATE TABLE A (
pk INTEGER AUTO_INCREMENT PRIMARY KEY,
fdate DATE
) ENGINE=MyISAM;
CREATE PROCEDURE p_analyze()
BEGIN
DECLARE attempts INTEGER DEFAULT 100;
wl_loop: WHILE attempts > 0 DO
ANALYZE TABLE A;
SET attempts = attempts - 1;
END WHILE wl_loop;
END |
CREATE FUNCTION rnd3() RETURNS INT
BEGIN
RETURN ROUND(3 * RAND() + 0.5);
END |
SET GLOBAL use_stat_tables = PREFERABLY;
DROP TABLE A;
DROP PROCEDURE p_analyze;
DROP FUNCTION rnd3;
SET GLOBAL use_stat_tables = DEFAULT;

View File

@ -7,6 +7,7 @@ mtr
mtr.global_suppressions OK
mtr.test_suppressions OK
mysql
mysql.column_stat OK
mysql.columns_priv OK
mysql.db OK
mysql.event OK
@ -16,12 +17,14 @@ mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.host OK
mysql.index_stat OK
mysql.ndb_binlog_index OK
mysql.plugin OK
mysql.proc OK
mysql.procs_priv OK
mysql.proxies_priv OK
mysql.servers OK
mysql.table_stat OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK
@ -44,6 +47,7 @@ mtr
mtr.global_suppressions OK
mtr.test_suppressions OK
mysql
mysql.column_stat OK
mysql.columns_priv OK
mysql.db OK
mysql.event OK
@ -53,12 +57,14 @@ mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.host OK
mysql.index_stat OK
mysql.ndb_binlog_index OK
mysql.plugin OK
mysql.proc OK
mysql.procs_priv OK
mysql.proxies_priv OK
mysql.servers OK
mysql.table_stat OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK
@ -81,6 +87,7 @@ mtr
mtr.global_suppressions OK
mtr.test_suppressions OK
mysql
mysql.column_stat OK
mysql.columns_priv OK
mysql.db OK
mysql.event OK
@ -90,12 +97,14 @@ mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.host OK
mysql.index_stat OK
mysql.ndb_binlog_index OK
mysql.plugin OK
mysql.proc OK
mysql.procs_priv OK
mysql.proxies_priv OK
mysql.servers OK
mysql.table_stat OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK
@ -121,6 +130,7 @@ mtr
mtr.global_suppressions OK
mtr.test_suppressions OK
mysql
mysql.column_stat OK
mysql.columns_priv OK
mysql.db OK
mysql.event OK
@ -130,12 +140,14 @@ mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.host OK
mysql.index_stat OK
mysql.ndb_binlog_index OK
mysql.plugin OK
mysql.proc OK
mysql.procs_priv OK
mysql.proxies_priv OK
mysql.servers OK
mysql.table_stat OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK
@ -164,6 +176,7 @@ mtr
mtr.global_suppressions OK
mtr.test_suppressions OK
mysql
mysql.column_stat OK
mysql.columns_priv OK
mysql.db OK
mysql.event OK
@ -173,12 +186,14 @@ mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.host OK
mysql.index_stat OK
mysql.ndb_binlog_index OK
mysql.plugin OK
mysql.proc OK
mysql.procs_priv OK
mysql.proxies_priv OK
mysql.servers OK
mysql.table_stat OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK
@ -210,6 +225,7 @@ mtr
mtr.global_suppressions OK
mtr.test_suppressions OK
mysql
mysql.column_stat OK
mysql.columns_priv OK
mysql.db OK
mysql.event OK
@ -219,12 +235,14 @@ mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.host OK
mysql.index_stat OK
mysql.ndb_binlog_index OK
mysql.plugin OK
mysql.proc OK
mysql.procs_priv OK
mysql.proxies_priv OK
mysql.servers OK
mysql.table_stat OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK
@ -259,6 +277,7 @@ mtr
mtr.global_suppressions OK
mtr.test_suppressions OK
mysql
mysql.column_stat OK
mysql.columns_priv OK
mysql.db OK
mysql.event OK
@ -268,12 +287,14 @@ mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.host OK
mysql.index_stat OK
mysql.ndb_binlog_index OK
mysql.plugin OK
mysql.proc OK
mysql.procs_priv OK
mysql.proxies_priv OK
mysql.servers OK
mysql.table_stat OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK

View File

@ -9,6 +9,7 @@ mtr
mtr.global_suppressions OK
mtr.test_suppressions OK
mysql
mysql.column_stat OK
mysql.columns_priv OK
mysql.db OK
mysql.event OK
@ -18,12 +19,14 @@ mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.host OK
mysql.index_stat OK
mysql.ndb_binlog_index OK
mysql.plugin OK
mysql.proc OK
mysql.procs_priv OK
mysql.proxies_priv OK
mysql.servers OK
mysql.table_stat OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK

View File

@ -3,6 +3,7 @@ drop view if exists v1;
drop database if exists client_test_db;
mtr.global_suppressions OK
mtr.test_suppressions OK
mysql.column_stat OK
mysql.columns_priv OK
mysql.db OK
mysql.event OK
@ -12,12 +13,14 @@ mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.host OK
mysql.index_stat OK
mysql.ndb_binlog_index OK
mysql.plugin OK
mysql.proc OK
mysql.procs_priv OK
mysql.proxies_priv OK
mysql.servers OK
mysql.table_stat OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK
@ -27,6 +30,7 @@ mysql.time_zone_transition_type OK
mysql.user OK
mtr.global_suppressions Table is already up to date
mtr.test_suppressions Table is already up to date
mysql.column_stat OK
mysql.columns_priv OK
mysql.db OK
mysql.event OK
@ -36,12 +40,14 @@ mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.host OK
mysql.index_stat OK
mysql.ndb_binlog_index OK
mysql.plugin OK
mysql.proc OK
mysql.procs_priv OK
mysql.proxies_priv OK
mysql.servers OK
mysql.table_stat OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK
@ -49,6 +55,7 @@ mysql.time_zone_name OK
mysql.time_zone_transition OK
mysql.time_zone_transition_type OK
mysql.user OK
mysql.column_stat OK
mysql.columns_priv OK
mysql.db OK
mysql.event OK
@ -58,12 +65,14 @@ mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.host OK
mysql.index_stat OK
mysql.ndb_binlog_index OK
mysql.plugin OK
mysql.proc OK
mysql.procs_priv OK
mysql.proxies_priv OK
mysql.servers OK
mysql.table_stat OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK
@ -71,6 +80,7 @@ mysql.time_zone_name OK
mysql.time_zone_transition OK
mysql.time_zone_transition_type OK
mysql.user OK
mysql.column_stat Table is already up to date
mysql.columns_priv Table is already up to date
mysql.db Table is already up to date
mysql.event Table is already up to date
@ -80,12 +90,14 @@ mysql.help_keyword Table is already up to date
mysql.help_relation Table is already up to date
mysql.help_topic Table is already up to date
mysql.host Table is already up to date
mysql.index_stat Table is already up to date
mysql.ndb_binlog_index Table is already up to date
mysql.plugin Table is already up to date
mysql.proc Table is already up to date
mysql.procs_priv Table is already up to date
mysql.proxies_priv Table is already up to date
mysql.servers Table is already up to date
mysql.table_stat Table is already up to date
mysql.tables_priv Table is already up to date
mysql.time_zone Table is already up to date
mysql.time_zone_leap_second Table is already up to date

View File

@ -843,6 +843,9 @@ The following options may be given as the first argument:
Prohibit update of a VIEW, which does not contain a key
of the underlying table and the query uses a LIMIT clause
(usually get from GUI tools)
--use-stat-tables=name
Specifies how to use system statistics tables. Possible
values are NEVER, COMPLEMENTARY, PREVERABLY
-u, --user=name Run mysqld daemon as user.
--userstat Enables statistics gathering for USER_STATISTICS,
CLIENT_STATISTICS, INDEX_STATISTICS and TABLE_STATISTICS
@ -1096,6 +1099,7 @@ transaction-alloc-block-size 8192
transaction-isolation REPEATABLE-READ
transaction-prealloc-size 4096
updatable-views-with-limit YES
use-stat-tables NEVER
userstat FALSE
verbose TRUE
wait-timeout 28800

View File

@ -0,0 +1,383 @@
select @@global.use_stat_tables;
@@global.use_stat_tables
COMPLEMENTARY
select @@session.use_stat_tables;
@@session.use_stat_tables
COMPLEMENTARY
set @save_use_stat_tables=@@use_stat_tables;
set use_stat_tables='preferably';
DROP DATABASE IF EXISTS dbt3_s001;
CREATE DATABASE dbt3_s001;
use dbt3_s001;
set @save_optimizer_switch=@@optimizer_switch;
set optimizer_switch='extended_keys=off';
select * from mysql.table_stat;
db_name table_name cardinality
dbt3_s001 customer 150
dbt3_s001 lineitem 6005
dbt3_s001 nation 25
dbt3_s001 orders 1500
dbt3_s001 part 200
dbt3_s001 partsupp 700
dbt3_s001 region 5
dbt3_s001 supplier 10
select * from mysql.index_stat;
db_name table_name index_name prefix_arity avg_frequency
dbt3_s001 customer PRIMARY 1 1.0000
dbt3_s001 customer i_c_nationkey 1 6.0000
dbt3_s001 lineitem PRIMARY 1 4.0033
dbt3_s001 lineitem PRIMARY 2 1.0000
dbt3_s001 lineitem i_l_shipdate 1 2.6500
dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250
dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786
dbt3_s001 lineitem i_l_partkey 1 30.0250
dbt3_s001 lineitem i_l_suppkey 1 600.5000
dbt3_s001 lineitem i_l_receiptdate 1 2.6477
dbt3_s001 lineitem i_l_orderkey 1 4.0033
dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033
dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404
dbt3_s001 lineitem i_l_commitdate 1 2.7160
dbt3_s001 nation PRIMARY 1 1.0000
dbt3_s001 nation i_n_regionkey 1 5.0000
dbt3_s001 orders PRIMARY 1 1.0000
dbt3_s001 orders i_o_orderdate 1 1.3321
dbt3_s001 orders i_o_custkey 1 15.0000
dbt3_s001 part PRIMARY 1 1.0000
dbt3_s001 part i_p_retailprice 1 1.0000
dbt3_s001 partsupp PRIMARY 1 3.5000
dbt3_s001 partsupp PRIMARY 2 1.0000
dbt3_s001 partsupp i_ps_partkey 1 3.5000
dbt3_s001 partsupp i_ps_suppkey 1 70.0000
dbt3_s001 region PRIMARY 1 1.0000
dbt3_s001 supplier PRIMARY 1 1.0000
dbt3_s001 supplier i_s_nationkey 1 1.1111
set optimizer_switch=@save_optimizer_switch;
set @save_optimizer_switch=@@optimizer_switch;
set optimizer_switch='index_condition_pushdown=off';
EXPLAIN select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue
from customer, orders, lineitem, supplier, nation, region
where c_custkey = o_custkey and l_orderkey = o_orderkey
and l_suppkey = s_suppkey and c_nationkey = s_nationkey
and s_nationkey = n_nationkey and n_regionkey = r_regionkey
and r_name = 'AMERICA' and o_orderdate >= date '1995-01-01'
and o_orderdate < date '1995-01-01' + interval '1' year
group by n_name
order by revenue desc;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE orders range PRIMARY,i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 179 Using where; Using temporary; Using filesort
1 SIMPLE customer eq_ref PRIMARY,i_c_nationkey PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where
1 SIMPLE nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.customer.c_nationkey 1
1 SIMPLE region ALL PRIMARY NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join)
1 SIMPLE lineitem ref PRIMARY,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where
1 SIMPLE supplier eq_ref PRIMARY,i_s_nationkey PRIMARY 4 dbt3_s001.lineitem.l_suppkey 1 Using where
select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue
from customer, orders, lineitem, supplier, nation, region
where c_custkey = o_custkey and l_orderkey = o_orderkey
and l_suppkey = s_suppkey and c_nationkey = s_nationkey
and s_nationkey = n_nationkey and n_regionkey = r_regionkey
and r_name = 'AMERICA' and o_orderdate >= date '1995-01-01'
and o_orderdate < date '1995-01-01' + interval '1' year
group by n_name
order by revenue desc;
n_name revenue
PERU 321915.8715
ARGENTINA 69817.1451
set optimizer_switch=@save_optimizer_switch;
delete from mysql.index_stat;
select * from mysql.table_stat;
db_name table_name cardinality
dbt3_s001 customer 150
dbt3_s001 lineitem 6005
dbt3_s001 nation 25
dbt3_s001 orders 1500
dbt3_s001 part 200
dbt3_s001 partsupp 700
dbt3_s001 region 5
dbt3_s001 supplier 10
select * from mysql.index_stat;
db_name table_name index_name prefix_arity avg_frequency
dbt3_s001 customer PRIMARY 1 1.0000
dbt3_s001 customer i_c_nationkey 1 6.0000
dbt3_s001 lineitem PRIMARY 1 4.0033
dbt3_s001 lineitem PRIMARY 2 1.0000
dbt3_s001 lineitem i_l_shipdate 1 2.6500
dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250
dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786
dbt3_s001 lineitem i_l_partkey 1 30.0250
dbt3_s001 lineitem i_l_suppkey 1 600.5000
dbt3_s001 lineitem i_l_receiptdate 1 2.6477
dbt3_s001 lineitem i_l_orderkey 1 4.0033
dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033
dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404
dbt3_s001 lineitem i_l_commitdate 1 2.7160
dbt3_s001 nation PRIMARY 1 1.0000
dbt3_s001 nation i_n_regionkey 1 5.0000
dbt3_s001 orders PRIMARY 1 1.0000
dbt3_s001 orders i_o_orderdate 1 1.3321
dbt3_s001 orders i_o_custkey 1 15.0000
dbt3_s001 part PRIMARY 1 1.0000
dbt3_s001 part i_p_retailprice 1 1.0000
dbt3_s001 partsupp PRIMARY 1 3.5000
dbt3_s001 partsupp PRIMARY 2 1.0000
dbt3_s001 partsupp i_ps_partkey 1 3.5000
dbt3_s001 partsupp i_ps_suppkey 1 70.0000
dbt3_s001 region PRIMARY 1 1.0000
dbt3_s001 supplier PRIMARY 1 1.0000
dbt3_s001 supplier i_s_nationkey 1 1.1111
select * from mysql.table_stat where table_name='orders';
db_name table_name cardinality
dbt3_s001 orders 1500
select * from mysql.index_stat where table_name='orders';
db_name table_name index_name prefix_arity avg_frequency
dbt3_s001 orders PRIMARY 1 1.0000
dbt3_s001 orders i_o_orderdate 1 1.3321
dbt3_s001 orders i_o_custkey 1 15.0000
select (select cardinality from mysql.table_stat where table_name='orders') /
(select avg_frequency from mysql.index_stat
where index_name='i_o_orderdate' and prefix_arity=1) as n_distinct;
n_distinct
1126.0416
select count(distinct o_orderdate) from orders;
count(distinct o_orderdate)
1126
select (select cardinality from mysql.table_stat where table_name='orders') /
(select avg_frequency from mysql.index_stat
where index_name='i_o_custkey' and prefix_arity=1) as n_distinct;
n_distinct
100.0000
select count(distinct o_custkey) from orders;
count(distinct o_custkey)
100
show index from orders;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
orders 0 PRIMARY 1 o_orderkey A 1500 NULL NULL BTREE
orders 1 i_o_orderdate 1 o_orderDATE A 1126 NULL NULL YES BTREE
orders 1 i_o_custkey 1 o_custkey A 100 NULL NULL YES BTREE
select index_name, column_name, cardinality from information_schema.statistics
where table_name='orders';
index_name column_name cardinality
PRIMARY o_orderkey 1500
i_o_orderdate o_orderDATE 1126
i_o_custkey o_custkey 100
set @save_optimizer_switch=@@optimizer_switch;
set optimizer_switch='index_condition_pushdown=off';
EXPLAIN select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue
from customer, orders, lineitem, supplier, nation, region
where c_custkey = o_custkey and l_orderkey = o_orderkey
and l_suppkey = s_suppkey and c_nationkey = s_nationkey
and s_nationkey = n_nationkey and n_regionkey = r_regionkey
and r_name = 'AMERICA' and o_orderdate >= date '1995-01-01'
and o_orderdate < date '1995-01-01' + interval '1' year
group by n_name
order by revenue desc;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE orders range PRIMARY,i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 179 Using where; Using temporary; Using filesort
1 SIMPLE customer eq_ref PRIMARY,i_c_nationkey PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where
1 SIMPLE nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.customer.c_nationkey 1
1 SIMPLE region ALL PRIMARY NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join)
1 SIMPLE lineitem ref PRIMARY,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where
1 SIMPLE supplier eq_ref PRIMARY,i_s_nationkey PRIMARY 4 dbt3_s001.lineitem.l_suppkey 1 Using where
select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue
from customer, orders, lineitem, supplier, nation, region
where c_custkey = o_custkey and l_orderkey = o_orderkey
and l_suppkey = s_suppkey and c_nationkey = s_nationkey
and s_nationkey = n_nationkey and n_regionkey = r_regionkey
and r_name = 'AMERICA' and o_orderdate >= date '1995-01-01'
and o_orderdate < date '1995-01-01' + interval '1' year
group by n_name
order by revenue desc;
n_name revenue
PERU 321915.8715
ARGENTINA 69817.1451
set optimizer_switch=@save_optimizer_switch;
EXPLAIN select o_year,
sum(case when nation = 'UNITED STATES' then volume else 0 end) /
sum(volume) as mkt_share
from (select extract(year from o_orderdate) as o_year,
l_extendedprice * (1-l_discount) as volume,
n2.n_name as nation
from part, supplier, lineitem, orders, customer,
nation n1, nation n2, region
where p_partkey = l_partkey and s_suppkey = l_suppkey
and l_orderkey = o_orderkey and o_custkey = c_custkey
and c_nationkey = n1.n_nationkey and n1.n_regionkey = r_regionkey
and r_name = 'AMERICA' and s_nationkey = n2.n_nationkey
and o_orderdate between date '1995-01-01' and date '1996-12-31'
and p_type = 'STANDARD BRUSHED STEEL' ) as all_nations
group by o_year
order by o_year;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE orders ALL PRIMARY,i_o_orderdate,i_o_custkey NULL NULL NULL 1500 Using where; Using temporary; Using filesort
1 SIMPLE customer eq_ref PRIMARY,i_c_nationkey PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where
1 SIMPLE n1 eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.customer.c_nationkey 1
1 SIMPLE region ALL PRIMARY NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join)
1 SIMPLE lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where
1 SIMPLE part eq_ref PRIMARY PRIMARY 4 dbt3_s001.lineitem.l_partkey 1 Using where
1 SIMPLE supplier eq_ref PRIMARY,i_s_nationkey PRIMARY 4 dbt3_s001.lineitem.l_suppkey 1 Using where
1 SIMPLE n2 eq_ref PRIMARY PRIMARY 4 dbt3_s001.supplier.s_nationkey 1
select o_year,
sum(case when nation = 'UNITED STATES' then volume else 0 end) /
sum(volume) as mkt_share
from (select extract(year from o_orderdate) as o_year,
l_extendedprice * (1-l_discount) as volume,
n2.n_name as nation
from part, supplier, lineitem, orders, customer,
nation n1, nation n2, region
where p_partkey = l_partkey and s_suppkey = l_suppkey
and l_orderkey = o_orderkey and o_custkey = c_custkey
and c_nationkey = n1.n_nationkey and n1.n_regionkey = r_regionkey
and r_name = 'AMERICA' and s_nationkey = n2.n_nationkey
and o_orderdate between date '1995-01-01' and date '1996-12-31'
and p_type = 'STANDARD BRUSHED STEEL' ) as all_nations
group by o_year
order by o_year;
o_year mkt_share
1995 0.4495521838895718
1996 0.024585468215352495
EXPLAIN select nation, o_year, sum(amount) as sum_profit
from (select n_name as nation,
extract(year from o_orderdate) as o_year,
l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount
from part, supplier, lineitem, partsupp, orders, nation
where s_suppkey = l_suppkey and ps_suppkey = l_suppkey
and ps_partkey = l_partkey and p_partkey = l_partkey
and o_orderkey = l_orderkey and s_nationkey = n_nationkey
and p_name like '%green%') as profit
group by nation, o_year
order by nation, o_year desc;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE supplier ALL PRIMARY,i_s_nationkey NULL NULL NULL 10 Using where; Using temporary; Using filesort
1 SIMPLE nation eq_ref PRIMARY PRIMARY 4 dbt3_s001.supplier.s_nationkey 1
1 SIMPLE partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 70
1 SIMPLE part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 Using where
1 SIMPLE lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.supplier.s_suppkey 8
1 SIMPLE orders eq_ref PRIMARY PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1
select nation, o_year, sum(amount) as sum_profit
from (select n_name as nation,
extract(year from o_orderdate) as o_year,
l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount
from part, supplier, lineitem, partsupp, orders, nation
where s_suppkey = l_suppkey and ps_suppkey = l_suppkey
and ps_partkey = l_partkey and p_partkey = l_partkey
and o_orderkey = l_orderkey and s_nationkey = n_nationkey
and p_name like '%green%') as profit
group by nation, o_year
order by nation, o_year desc;
nation o_year sum_profit
ARGENTINA 1997 18247.873399999993
ARGENTINA 1996 7731.089399999995
ARGENTINA 1995 134490.5697
ARGENTINA 1994 36767.101500000004
ARGENTINA 1993 35857.08
ARGENTINA 1992 35740
ETHIOPIA 1998 2758.7801999999992
ETHIOPIA 1997 19419.294599999997
ETHIOPIA 1995 51231.87439999999
ETHIOPIA 1994 3578.9478999999974
ETHIOPIA 1992 1525.8234999999986
IRAN 1998 37817.229600000006
IRAN 1997 52643.77359999999
IRAN 1996 70143.7761
IRAN 1995 84094.58260000001
IRAN 1994 18140.925599999995
IRAN 1993 78655.1676
IRAN 1992 87142.23960000002
IRAQ 1998 22860.8082
IRAQ 1997 93676.24359999999
IRAQ 1996 45103.3242
IRAQ 1994 36010.728599999995
IRAQ 1993 33221.9399
IRAQ 1992 47755.05900000001
KENYA 1998 44194.831999999995
KENYA 1997 57578.36259999999
KENYA 1996 59195.90210000001
KENYA 1995 79262.6278
KENYA 1994 102360.66609999999
KENYA 1993 128422.0196
KENYA 1992 181517.2089
MOROCCO 1998 41797.823199999984
MOROCCO 1997 23685.801799999994
MOROCCO 1996 62115.19579999998
MOROCCO 1995 42442.64300000001
MOROCCO 1994 48655.878000000004
MOROCCO 1993 22926.744400000003
MOROCCO 1992 32239.8088
PERU 1998 86999.36459999997
PERU 1997 121110.41070000001
PERU 1996 177040.40759999995
PERU 1995 122247.94520000002
PERU 1994 88046.25329999998
PERU 1993 49379.813799999996
PERU 1992 80646.86050000001
UNITED KINGDOM 1998 50577.25560000001
UNITED KINGDOM 1997 114288.8605
UNITED KINGDOM 1996 147684.46480000002
UNITED KINGDOM 1995 225267.65759999998
UNITED KINGDOM 1994 140595.5864
UNITED KINGDOM 1993 322548.49210000003
UNITED KINGDOM 1992 67747.88279999999
UNITED STATES 1998 3957.0431999999996
UNITED STATES 1997 94729.5704
UNITED STATES 1996 79297.85670000002
UNITED STATES 1995 62201.23360000001
UNITED STATES 1994 43075.629899999985
UNITED STATES 1993 27168.486199999996
UNITED STATES 1992 34092.366
set @save_optimizer_switch=@@optimizer_switch;
set optimizer_switch='extended_keys=on';
EXPLAIN select o_orderkey, p_partkey
from part, lineitem, orders
where p_retailprice > 1100 and o_orderdate='1997-01-01'
and o_orderkey=l_orderkey and p_partkey=l_partkey;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE orders ref PRIMARY,i_o_orderdate i_o_orderdate 4 const 1
1 SIMPLE lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where
1 SIMPLE part eq_ref PRIMARY,i_p_retailprice PRIMARY 4 dbt3_s001.lineitem.l_partkey 1 Using where
select o_orderkey, p_partkey
from part, lineitem, orders
where p_retailprice > 1100 and o_orderdate='1997-01-01'
and o_orderkey=l_orderkey and p_partkey=l_partkey;
o_orderkey p_partkey
5895 200
set optimizer_switch=@save_optimizer_switch;
DROP DATABASE dbt3_s001;
use test;
#
# Bug mdev-473: ANALYZE table locked for write
#
set use_stat_tables='complementary';
create table t1 (i int);
lock table t1 write;
analyze table t1;
Table Op Msg_type Msg_text
test.t1 analyze status Table is already up to date
alter table t1 add column a varchar(8);
drop table t1;
#
# Bug mdev-487: memory leak in ANALYZE with stat tables
#
SET use_stat_tables = 'preferably';
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(2);
DELETE FROM t1 WHERE a=1;
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
DROP TABLE t1;
#
# Bug mdev-518: corrupted/missing statistical tables
#
CREATE TABLE t1 (i int) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1),(2);
FLUSH TABLE t1;
SET use_stat_tables='never';
EXPLAIN SELECT * FROM t1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2
FLUSH TABLES;
SET use_stat_tables='preferably';
EXPLAIN SELECT * FROM t1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2
DROP TABLE t1;
set use_stat_tables=@save_use_stat_tables;

View File

@ -0,0 +1,70 @@
SET SESSION STORAGE_ENGINE='InnoDB';
select @@global.use_stat_tables;
@@global.use_stat_tables
NEVER
select @@session.use_stat_tables;
@@session.use_stat_tables
NEVER
set @save_use_stat_tables=@@use_stat_tables;
set use_stat_tables='preferably';
DROP DATABASE IF EXISTS dbt3_s001;
CREATE DATABASE dbt3_s001;
use dbt3_s001;
set @save_optimizer_switch=@@optimizer_switch;
set optimizer_switch='extended_keys=off';
#
# Bug mdev-503: optimizer ignores setting use_stat_tables='preferably'
#
flush tables
customer, lineitem, nation, orders, part, partsupp, region, supplier;
set use_stat_tables='never';
EXPLAIN select sql_calc_found_rows straight_join
l_orderkey, sum(l_extendedprice*(1-l_discount)) as revenue,
o_orderdate, o_shippriority
from orders, customer, lineitem
where c_mktsegment = 'BUILDING' and c_custkey = o_custkey
and l_orderkey = o_orderkey and o_orderdate < date '1995-03-15'
and l_shipdate > date '1995-03-15'
group by l_orderkey, o_orderdate, o_shippriority
order by revenue desc, o_orderdate
limit 10;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE orders ALL PRIMARY,i_o_orderdate,i_o_custkey NULL NULL NULL # Using where; Using temporary; Using filesort
1 SIMPLE customer eq_ref PRIMARY PRIMARY 4 dbt3_s001.orders.o_custkey # Using where
1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey # Using where
set use_stat_tables='preferably';
EXPLAIN select sql_calc_found_rows straight_join
l_orderkey, sum(l_extendedprice*(1-l_discount)) as revenue,
o_orderdate, o_shippriority
from orders, customer, lineitem
where c_mktsegment = 'BUILDING' and c_custkey = o_custkey
and l_orderkey = o_orderkey and o_orderdate < date '1995-03-15'
and l_shipdate > date '1995-03-15'
group by l_orderkey, o_orderdate, o_shippriority
order by revenue desc, o_orderdate
limit 10;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE orders ALL PRIMARY,i_o_orderdate,i_o_custkey NULL NULL NULL 1500 Using where; Using temporary; Using filesort
1 SIMPLE customer eq_ref PRIMARY PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where
1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where
flush tables customer, orders, lineitem;
EXPLAIN select sql_calc_found_rows straight_join
l_orderkey, sum(l_extendedprice*(1-l_discount)) as revenue,
o_orderdate, o_shippriority
from orders, customer, lineitem
where c_mktsegment = 'BUILDING' and c_custkey = o_custkey
and l_orderkey = o_orderkey and o_orderdate < date '1995-03-15'
and l_shipdate > date '1995-03-15'
group by l_orderkey, o_orderdate, o_shippriority
order by revenue desc, o_orderdate
limit 10;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE orders ALL PRIMARY,i_o_orderdate,i_o_custkey NULL NULL NULL 1500 Using where; Using temporary; Using filesort
1 SIMPLE customer eq_ref PRIMARY PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where
1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where
# End of the test case for mdev-503
set optimizer_switch=@save_optimizer_switch;
DROP DATABASE dbt3_s001;
use test;
set use_stat_tables=@save_use_stat_tables;
SET SESSION STORAGE_ENGINE=DEFAULT;

View File

@ -0,0 +1,412 @@
SET SESSION STORAGE_ENGINE='InnoDB';
set @save_optimizer_switch_for_stat_tables_test=@@optimizer_switch;
set optimizer_switch='extended_keys=on';
select @@global.use_stat_tables;
@@global.use_stat_tables
COMPLEMENTARY
select @@session.use_stat_tables;
@@session.use_stat_tables
COMPLEMENTARY
set @save_use_stat_tables=@@use_stat_tables;
set use_stat_tables='preferably';
DROP DATABASE IF EXISTS dbt3_s001;
CREATE DATABASE dbt3_s001;
use dbt3_s001;
set @save_optimizer_switch=@@optimizer_switch;
set optimizer_switch='extended_keys=off';
select * from mysql.table_stat;
db_name table_name cardinality
dbt3_s001 customer 150
dbt3_s001 lineitem 6005
dbt3_s001 nation 25
dbt3_s001 orders 1500
dbt3_s001 part 200
dbt3_s001 partsupp 700
dbt3_s001 region 5
dbt3_s001 supplier 10
select * from mysql.index_stat;
db_name table_name index_name prefix_arity avg_frequency
dbt3_s001 customer PRIMARY 1 1.0000
dbt3_s001 customer i_c_nationkey 1 6.0000
dbt3_s001 lineitem PRIMARY 1 4.0033
dbt3_s001 lineitem PRIMARY 2 1.0000
dbt3_s001 lineitem i_l_shipdate 1 2.6500
dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250
dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786
dbt3_s001 lineitem i_l_partkey 1 30.0250
dbt3_s001 lineitem i_l_suppkey 1 600.5000
dbt3_s001 lineitem i_l_receiptdate 1 2.6477
dbt3_s001 lineitem i_l_orderkey 1 4.0033
dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033
dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404
dbt3_s001 lineitem i_l_commitdate 1 2.7160
dbt3_s001 nation PRIMARY 1 1.0000
dbt3_s001 nation i_n_regionkey 1 5.0000
dbt3_s001 orders PRIMARY 1 1.0000
dbt3_s001 orders i_o_orderdate 1 1.3321
dbt3_s001 orders i_o_custkey 1 15.0000
dbt3_s001 part PRIMARY 1 1.0000
dbt3_s001 part i_p_retailprice 1 1.0000
dbt3_s001 partsupp PRIMARY 1 3.5000
dbt3_s001 partsupp PRIMARY 2 1.0000
dbt3_s001 partsupp i_ps_partkey 1 3.5000
dbt3_s001 partsupp i_ps_suppkey 1 70.0000
dbt3_s001 region PRIMARY 1 1.0000
dbt3_s001 supplier PRIMARY 1 1.0000
dbt3_s001 supplier i_s_nationkey 1 1.1111
set optimizer_switch=@save_optimizer_switch;
set @save_optimizer_switch=@@optimizer_switch;
set optimizer_switch='index_condition_pushdown=off';
EXPLAIN select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue
from customer, orders, lineitem, supplier, nation, region
where c_custkey = o_custkey and l_orderkey = o_orderkey
and l_suppkey = s_suppkey and c_nationkey = s_nationkey
and s_nationkey = n_nationkey and n_regionkey = r_regionkey
and r_name = 'AMERICA' and o_orderdate >= date '1995-01-01'
and o_orderdate < date '1995-01-01' + interval '1' year
group by n_name
order by revenue desc;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE orders range PRIMARY,i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 211 Using where; Using temporary; Using filesort
1 SIMPLE customer eq_ref PRIMARY,i_c_nationkey PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where
1 SIMPLE nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.customer.c_nationkey 1
1 SIMPLE supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.customer.c_nationkey 1 Using index
1 SIMPLE region ALL PRIMARY NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join)
1 SIMPLE lineitem ref PRIMARY,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where
select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue
from customer, orders, lineitem, supplier, nation, region
where c_custkey = o_custkey and l_orderkey = o_orderkey
and l_suppkey = s_suppkey and c_nationkey = s_nationkey
and s_nationkey = n_nationkey and n_regionkey = r_regionkey
and r_name = 'AMERICA' and o_orderdate >= date '1995-01-01'
and o_orderdate < date '1995-01-01' + interval '1' year
group by n_name
order by revenue desc;
n_name revenue
PERU 321915.8715
ARGENTINA 69817.1451
set optimizer_switch=@save_optimizer_switch;
delete from mysql.index_stat;
select * from mysql.table_stat;
db_name table_name cardinality
dbt3_s001 customer 150
dbt3_s001 lineitem 6005
dbt3_s001 nation 25
dbt3_s001 orders 1500
dbt3_s001 part 200
dbt3_s001 partsupp 700
dbt3_s001 region 5
dbt3_s001 supplier 10
select * from mysql.index_stat;
db_name table_name index_name prefix_arity avg_frequency
dbt3_s001 customer PRIMARY 1 1.0000
dbt3_s001 customer i_c_nationkey 1 6.0000
dbt3_s001 customer i_c_nationkey 2 1.0000
dbt3_s001 lineitem PRIMARY 1 4.0033
dbt3_s001 lineitem PRIMARY 2 1.0000
dbt3_s001 lineitem i_l_shipdate 1 2.6500
dbt3_s001 lineitem i_l_shipdate 2 1.0149
dbt3_s001 lineitem i_l_shipdate 3 1.0000
dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250
dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786
dbt3_s001 lineitem i_l_suppkey_partkey 3 1.0030
dbt3_s001 lineitem i_l_suppkey_partkey 4 1.0000
dbt3_s001 lineitem i_l_partkey 1 30.0250
dbt3_s001 lineitem i_l_partkey 2 1.0089
dbt3_s001 lineitem i_l_partkey 3 1.0000
dbt3_s001 lineitem i_l_suppkey 1 600.5000
dbt3_s001 lineitem i_l_suppkey 2 1.2073
dbt3_s001 lineitem i_l_suppkey 3 1.0000
dbt3_s001 lineitem i_l_receiptdate 1 2.6477
dbt3_s001 lineitem i_l_receiptdate 2 1.0152
dbt3_s001 lineitem i_l_receiptdate 3 1.0000
dbt3_s001 lineitem i_l_orderkey 1 4.0033
dbt3_s001 lineitem i_l_orderkey 2 1.0000
dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033
dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404
dbt3_s001 lineitem i_l_orderkey_quantity 3 1.0000
dbt3_s001 lineitem i_l_commitdate 1 2.7160
dbt3_s001 lineitem i_l_commitdate 2 1.0364
dbt3_s001 lineitem i_l_commitdate 3 1.0000
dbt3_s001 nation PRIMARY 1 1.0000
dbt3_s001 nation i_n_regionkey 1 5.0000
dbt3_s001 nation i_n_regionkey 2 1.0000
dbt3_s001 orders PRIMARY 1 1.0000
dbt3_s001 orders i_o_orderdate 1 1.3321
dbt3_s001 orders i_o_orderdate 2 1.0000
dbt3_s001 orders i_o_custkey 1 15.0000
dbt3_s001 orders i_o_custkey 2 1.0000
dbt3_s001 part PRIMARY 1 1.0000
dbt3_s001 part i_p_retailprice 1 1.0000
dbt3_s001 part i_p_retailprice 2 1.0000
dbt3_s001 partsupp PRIMARY 1 3.5000
dbt3_s001 partsupp PRIMARY 2 1.0000
dbt3_s001 partsupp i_ps_partkey 1 3.5000
dbt3_s001 partsupp i_ps_partkey 2 1.0000
dbt3_s001 partsupp i_ps_suppkey 1 70.0000
dbt3_s001 partsupp i_ps_suppkey 2 1.0000
dbt3_s001 region PRIMARY 1 1.0000
dbt3_s001 supplier PRIMARY 1 1.0000
dbt3_s001 supplier i_s_nationkey 1 1.1111
dbt3_s001 supplier i_s_nationkey 2 1.0000
select * from mysql.table_stat where table_name='orders';
db_name table_name cardinality
dbt3_s001 orders 1500
select * from mysql.index_stat where table_name='orders';
db_name table_name index_name prefix_arity avg_frequency
dbt3_s001 orders PRIMARY 1 1.0000
dbt3_s001 orders i_o_orderdate 1 1.3321
dbt3_s001 orders i_o_orderdate 2 1.0000
dbt3_s001 orders i_o_custkey 1 15.0000
dbt3_s001 orders i_o_custkey 2 1.0000
select (select cardinality from mysql.table_stat where table_name='orders') /
(select avg_frequency from mysql.index_stat
where index_name='i_o_orderdate' and prefix_arity=1) as n_distinct;
n_distinct
1126.0416
select count(distinct o_orderdate) from orders;
count(distinct o_orderdate)
1126
select (select cardinality from mysql.table_stat where table_name='orders') /
(select avg_frequency from mysql.index_stat
where index_name='i_o_custkey' and prefix_arity=1) as n_distinct;
n_distinct
100.0000
select count(distinct o_custkey) from orders;
count(distinct o_custkey)
100
show index from orders;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
orders 0 PRIMARY 1 o_orderkey A 1500 NULL NULL BTREE
orders 1 i_o_orderdate 1 o_orderDATE A 1126 NULL NULL YES BTREE
orders 1 i_o_custkey 1 o_custkey A 100 NULL NULL YES BTREE
select index_name, column_name, cardinality from information_schema.statistics
where table_name='orders';
index_name column_name cardinality
PRIMARY o_orderkey 1500
i_o_orderdate o_orderDATE 1126
i_o_custkey o_custkey 100
set @save_optimizer_switch=@@optimizer_switch;
set optimizer_switch='index_condition_pushdown=off';
EXPLAIN select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue
from customer, orders, lineitem, supplier, nation, region
where c_custkey = o_custkey and l_orderkey = o_orderkey
and l_suppkey = s_suppkey and c_nationkey = s_nationkey
and s_nationkey = n_nationkey and n_regionkey = r_regionkey
and r_name = 'AMERICA' and o_orderdate >= date '1995-01-01'
and o_orderdate < date '1995-01-01' + interval '1' year
group by n_name
order by revenue desc;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE orders range PRIMARY,i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 211 Using where; Using temporary; Using filesort
1 SIMPLE customer eq_ref PRIMARY,i_c_nationkey PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where
1 SIMPLE nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.customer.c_nationkey 1
1 SIMPLE supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.customer.c_nationkey 1 Using index
1 SIMPLE region ALL PRIMARY NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join)
1 SIMPLE lineitem ref PRIMARY,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where
select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue
from customer, orders, lineitem, supplier, nation, region
where c_custkey = o_custkey and l_orderkey = o_orderkey
and l_suppkey = s_suppkey and c_nationkey = s_nationkey
and s_nationkey = n_nationkey and n_regionkey = r_regionkey
and r_name = 'AMERICA' and o_orderdate >= date '1995-01-01'
and o_orderdate < date '1995-01-01' + interval '1' year
group by n_name
order by revenue desc;
n_name revenue
PERU 321915.8715
ARGENTINA 69817.1451
set optimizer_switch=@save_optimizer_switch;
EXPLAIN select o_year,
sum(case when nation = 'UNITED STATES' then volume else 0 end) /
sum(volume) as mkt_share
from (select extract(year from o_orderdate) as o_year,
l_extendedprice * (1-l_discount) as volume,
n2.n_name as nation
from part, supplier, lineitem, orders, customer,
nation n1, nation n2, region
where p_partkey = l_partkey and s_suppkey = l_suppkey
and l_orderkey = o_orderkey and o_custkey = c_custkey
and c_nationkey = n1.n_nationkey and n1.n_regionkey = r_regionkey
and r_name = 'AMERICA' and s_nationkey = n2.n_nationkey
and o_orderdate between date '1995-01-01' and date '1996-12-31'
and p_type = 'STANDARD BRUSHED STEEL' ) as all_nations
group by o_year
order by o_year;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE orders ALL PRIMARY,i_o_orderdate,i_o_custkey NULL NULL NULL 1500 Using where; Using temporary; Using filesort
1 SIMPLE customer eq_ref PRIMARY,i_c_nationkey PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where
1 SIMPLE n1 eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.customer.c_nationkey 1
1 SIMPLE region ALL PRIMARY NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join)
1 SIMPLE lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where
1 SIMPLE part eq_ref PRIMARY PRIMARY 4 dbt3_s001.lineitem.l_partkey 1 Using where
1 SIMPLE supplier eq_ref PRIMARY,i_s_nationkey PRIMARY 4 dbt3_s001.lineitem.l_suppkey 1 Using where
1 SIMPLE n2 eq_ref PRIMARY PRIMARY 4 dbt3_s001.supplier.s_nationkey 1
select o_year,
sum(case when nation = 'UNITED STATES' then volume else 0 end) /
sum(volume) as mkt_share
from (select extract(year from o_orderdate) as o_year,
l_extendedprice * (1-l_discount) as volume,
n2.n_name as nation
from part, supplier, lineitem, orders, customer,
nation n1, nation n2, region
where p_partkey = l_partkey and s_suppkey = l_suppkey
and l_orderkey = o_orderkey and o_custkey = c_custkey
and c_nationkey = n1.n_nationkey and n1.n_regionkey = r_regionkey
and r_name = 'AMERICA' and s_nationkey = n2.n_nationkey
and o_orderdate between date '1995-01-01' and date '1996-12-31'
and p_type = 'STANDARD BRUSHED STEEL' ) as all_nations
group by o_year
order by o_year;
o_year mkt_share
1995 0.4495521838895718
1996 0.024585468215352495
EXPLAIN select nation, o_year, sum(amount) as sum_profit
from (select n_name as nation,
extract(year from o_orderdate) as o_year,
l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount
from part, supplier, lineitem, partsupp, orders, nation
where s_suppkey = l_suppkey and ps_suppkey = l_suppkey
and ps_partkey = l_partkey and p_partkey = l_partkey
and o_orderkey = l_orderkey and s_nationkey = n_nationkey
and p_name like '%green%') as profit
group by nation, o_year
order by nation, o_year desc;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE supplier index PRIMARY,i_s_nationkey i_s_nationkey 5 NULL 10 Using where; Using index; Using temporary; Using filesort
1 SIMPLE nation eq_ref PRIMARY PRIMARY 4 dbt3_s001.supplier.s_nationkey 1
1 SIMPLE partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 70
1 SIMPLE part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 Using where
1 SIMPLE lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.supplier.s_suppkey 8
1 SIMPLE orders eq_ref PRIMARY PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1
select nation, o_year, sum(amount) as sum_profit
from (select n_name as nation,
extract(year from o_orderdate) as o_year,
l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount
from part, supplier, lineitem, partsupp, orders, nation
where s_suppkey = l_suppkey and ps_suppkey = l_suppkey
and ps_partkey = l_partkey and p_partkey = l_partkey
and o_orderkey = l_orderkey and s_nationkey = n_nationkey
and p_name like '%green%') as profit
group by nation, o_year
order by nation, o_year desc;
nation o_year sum_profit
ARGENTINA 1997 18247.873399999993
ARGENTINA 1996 7731.089399999995
ARGENTINA 1995 134490.5697
ARGENTINA 1994 36767.101500000004
ARGENTINA 1993 35857.08
ARGENTINA 1992 35740
ETHIOPIA 1998 2758.7801999999992
ETHIOPIA 1997 19419.294599999997
ETHIOPIA 1995 51231.87439999999
ETHIOPIA 1994 3578.9478999999974
ETHIOPIA 1992 1525.8234999999986
IRAN 1998 37817.229600000006
IRAN 1997 52643.77359999999
IRAN 1996 70143.7761
IRAN 1995 84094.58260000001
IRAN 1994 18140.925599999995
IRAN 1993 78655.1676
IRAN 1992 87142.23960000002
IRAQ 1998 22860.8082
IRAQ 1997 93676.24359999999
IRAQ 1996 45103.3242
IRAQ 1994 36010.728599999995
IRAQ 1993 33221.9399
IRAQ 1992 47755.05900000001
KENYA 1998 44194.831999999995
KENYA 1997 57578.36259999999
KENYA 1996 59195.90210000001
KENYA 1995 79262.6278
KENYA 1994 102360.66609999999
KENYA 1993 128422.0196
KENYA 1992 181517.2089
MOROCCO 1998 41797.823199999984
MOROCCO 1997 23685.801799999994
MOROCCO 1996 62115.19579999998
MOROCCO 1995 42442.64300000001
MOROCCO 1994 48655.878000000004
MOROCCO 1993 22926.744400000003
MOROCCO 1992 32239.8088
PERU 1998 86999.36459999997
PERU 1997 121110.41070000001
PERU 1996 177040.40759999995
PERU 1995 122247.94520000002
PERU 1994 88046.25329999998
PERU 1993 49379.813799999996
PERU 1992 80646.86050000001
UNITED KINGDOM 1998 50577.25560000001
UNITED KINGDOM 1997 114288.8605
UNITED KINGDOM 1996 147684.46480000002
UNITED KINGDOM 1995 225267.65759999998
UNITED KINGDOM 1994 140595.5864
UNITED KINGDOM 1993 322548.49210000003
UNITED KINGDOM 1992 67747.88279999999
UNITED STATES 1998 3957.0431999999996
UNITED STATES 1997 94729.5704
UNITED STATES 1996 79297.85670000002
UNITED STATES 1995 62201.23360000001
UNITED STATES 1994 43075.629899999985
UNITED STATES 1993 27168.486199999996
UNITED STATES 1992 34092.366
set @save_optimizer_switch=@@optimizer_switch;
set optimizer_switch='extended_keys=on';
EXPLAIN select o_orderkey, p_partkey
from part, lineitem, orders
where p_retailprice > 1100 and o_orderdate='1997-01-01'
and o_orderkey=l_orderkey and p_partkey=l_partkey;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE part range PRIMARY,i_p_retailprice i_p_retailprice 9 NULL 1 Using where; Using index
1 SIMPLE orders ref PRIMARY,i_o_orderdate i_o_orderdate 4 const 1 Using index
1 SIMPLE lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_orderkey,i_l_orderkey_quantity i_l_partkey 9 dbt3_s001.part.p_partkey,dbt3_s001.orders.o_orderkey 1 Using index
select o_orderkey, p_partkey
from part, lineitem, orders
where p_retailprice > 1100 and o_orderdate='1997-01-01'
and o_orderkey=l_orderkey and p_partkey=l_partkey;
o_orderkey p_partkey
5895 200
set optimizer_switch=@save_optimizer_switch;
DROP DATABASE dbt3_s001;
use test;
#
# Bug mdev-473: ANALYZE table locked for write
#
set use_stat_tables='complementary';
create table t1 (i int);
lock table t1 write;
analyze table t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
alter table t1 add column a varchar(8);
drop table t1;
#
# Bug mdev-487: memory leak in ANALYZE with stat tables
#
SET use_stat_tables = 'preferably';
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(2);
DELETE FROM t1 WHERE a=1;
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
DROP TABLE t1;
#
# Bug mdev-518: corrupted/missing statistical tables
#
CREATE TABLE t1 (i int) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1),(2);
FLUSH TABLE t1;
SET use_stat_tables='never';
EXPLAIN SELECT * FROM t1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2
FLUSH TABLES;
SET use_stat_tables='preferably';
EXPLAIN SELECT * FROM t1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2
DROP TABLE t1;
set use_stat_tables=@save_use_stat_tables;
set optimizer_switch=@save_optimizer_switch_for_stat_tables_test;
SET SESSION STORAGE_ENGINE=DEFAULT;

View File

@ -0,0 +1,167 @@
set @save_use_stat_tables=@@use_stat_tables;
set use_stat_tables='preferably';
DROP DATABASE IF EXISTS dbt3_s001;
CREATE DATABASE dbt3_s001;
use dbt3_s001;
set @save_optimizer_switch=@@optimizer_switch;
set optimizer_switch='extended_keys=off';
select * from mysql.table_stat;
db_name table_name cardinality
dbt3_s001 customer 150
dbt3_s001 lineitem 6005
dbt3_s001 nation 25
dbt3_s001 orders 1500
dbt3_s001 part 200
dbt3_s001 partsupp 700
dbt3_s001 region 5
dbt3_s001 supplier 10
select * from mysql.index_stat;
db_name table_name index_name prefix_arity avg_frequency
dbt3_s001 customer PRIMARY 1 1.0000
dbt3_s001 customer i_c_nationkey 1 6.0000
dbt3_s001 lineitem PRIMARY 1 4.0033
dbt3_s001 lineitem PRIMARY 2 1.0000
dbt3_s001 lineitem i_l_shipdate 1 2.6500
dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250
dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786
dbt3_s001 lineitem i_l_partkey 1 30.0250
dbt3_s001 lineitem i_l_suppkey 1 600.5000
dbt3_s001 lineitem i_l_receiptdate 1 2.6477
dbt3_s001 lineitem i_l_orderkey 1 4.0033
dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033
dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404
dbt3_s001 lineitem i_l_commitdate 1 2.7160
dbt3_s001 nation PRIMARY 1 1.0000
dbt3_s001 nation i_n_regionkey 1 5.0000
dbt3_s001 orders PRIMARY 1 1.0000
dbt3_s001 orders i_o_orderdate 1 1.3321
dbt3_s001 orders i_o_custkey 1 15.0000
dbt3_s001 part PRIMARY 1 1.0000
dbt3_s001 partsupp PRIMARY 1 3.5000
dbt3_s001 partsupp PRIMARY 2 1.0000
dbt3_s001 partsupp i_ps_partkey 1 3.5000
dbt3_s001 partsupp i_ps_suppkey 1 70.0000
dbt3_s001 region PRIMARY 1 1.0000
dbt3_s001 supplier PRIMARY 1 1.0000
dbt3_s001 supplier i_s_nationkey 1 1.1111
flush table lineitem;
set use_stat_tables='never';
select sum(l_extendedprice*l_discount) as revenue
from lineitem
where l_shipdate >= date '1994-01-01'
and l_shipdate < date '1994-01-01' + interval '1' year
and l_discount between 0.06 - 0.01 and 0.06 + 0.01
and l_quantity < 24;
revenue
77949.91860000002
set debug_sync='statistics_mem_alloc_start1 WAIT_FOR second_thread_started_too';
set debug_sync='statistics_mem_alloc_start2 SIGNAL first_thread_working';
use dbt3_s001;
set use_stat_tables='preferably';
select sum(l_extendedprice*l_discount) as revenue
from lineitem
where l_shipdate >= date '1994-01-01'
and l_shipdate < date '1994-01-01' + interval '1' year
and l_discount between 0.06 - 0.01 and 0.06 + 0.01
and l_quantity < 24 ;
set debug_sync='statistics_mem_alloc_start1 SIGNAL second_thread_started_too';
set debug_sync='statistics_mem_alloc_start2 WAIT_FOR first_thread_working';
use dbt3_s001;
set use_stat_tables='preferably';
select sum(l_extendedprice*l_discount) as revenue
from lineitem
where l_shipdate >= date '1994-01-01'
and l_shipdate < date '1994-01-01' + interval '1' year
and l_discount between 0.06 - 0.01 and 0.06 + 0.01
and l_quantity < 24;
revenue
77949.91860000002
revenue
77949.91860000002
set use_stat_tables='preferably';
set debug_sync='RESET';
select * from mysql.index_stat where table_name='lineitem' order by index_name;
db_name table_name index_name prefix_arity avg_frequency
dbt3_s001 lineitem PRIMARY 1 4.0033
dbt3_s001 lineitem PRIMARY 2 1.0000
dbt3_s001 lineitem i_l_commitdate 1 2.7160
dbt3_s001 lineitem i_l_orderkey 1 4.0033
dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033
dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404
dbt3_s001 lineitem i_l_partkey 1 30.0250
dbt3_s001 lineitem i_l_receiptdate 1 2.6477
dbt3_s001 lineitem i_l_shipdate 1 2.6500
dbt3_s001 lineitem i_l_suppkey 1 600.5000
dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250
dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786
delete from mysql.index_stat
where table_name='lineitem' and
index_name in ('i_l_shipdate', 'i_l_receiptdate');
select * from mysql.index_stat where table_name='lineitem' order by index_name;
db_name table_name index_name prefix_arity avg_frequency
dbt3_s001 lineitem PRIMARY 1 4.0033
dbt3_s001 lineitem PRIMARY 2 1.0000
dbt3_s001 lineitem i_l_commitdate 1 2.7160
dbt3_s001 lineitem i_l_orderkey 1 4.0033
dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033
dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404
dbt3_s001 lineitem i_l_partkey 1 30.0250
dbt3_s001 lineitem i_l_suppkey 1 600.5000
dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786
dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250
analyze table lineitem persistent for columns() indexes (i_l_shipdate);
select * from mysql.index_stat where table_name='lineitem' order by index_name;
db_name table_name index_name prefix_arity avg_frequency
dbt3_s001 lineitem PRIMARY 1 4.0033
dbt3_s001 lineitem PRIMARY 2 1.0000
dbt3_s001 lineitem i_l_commitdate 1 2.7160
dbt3_s001 lineitem i_l_orderkey 1 4.0033
dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033
dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404
dbt3_s001 lineitem i_l_partkey 1 30.0250
dbt3_s001 lineitem i_l_shipdate 1 2.6500
dbt3_s001 lineitem i_l_suppkey 1 600.5000
dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786
dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250
delete from mysql.index_stat
where table_name='lineitem' and index_name= 'i_l_shipdate';
select * from mysql.index_stat where table_name='lineitem' order by index_name;
db_name table_name index_name prefix_arity avg_frequency
dbt3_s001 lineitem PRIMARY 1 4.0033
dbt3_s001 lineitem PRIMARY 2 1.0000
dbt3_s001 lineitem i_l_commitdate 1 2.7160
dbt3_s001 lineitem i_l_orderkey 1 4.0033
dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033
dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404
dbt3_s001 lineitem i_l_partkey 1 30.0250
dbt3_s001 lineitem i_l_suppkey 1 600.5000
dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786
dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250
set debug_sync='statistics_collection_start1 WAIT_FOR second_thread_started_too';
set debug_sync='statistics_collection_start2 SIGNAL first_thread_working';
use dbt3_s001;
set use_stat_tables='preferably';
analyze table lineitem persistent for columns() indexes (i_l_shipdate);
set debug_sync='statistics_collection_start1 SIGNAL second_thread_started_too';
set debug_sync='statistics_collection_start2 WAIT_FOR first_thread_working';
use dbt3_s001;
set use_stat_tables='preferably';
analyze table lineitem persistent for columns() indexes (i_l_receiptdate);
set debug_sync='RESET';
select * from mysql.index_stat where table_name='lineitem' order by index_name;
db_name table_name index_name prefix_arity avg_frequency
dbt3_s001 lineitem PRIMARY 1 4.0033
dbt3_s001 lineitem PRIMARY 2 1.0000
dbt3_s001 lineitem i_l_commitdate 1 2.7160
dbt3_s001 lineitem i_l_orderkey 1 4.0033
dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033
dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404
dbt3_s001 lineitem i_l_partkey 1 30.0250
dbt3_s001 lineitem i_l_receiptdate 1 2.6477
dbt3_s001 lineitem i_l_shipdate 1 2.6500
dbt3_s001 lineitem i_l_suppkey 1 600.5000
dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250
dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786
DROP DATABASE dbt3_s001;
use test;
set use_stat_tables=@save_use_stat_tables;

View File

@ -0,0 +1,172 @@
SET SESSION STORAGE_ENGINE='InnoDB';
set @save_optimizer_switch_for_stat_tables_test=@@optimizer_switch;
set optimizer_switch='extended_keys=on';
set @save_use_stat_tables=@@use_stat_tables;
set use_stat_tables='preferably';
DROP DATABASE IF EXISTS dbt3_s001;
CREATE DATABASE dbt3_s001;
use dbt3_s001;
set @save_optimizer_switch=@@optimizer_switch;
set optimizer_switch='extended_keys=off';
select * from mysql.table_stat;
db_name table_name cardinality
dbt3_s001 customer 150
dbt3_s001 lineitem 6005
dbt3_s001 nation 25
dbt3_s001 orders 1500
dbt3_s001 part 200
dbt3_s001 partsupp 700
dbt3_s001 region 5
dbt3_s001 supplier 10
select * from mysql.index_stat;
db_name table_name index_name prefix_arity avg_frequency
dbt3_s001 customer PRIMARY 1 1.0000
dbt3_s001 customer i_c_nationkey 1 6.0000
dbt3_s001 lineitem PRIMARY 1 4.0033
dbt3_s001 lineitem PRIMARY 2 1.0000
dbt3_s001 lineitem i_l_shipdate 1 2.6500
dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250
dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786
dbt3_s001 lineitem i_l_partkey 1 30.0250
dbt3_s001 lineitem i_l_suppkey 1 600.5000
dbt3_s001 lineitem i_l_receiptdate 1 2.6477
dbt3_s001 lineitem i_l_orderkey 1 4.0033
dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033
dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404
dbt3_s001 lineitem i_l_commitdate 1 2.7160
dbt3_s001 nation PRIMARY 1 1.0000
dbt3_s001 nation i_n_regionkey 1 5.0000
dbt3_s001 orders PRIMARY 1 1.0000
dbt3_s001 orders i_o_orderdate 1 1.3321
dbt3_s001 orders i_o_custkey 1 15.0000
dbt3_s001 part PRIMARY 1 1.0000
dbt3_s001 partsupp PRIMARY 1 3.5000
dbt3_s001 partsupp PRIMARY 2 1.0000
dbt3_s001 partsupp i_ps_partkey 1 3.5000
dbt3_s001 partsupp i_ps_suppkey 1 70.0000
dbt3_s001 region PRIMARY 1 1.0000
dbt3_s001 supplier PRIMARY 1 1.0000
dbt3_s001 supplier i_s_nationkey 1 1.1111
flush table lineitem;
set use_stat_tables='never';
select sum(l_extendedprice*l_discount) as revenue
from lineitem
where l_shipdate >= date '1994-01-01'
and l_shipdate < date '1994-01-01' + interval '1' year
and l_discount between 0.06 - 0.01 and 0.06 + 0.01
and l_quantity < 24;
revenue
77949.91860000002
set debug_sync='statistics_mem_alloc_start1 WAIT_FOR second_thread_started_too';
set debug_sync='statistics_mem_alloc_start2 SIGNAL first_thread_working';
use dbt3_s001;
set use_stat_tables='preferably';
select sum(l_extendedprice*l_discount) as revenue
from lineitem
where l_shipdate >= date '1994-01-01'
and l_shipdate < date '1994-01-01' + interval '1' year
and l_discount between 0.06 - 0.01 and 0.06 + 0.01
and l_quantity < 24 ;
set debug_sync='statistics_mem_alloc_start1 SIGNAL second_thread_started_too';
set debug_sync='statistics_mem_alloc_start2 WAIT_FOR first_thread_working';
use dbt3_s001;
set use_stat_tables='preferably';
select sum(l_extendedprice*l_discount) as revenue
from lineitem
where l_shipdate >= date '1994-01-01'
and l_shipdate < date '1994-01-01' + interval '1' year
and l_discount between 0.06 - 0.01 and 0.06 + 0.01
and l_quantity < 24;
revenue
77949.91860000002
revenue
77949.91860000002
set use_stat_tables='preferably';
set debug_sync='RESET';
select * from mysql.index_stat where table_name='lineitem' order by index_name;
db_name table_name index_name prefix_arity avg_frequency
dbt3_s001 lineitem PRIMARY 1 4.0033
dbt3_s001 lineitem PRIMARY 2 1.0000
dbt3_s001 lineitem i_l_commitdate 1 2.7160
dbt3_s001 lineitem i_l_orderkey 1 4.0033
dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033
dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404
dbt3_s001 lineitem i_l_partkey 1 30.0250
dbt3_s001 lineitem i_l_receiptdate 1 2.6477
dbt3_s001 lineitem i_l_shipdate 1 2.6500
dbt3_s001 lineitem i_l_suppkey 1 600.5000
dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250
dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786
delete from mysql.index_stat
where table_name='lineitem' and
index_name in ('i_l_shipdate', 'i_l_receiptdate');
select * from mysql.index_stat where table_name='lineitem' order by index_name;
db_name table_name index_name prefix_arity avg_frequency
dbt3_s001 lineitem PRIMARY 1 4.0033
dbt3_s001 lineitem PRIMARY 2 1.0000
dbt3_s001 lineitem i_l_commitdate 1 2.7160
dbt3_s001 lineitem i_l_orderkey 1 4.0033
dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033
dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404
dbt3_s001 lineitem i_l_partkey 1 30.0250
dbt3_s001 lineitem i_l_suppkey 1 600.5000
dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786
dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250
analyze table lineitem persistent for columns() indexes (i_l_shipdate);
select * from mysql.index_stat where table_name='lineitem' order by index_name;
db_name table_name index_name prefix_arity avg_frequency
dbt3_s001 lineitem PRIMARY 1 4.0033
dbt3_s001 lineitem PRIMARY 2 1.0000
dbt3_s001 lineitem i_l_commitdate 1 2.7160
dbt3_s001 lineitem i_l_orderkey 1 4.0033
dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033
dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404
dbt3_s001 lineitem i_l_partkey 1 30.0250
dbt3_s001 lineitem i_l_shipdate 1 2.6500
dbt3_s001 lineitem i_l_suppkey 1 600.5000
dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786
dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250
delete from mysql.index_stat
where table_name='lineitem' and index_name= 'i_l_shipdate';
select * from mysql.index_stat where table_name='lineitem' order by index_name;
db_name table_name index_name prefix_arity avg_frequency
dbt3_s001 lineitem PRIMARY 1 4.0033
dbt3_s001 lineitem PRIMARY 2 1.0000
dbt3_s001 lineitem i_l_commitdate 1 2.7160
dbt3_s001 lineitem i_l_orderkey 1 4.0033
dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033
dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404
dbt3_s001 lineitem i_l_partkey 1 30.0250
dbt3_s001 lineitem i_l_suppkey 1 600.5000
dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786
dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250
set debug_sync='statistics_collection_start1 WAIT_FOR second_thread_started_too';
set debug_sync='statistics_collection_start2 SIGNAL first_thread_working';
use dbt3_s001;
set use_stat_tables='preferably';
analyze table lineitem persistent for columns() indexes (i_l_shipdate);
set debug_sync='statistics_collection_start1 SIGNAL second_thread_started_too';
set debug_sync='statistics_collection_start2 WAIT_FOR first_thread_working';
use dbt3_s001;
set use_stat_tables='preferably';
analyze table lineitem persistent for columns() indexes (i_l_receiptdate);
set debug_sync='RESET';
select * from mysql.index_stat where table_name='lineitem' order by index_name;
db_name table_name index_name prefix_arity avg_frequency
dbt3_s001 lineitem PRIMARY 1 4.0033
dbt3_s001 lineitem PRIMARY 2 1.0000
dbt3_s001 lineitem i_l_commitdate 1 2.7160
dbt3_s001 lineitem i_l_orderkey 1 4.0033
dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033
dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404
dbt3_s001 lineitem i_l_partkey 1 30.0250
dbt3_s001 lineitem i_l_receiptdate 1 2.6477
dbt3_s001 lineitem i_l_shipdate 1 2.6500
dbt3_s001 lineitem i_l_suppkey 1 600.5000
dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250
dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786
DROP DATABASE dbt3_s001;
use test;
set use_stat_tables=@save_use_stat_tables;
set optimizer_switch=@save_optimizer_switch_for_stat_tables_test;
SET SESSION STORAGE_ENGINE=DEFAULT;

View File

@ -0,0 +1,25 @@
#
# Bug mdev-463: assertion failure when running ANALYZE with RBR on
#
SET GLOBAL use_stat_tables = PREFERABLY;
CREATE TABLE t1 (i INT) ENGINE=InnoDB;
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
DROP TABLE t1;
SET GLOBAL use_stat_tables = DEFAULT;
SET use_stat_tables = PREFERABLY;
CREATE TABLE t1 ( a INT ) ENGINE=MyISAM PARTITION BY HASH(a) PARTITIONS 2;
ALTER TABLE t1 ANALYZE PARTITION p1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
SHOW BINLOG EVENTS;
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 4 Format_desc 1 245 Server ver: #, Binlog ver: #
master-bin.000001 245 Query 1 345 use `test`; CREATE TABLE t1 (i INT) ENGINE=InnoDB
master-bin.000001 345 Query 1 424 use `test`; ANALYZE TABLE t1
master-bin.000001 424 Query 1 528 use `test`; DROP TABLE `t1` /* generated by server */
master-bin.000001 528 Query 1 664 use `test`; CREATE TABLE t1 ( a INT ) ENGINE=MyISAM PARTITION BY HASH(a) PARTITIONS 2
master-bin.000001 664 Query 1 762 use `test`; ALTER TABLE t1 ANALYZE PARTITION p1
SET use_stat_tables = DEFAULT;
DROP TABLE t1;

View File

@ -0,0 +1,41 @@
include/master-slave.inc
[connection master]
#
# Bug mdev-485: unexpected failure with replication of DROP/ALTER table
# when RBR is on
#
CREATE TABLE t1 ( a int, b int ) ENGINE=MyISAM;
INSERT INTO t1 VALUES (2,20), (1,20), (3,30);
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
DROP TABLE t1;
CREATE TABLE t1 ( a int, b int, INDEX idx1(b) ) ENGINE=MyISAM;
INSERT INTO t1 VALUES (2,20), (1,20), (3,30);
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
DROP INDEX idx1 ON t1;
DROP TABLE t1;
CREATE TABLE t1 ( a int, b int, INDEX idx1(b) ) ENGINE=MyISAM;
INSERT INTO t1 VALUES (2,20), (1,20), (3,30);
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
ALTER TABLE t1 DROP COLUMN b;
DROP TABLE t1;
CREATE TABLE t1 ( a int, b int, INDEX idx1(b) ) ENGINE=MyISAM;
INSERT INTO t1 VALUES (2,20), (1,20), (3,30);
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
ALTER TABLE t1 RENAME to s;
DROP TABLE s;
CREATE TABLE t1 ( a int, b int, INDEX idx1(b) ) ENGINE=MyISAM;
INSERT INTO t1 VALUES (2,20), (1,20), (3,30);
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
ALTER TABLE t1 CHANGE COLUMN b c int ;
DROP TABLE t1;
include/rpl_end.inc

File diff suppressed because it is too large Load Diff

View File

@ -107,7 +107,7 @@ Handler_mrr_key_refills 0
Handler_mrr_rowid_refills 0
Handler_prepare 18
Handler_read_first 0
Handler_read_key 3
Handler_read_key 9
Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
@ -123,7 +123,7 @@ Handler_update 5
Handler_write 7
select variable_value - @global_read_key as "handler_read_key" from information_schema.global_status where variable_name="handler_read_key";
handler_read_key
3
9
set @@global.userstat=0;
select * from information_schema.index_statistics;
TABLE_SCHEMA TABLE_NAME INDEX_NAME ROWS_READ

View File

@ -1,5 +1,6 @@
show tables;
Tables_in_db
column_stat
columns_priv
db
event
@ -10,6 +11,7 @@ help_keyword
help_relation
help_topic
host
index_stat
ndb_binlog_index
plugin
proc
@ -17,6 +19,7 @@ procs_priv
proxies_priv
servers
slow_log
table_stat
tables_priv
time_zone
time_zone_leap_second
@ -264,5 +267,36 @@ slow_log CREATE TABLE `slow_log` (
`server_id` int(10) unsigned NOT NULL,
`sql_text` mediumtext NOT NULL
) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='Slow log'
show create table table_stat;
Table Create Table
table_stat CREATE TABLE `table_stat` (
`db_name` varchar(64) COLLATE utf8_bin NOT NULL,
`table_name` varchar(64) COLLATE utf8_bin NOT NULL,
`cardinality` bigint(21) unsigned DEFAULT NULL,
PRIMARY KEY (`db_name`,`table_name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Statistics on Tables'
show create table column_stat;
Table Create Table
column_stat CREATE TABLE `column_stat` (
`db_name` varchar(64) COLLATE utf8_bin NOT NULL,
`table_name` varchar(64) COLLATE utf8_bin NOT NULL,
`column_name` varchar(64) COLLATE utf8_bin NOT NULL,
`min_value` varchar(255) COLLATE utf8_bin DEFAULT NULL,
`max_value` varchar(255) COLLATE utf8_bin DEFAULT NULL,
`nulls_ratio` decimal(12,4) DEFAULT NULL,
`avg_length` decimal(12,4) DEFAULT NULL,
`avg_frequency` decimal(12,4) DEFAULT NULL,
PRIMARY KEY (`db_name`,`table_name`,`column_name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Statistics on Columns'
show create table index_stat;
Table Create Table
index_stat CREATE TABLE `index_stat` (
`db_name` varchar(64) COLLATE utf8_bin NOT NULL,
`table_name` varchar(64) COLLATE utf8_bin NOT NULL,
`index_name` varchar(64) COLLATE utf8_bin NOT NULL,
`prefix_arity` int(11) unsigned NOT NULL,
`avg_frequency` decimal(12,4) DEFAULT NULL,
PRIMARY KEY (`db_name`,`table_name`,`index_name`,`prefix_arity`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Statistics on Indexes'
show tables;
Tables_in_test

View File

@ -1,5 +1,6 @@
show tables;
Tables_in_db
column_stat
columns_priv
db
event
@ -10,6 +11,7 @@ help_keyword
help_relation
help_topic
host
index_stat
ndb_binlog_index
plugin
proc
@ -17,6 +19,7 @@ procs_priv
proxies_priv
servers
slow_log
table_stat
tables_priv
time_zone
time_zone_leap_second
@ -264,5 +267,36 @@ slow_log CREATE TABLE `slow_log` (
`server_id` int(10) unsigned NOT NULL,
`sql_text` mediumtext NOT NULL
) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='Slow log'
show create table table_stat;
Table Create Table
table_stat CREATE TABLE `table_stat` (
`db_name` varchar(64) COLLATE utf8_bin NOT NULL,
`table_name` varchar(64) COLLATE utf8_bin NOT NULL,
`cardinality` bigint(21) unsigned DEFAULT NULL,
PRIMARY KEY (`db_name`,`table_name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Statistics on Tables'
show create table column_stat;
Table Create Table
column_stat CREATE TABLE `column_stat` (
`db_name` varchar(64) COLLATE utf8_bin NOT NULL,
`table_name` varchar(64) COLLATE utf8_bin NOT NULL,
`column_name` varchar(64) COLLATE utf8_bin NOT NULL,
`min_value` varchar(255) COLLATE utf8_bin DEFAULT NULL,
`max_value` varchar(255) COLLATE utf8_bin DEFAULT NULL,
`nulls_ratio` double DEFAULT NULL,
`avg_length` double DEFAULT NULL,
`avg_frequency` double DEFAULT NULL,
PRIMARY KEY (`db_name`,`table_name`,`column_name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Statistics on Columns'
show create table index_stat;
Table Create Table
index_stat CREATE TABLE `index_stat` (
`db_name` varchar(64) COLLATE utf8_bin NOT NULL,
`table_name` varchar(64) COLLATE utf8_bin NOT NULL,
`index_name` varchar(64) COLLATE utf8_bin NOT NULL,
`prefix_arity` int(11) unsigned NOT NULL,
`avg_frequency` double DEFAULT NULL,
PRIMARY KEY (`db_name`,`table_name`,`index_name`,`prefix_arity`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Statistics on Indexes'
show tables;
Tables_in_test

View File

@ -1,5 +1,6 @@
show tables;
Tables_in_db
column_stat
columns_priv
db
event
@ -10,6 +11,7 @@ help_keyword
help_relation
help_topic
host
index_stat
ndb_binlog_index
plugin
proc
@ -17,6 +19,7 @@ procs_priv
proxies_priv
servers
slow_log
table_stat
tables_priv
time_zone
time_zone_leap_second
@ -264,5 +267,36 @@ slow_log CREATE TABLE `slow_log` (
`server_id` int(10) unsigned NOT NULL,
`sql_text` mediumtext NOT NULL
) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='Slow log'
show create table table_stat;
Table Create Table
table_stat CREATE TABLE `table_stat` (
`db_name` varchar(64) COLLATE utf8_bin NOT NULL,
`table_name` varchar(64) COLLATE utf8_bin NOT NULL,
`cardinality` bigint(21) unsigned DEFAULT NULL,
PRIMARY KEY (`db_name`,`table_name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Statistics on Tables'
show create table column_stat;
Table Create Table
column_stat CREATE TABLE `column_stat` (
`db_name` varchar(64) COLLATE utf8_bin NOT NULL,
`table_name` varchar(64) COLLATE utf8_bin NOT NULL,
`column_name` varchar(64) COLLATE utf8_bin NOT NULL,
`min_value` varchar(255) COLLATE utf8_bin DEFAULT NULL,
`max_value` varchar(255) COLLATE utf8_bin DEFAULT NULL,
`nulls_ratio` double DEFAULT NULL,
`avg_length` double DEFAULT NULL,
`avg_frequency` double DEFAULT NULL,
PRIMARY KEY (`db_name`,`table_name`,`column_name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Statistics on Columns'
show create table index_stat;
Table Create Table
index_stat CREATE TABLE `index_stat` (
`db_name` varchar(64) COLLATE utf8_bin NOT NULL,
`table_name` varchar(64) COLLATE utf8_bin NOT NULL,
`index_name` varchar(64) COLLATE utf8_bin NOT NULL,
`prefix_arity` int(11) unsigned NOT NULL,
`avg_frequency` double DEFAULT NULL,
PRIMARY KEY (`db_name`,`table_name`,`index_name`,`prefix_arity`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Statistics on Indexes'
show tables;
Tables_in_test

View File

@ -1,5 +1,6 @@
show tables;
Tables_in_db
column_stat
columns_priv
db
event
@ -10,6 +11,7 @@ help_keyword
help_relation
help_topic
host
index_stat
ndb_binlog_index
plugin
proc
@ -17,6 +19,7 @@ procs_priv
proxies_priv
servers
slow_log
table_stat
tables_priv
time_zone
time_zone_leap_second
@ -264,5 +267,36 @@ slow_log CREATE TABLE `slow_log` (
`server_id` int(10) unsigned NOT NULL,
`sql_text` mediumtext NOT NULL
) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='Slow log'
show create table table_stat;
Table Create Table
table_stat CREATE TABLE `table_stat` (
`db_name` varchar(64) COLLATE utf8_bin NOT NULL,
`table_name` varchar(64) COLLATE utf8_bin NOT NULL,
`cardinality` bigint(21) unsigned DEFAULT NULL,
PRIMARY KEY (`db_name`,`table_name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Statistics on Tables'
show create table column_stat;
Table Create Table
column_stat CREATE TABLE `column_stat` (
`db_name` varchar(64) COLLATE utf8_bin NOT NULL,
`table_name` varchar(64) COLLATE utf8_bin NOT NULL,
`column_name` varchar(64) COLLATE utf8_bin NOT NULL,
`min_value` varchar(255) COLLATE utf8_bin DEFAULT NULL,
`max_value` varchar(255) COLLATE utf8_bin DEFAULT NULL,
`nulls_ratio` double DEFAULT NULL,
`avg_length` double DEFAULT NULL,
`avg_frequency` double DEFAULT NULL,
PRIMARY KEY (`db_name`,`table_name`,`column_name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Statistics on Columns'
show create table index_stat;
Table Create Table
index_stat CREATE TABLE `index_stat` (
`db_name` varchar(64) COLLATE utf8_bin NOT NULL,
`table_name` varchar(64) COLLATE utf8_bin NOT NULL,
`index_name` varchar(64) COLLATE utf8_bin NOT NULL,
`prefix_arity` int(11) unsigned NOT NULL,
`avg_frequency` double DEFAULT NULL,
PRIMARY KEY (`db_name`,`table_name`,`index_name`,`prefix_arity`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Statistics on Indexes'
show tables;
Tables_in_test

View File

@ -9,6 +9,14 @@ def mysql columns_priv Host 1 NO char 60 180 NULL NULL NULL utf8 utf8_bin char(
def mysql columns_priv Table_name 4 NO char 64 192 NULL NULL NULL utf8 utf8_bin char(64) PRI select,insert,update,references
def mysql columns_priv Timestamp 6 CURRENT_TIMESTAMP NO timestamp NULL NULL NULL NULL 0 NULL NULL timestamp on update CURRENT_TIMESTAMP select,insert,update,references
def mysql columns_priv User 3 NO char 16 48 NULL NULL NULL utf8 utf8_bin char(16) PRI select,insert,update,references
def mysql column_stat avg_frequency 8 NULL YES decimal NULL NULL 12 4 NULL NULL NULL decimal(12,4) select,insert,update,references
def mysql column_stat avg_length 7 NULL YES decimal NULL NULL 12 4 NULL NULL NULL decimal(12,4) select,insert,update,references
def mysql column_stat column_name 3 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI select,insert,update,references
def mysql column_stat db_name 1 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI select,insert,update,references
def mysql column_stat max_value 5 NULL YES varchar 255 765 NULL NULL NULL utf8 utf8_bin varchar(255) select,insert,update,references
def mysql column_stat min_value 4 NULL YES varchar 255 765 NULL NULL NULL utf8 utf8_bin varchar(255) select,insert,update,references
def mysql column_stat nulls_ratio 6 NULL YES decimal NULL NULL 12 4 NULL NULL NULL decimal(12,4) select,insert,update,references
def mysql column_stat table_name 2 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI select,insert,update,references
def mysql db Alter_priv 13 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci enum('N','Y') select,insert,update,references
def mysql db Alter_routine_priv 19 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci enum('N','Y') select,insert,update,references
def mysql db Create_priv 8 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci enum('N','Y') select,insert,update,references
@ -97,6 +105,11 @@ def mysql host Select_priv 3 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci e
def mysql host Show_view_priv 16 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci enum('N','Y') select,insert,update,references
def mysql host Trigger_priv 20 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci enum('N','Y') select,insert,update,references
def mysql host Update_priv 5 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci enum('N','Y') select,insert,update,references
def mysql index_stat avg_frequency 5 NULL YES decimal NULL NULL 12 4 NULL NULL NULL decimal(12,4) select,insert,update,references
def mysql index_stat db_name 1 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI select,insert,update,references
def mysql index_stat index_name 3 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI select,insert,update,references
def mysql index_stat prefix_arity 4 NULL NO int NULL NULL 10 0 NULL NULL NULL int(11) unsigned PRI select,insert,update,references
def mysql index_stat table_name 2 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI select,insert,update,references
def mysql ndb_binlog_index deletes 6 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references
def mysql ndb_binlog_index epoch 3 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned PRI select,insert,update,references
def mysql ndb_binlog_index File 2 NULL NO varchar 255 255 NULL NULL NULL latin1 latin1_swedish_ci varchar(255) select,insert,update,references
@ -169,6 +182,9 @@ def mysql tables_priv Table_name 4 NO char 64 192 NULL NULL NULL utf8 utf8_bin
def mysql tables_priv Table_priv 7 NO set 98 294 NULL NULL NULL utf8 utf8_general_ci set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter','Create View','Show view','Trigger') select,insert,update,references
def mysql tables_priv Timestamp 6 CURRENT_TIMESTAMP NO timestamp NULL NULL NULL NULL 0 NULL NULL timestamp on update CURRENT_TIMESTAMP select,insert,update,references
def mysql tables_priv User 3 NO char 16 48 NULL NULL NULL utf8 utf8_bin char(16) PRI select,insert,update,references
def mysql table_stat cardinality 3 NULL YES bigint NULL NULL 20 0 NULL NULL NULL bigint(21) unsigned select,insert,update,references
def mysql table_stat db_name 1 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI select,insert,update,references
def mysql table_stat table_name 2 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI select,insert,update,references
def mysql time_zone Time_zone_id 1 NULL NO int NULL NULL 10 0 NULL NULL NULL int(10) unsigned PRI auto_increment select,insert,update,references
def mysql time_zone Use_leap_seconds 2 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci enum('Y','N') select,insert,update,references
def mysql time_zone_leap_second Correction 2 NULL NO int NULL NULL 10 0 NULL NULL NULL int(11) select,insert,update,references
@ -258,6 +274,7 @@ ORDER BY CHARACTER_SET_NAME, COLLATION_NAME, COL_CML;
COL_CML DATA_TYPE CHARACTER_SET_NAME COLLATION_NAME
3.0000 char utf8 utf8_bin
3.0000 enum utf8 utf8_bin
3.0000 varchar utf8 utf8_bin
3.0000 char utf8 utf8_general_ci
3.0000 enum utf8 utf8_general_ci
3.0000 set utf8 utf8_general_ci
@ -274,6 +291,7 @@ ORDER BY CHARACTER_SET_NAME, COLLATION_NAME, COL_CML;
COL_CML DATA_TYPE CHARACTER_SET_NAME COLLATION_NAME
NULL bigint NULL NULL
NULL datetime NULL NULL
NULL decimal NULL NULL
NULL int NULL NULL
NULL smallint NULL NULL
NULL time NULL NULL
@ -302,6 +320,14 @@ COL_CML TABLE_SCHEMA TABLE_NAME COLUMN_NAME DATA_TYPE CHARACTER_MAXIMUM_LENGTH C
3.0000 mysql columns_priv Column_name char 64 192 utf8 utf8_bin char(64)
NULL mysql columns_priv Timestamp timestamp NULL NULL NULL NULL timestamp
3.0000 mysql columns_priv Column_priv set 31 93 utf8 utf8_general_ci set('Select','Insert','Update','References')
3.0000 mysql column_stat db_name varchar 64 192 utf8 utf8_bin varchar(64)
3.0000 mysql column_stat table_name varchar 64 192 utf8 utf8_bin varchar(64)
3.0000 mysql column_stat column_name varchar 64 192 utf8 utf8_bin varchar(64)
3.0000 mysql column_stat min_value varchar 255 765 utf8 utf8_bin varchar(255)
3.0000 mysql column_stat max_value varchar 255 765 utf8 utf8_bin varchar(255)
NULL mysql column_stat nulls_ratio decimal NULL NULL NULL NULL decimal(12,4)
NULL mysql column_stat avg_length decimal NULL NULL NULL NULL decimal(12,4)
NULL mysql column_stat avg_frequency decimal NULL NULL NULL NULL decimal(12,4)
3.0000 mysql db Host char 60 180 utf8 utf8_bin char(60)
3.0000 mysql db Db char 64 192 utf8 utf8_bin char(64)
3.0000 mysql db User char 16 48 utf8 utf8_bin char(16)
@ -390,6 +416,11 @@ NULL mysql help_topic help_category_id smallint NULL NULL NULL NULL smallint(5)
3.0000 mysql host Alter_routine_priv enum 1 3 utf8 utf8_general_ci enum('N','Y')
3.0000 mysql host Execute_priv enum 1 3 utf8 utf8_general_ci enum('N','Y')
3.0000 mysql host Trigger_priv enum 1 3 utf8 utf8_general_ci enum('N','Y')
3.0000 mysql index_stat db_name varchar 64 192 utf8 utf8_bin varchar(64)
3.0000 mysql index_stat table_name varchar 64 192 utf8 utf8_bin varchar(64)
3.0000 mysql index_stat index_name varchar 64 192 utf8 utf8_bin varchar(64)
NULL mysql index_stat prefix_arity int NULL NULL NULL NULL int(11) unsigned
NULL mysql index_stat avg_frequency decimal NULL NULL NULL NULL decimal(12,4)
NULL mysql ndb_binlog_index Position bigint NULL NULL NULL NULL bigint(20) unsigned
1.0000 mysql ndb_binlog_index File varchar 255 255 latin1 latin1_swedish_ci varchar(255)
NULL mysql ndb_binlog_index epoch bigint NULL NULL NULL NULL bigint(20) unsigned
@ -462,6 +493,9 @@ NULL mysql slow_log server_id int NULL NULL NULL NULL int(10) unsigned
NULL mysql tables_priv Timestamp timestamp NULL NULL NULL NULL timestamp
3.0000 mysql tables_priv Table_priv set 98 294 utf8 utf8_general_ci set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter','Create View','Show view','Trigger')
3.0000 mysql tables_priv Column_priv set 31 93 utf8 utf8_general_ci set('Select','Insert','Update','References')
3.0000 mysql table_stat db_name varchar 64 192 utf8 utf8_bin varchar(64)
3.0000 mysql table_stat table_name varchar 64 192 utf8 utf8_bin varchar(64)
NULL mysql table_stat cardinality bigint NULL NULL NULL NULL bigint(21) unsigned
NULL mysql time_zone Time_zone_id int NULL NULL NULL NULL int(10) unsigned
3.0000 mysql time_zone Use_leap_seconds enum 1 3 utf8 utf8_general_ci enum('Y','N')
NULL mysql time_zone_leap_second Transition_time bigint NULL NULL NULL NULL bigint(20)

View File

@ -9,6 +9,14 @@ def mysql columns_priv Host 1 NO char 60 180 NULL NULL NULL utf8 utf8_bin char(
def mysql columns_priv Table_name 4 NO char 64 192 NULL NULL NULL utf8 utf8_bin char(64) PRI
def mysql columns_priv Timestamp 6 CURRENT_TIMESTAMP NO timestamp NULL NULL NULL NULL 0 NULL NULL timestamp on update CURRENT_TIMESTAMP
def mysql columns_priv User 3 NO char 16 48 NULL NULL NULL utf8 utf8_bin char(16) PRI
def mysql column_stat avg_frequency 8 NULL YES decimal NULL NULL 12 4 NULL NULL NULL decimal(12,4)
def mysql column_stat avg_length 7 NULL YES decimal NULL NULL 12 4 NULL NULL NULL decimal(12,4)
def mysql column_stat column_name 3 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI
def mysql column_stat db_name 1 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI
def mysql column_stat max_value 5 NULL YES varchar 255 765 NULL NULL NULL utf8 utf8_bin varchar(255)
def mysql column_stat min_value 4 NULL YES varchar 255 765 NULL NULL NULL utf8 utf8_bin varchar(255)
def mysql column_stat nulls_ratio 6 NULL YES decimal NULL NULL 12 4 NULL NULL NULL decimal(12,4)
def mysql column_stat table_name 2 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI
def mysql db Alter_priv 13 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci enum('N','Y')
def mysql db Alter_routine_priv 19 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci enum('N','Y')
def mysql db Create_priv 8 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci enum('N','Y')
@ -97,6 +105,11 @@ def mysql host Select_priv 3 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci e
def mysql host Show_view_priv 16 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci enum('N','Y')
def mysql host Trigger_priv 20 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci enum('N','Y')
def mysql host Update_priv 5 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci enum('N','Y')
def mysql index_stat avg_frequency 5 NULL YES decimal NULL NULL 12 4 NULL NULL NULL decimal(12,4)
def mysql index_stat db_name 1 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI
def mysql index_stat index_name 3 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI
def mysql index_stat prefix_arity 4 NULL NO int NULL NULL 10 0 NULL NULL NULL int(11) unsigned PRI
def mysql index_stat table_name 2 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI
def mysql ndb_binlog_index deletes 6 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned
def mysql ndb_binlog_index epoch 3 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned PRI
def mysql ndb_binlog_index File 2 NULL NO varchar 255 255 NULL NULL NULL latin1 latin1_swedish_ci varchar(255)
@ -169,6 +182,9 @@ def mysql tables_priv Table_name 4 NO char 64 192 NULL NULL NULL utf8 utf8_bin
def mysql tables_priv Table_priv 7 NO set 98 294 NULL NULL NULL utf8 utf8_general_ci set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter','Create View','Show view','Trigger')
def mysql tables_priv Timestamp 6 CURRENT_TIMESTAMP NO timestamp NULL NULL NULL NULL 0 NULL NULL timestamp on update CURRENT_TIMESTAMP
def mysql tables_priv User 3 NO char 16 48 NULL NULL NULL utf8 utf8_bin char(16) PRI
def mysql table_stat cardinality 3 NULL YES bigint NULL NULL 20 0 NULL NULL NULL bigint(21) unsigned
def mysql table_stat db_name 1 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI
def mysql table_stat table_name 2 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI
def mysql time_zone Time_zone_id 1 NULL NO int NULL NULL 10 0 NULL NULL NULL int(10) unsigned PRI auto_increment
def mysql time_zone Use_leap_seconds 2 N NO enum 1 3 NULL NULL NULL utf8 utf8_general_ci enum('Y','N')
def mysql time_zone_leap_second Correction 2 NULL NO int NULL NULL 10 0 NULL NULL NULL int(11)
@ -258,6 +274,7 @@ ORDER BY CHARACTER_SET_NAME, COLLATION_NAME, COL_CML;
COL_CML DATA_TYPE CHARACTER_SET_NAME COLLATION_NAME
3.0000 char utf8 utf8_bin
3.0000 enum utf8 utf8_bin
3.0000 varchar utf8 utf8_bin
3.0000 char utf8 utf8_general_ci
3.0000 enum utf8 utf8_general_ci
3.0000 set utf8 utf8_general_ci
@ -274,6 +291,7 @@ ORDER BY CHARACTER_SET_NAME, COLLATION_NAME, COL_CML;
COL_CML DATA_TYPE CHARACTER_SET_NAME COLLATION_NAME
NULL bigint NULL NULL
NULL datetime NULL NULL
NULL decimal NULL NULL
NULL int NULL NULL
NULL smallint NULL NULL
NULL time NULL NULL
@ -302,6 +320,14 @@ COL_CML TABLE_SCHEMA TABLE_NAME COLUMN_NAME DATA_TYPE CHARACTER_MAXIMUM_LENGTH C
3.0000 mysql columns_priv Column_name char 64 192 utf8 utf8_bin char(64)
NULL mysql columns_priv Timestamp timestamp NULL NULL NULL NULL timestamp
3.0000 mysql columns_priv Column_priv set 31 93 utf8 utf8_general_ci set('Select','Insert','Update','References')
3.0000 mysql column_stat db_name varchar 64 192 utf8 utf8_bin varchar(64)
3.0000 mysql column_stat table_name varchar 64 192 utf8 utf8_bin varchar(64)
3.0000 mysql column_stat column_name varchar 64 192 utf8 utf8_bin varchar(64)
3.0000 mysql column_stat min_value varchar 255 765 utf8 utf8_bin varchar(255)
3.0000 mysql column_stat max_value varchar 255 765 utf8 utf8_bin varchar(255)
NULL mysql column_stat nulls_ratio decimal NULL NULL NULL NULL decimal(12,4)
NULL mysql column_stat avg_length decimal NULL NULL NULL NULL decimal(12,4)
NULL mysql column_stat avg_frequency decimal NULL NULL NULL NULL decimal(12,4)
3.0000 mysql db Host char 60 180 utf8 utf8_bin char(60)
3.0000 mysql db Db char 64 192 utf8 utf8_bin char(64)
3.0000 mysql db User char 16 48 utf8 utf8_bin char(16)
@ -390,6 +416,11 @@ NULL mysql help_topic help_category_id smallint NULL NULL NULL NULL smallint(5)
3.0000 mysql host Alter_routine_priv enum 1 3 utf8 utf8_general_ci enum('N','Y')
3.0000 mysql host Execute_priv enum 1 3 utf8 utf8_general_ci enum('N','Y')
3.0000 mysql host Trigger_priv enum 1 3 utf8 utf8_general_ci enum('N','Y')
3.0000 mysql index_stat db_name varchar 64 192 utf8 utf8_bin varchar(64)
3.0000 mysql index_stat table_name varchar 64 192 utf8 utf8_bin varchar(64)
3.0000 mysql index_stat index_name varchar 64 192 utf8 utf8_bin varchar(64)
NULL mysql index_stat prefix_arity int NULL NULL NULL NULL int(11) unsigned
NULL mysql index_stat avg_frequency decimal NULL NULL NULL NULL decimal(12,4)
NULL mysql ndb_binlog_index Position bigint NULL NULL NULL NULL bigint(20) unsigned
1.0000 mysql ndb_binlog_index File varchar 255 255 latin1 latin1_swedish_ci varchar(255)
NULL mysql ndb_binlog_index epoch bigint NULL NULL NULL NULL bigint(20) unsigned
@ -462,6 +493,9 @@ NULL mysql slow_log server_id int NULL NULL NULL NULL int(10) unsigned
NULL mysql tables_priv Timestamp timestamp NULL NULL NULL NULL timestamp
3.0000 mysql tables_priv Table_priv set 98 294 utf8 utf8_general_ci set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter','Create View','Show view','Trigger')
3.0000 mysql tables_priv Column_priv set 31 93 utf8 utf8_general_ci set('Select','Insert','Update','References')
3.0000 mysql table_stat db_name varchar 64 192 utf8 utf8_bin varchar(64)
3.0000 mysql table_stat table_name varchar 64 192 utf8 utf8_bin varchar(64)
NULL mysql table_stat cardinality bigint NULL NULL NULL NULL bigint(21) unsigned
NULL mysql time_zone Time_zone_id int NULL NULL NULL NULL int(10) unsigned
3.0000 mysql time_zone Use_leap_seconds enum 1 3 utf8 utf8_general_ci enum('Y','N')
NULL mysql time_zone_leap_second Transition_time bigint NULL NULL NULL NULL bigint(20)

View File

@ -75,6 +75,9 @@ table_schema, table_name, column_name
FROM information_schema.key_column_usage
WHERE constraint_catalog IS NOT NULL OR table_catalog IS NOT NULL;
constraint_catalog constraint_schema constraint_name table_catalog table_schema table_name column_name
def mysql PRIMARY def mysql column_stat db_name
def mysql PRIMARY def mysql column_stat table_name
def mysql PRIMARY def mysql column_stat column_name
def mysql PRIMARY def mysql columns_priv Host
def mysql PRIMARY def mysql columns_priv Db
def mysql PRIMARY def mysql columns_priv User
@ -96,6 +99,10 @@ def mysql PRIMARY def mysql help_topic help_topic_id
def mysql name def mysql help_topic name
def mysql PRIMARY def mysql host Host
def mysql PRIMARY def mysql host Db
def mysql PRIMARY def mysql index_stat db_name
def mysql PRIMARY def mysql index_stat table_name
def mysql PRIMARY def mysql index_stat index_name
def mysql PRIMARY def mysql index_stat prefix_arity
def mysql PRIMARY def mysql ndb_binlog_index epoch
def mysql PRIMARY def mysql plugin name
def mysql PRIMARY def mysql proc db
@ -111,6 +118,8 @@ def mysql PRIMARY def mysql proxies_priv User
def mysql PRIMARY def mysql proxies_priv Proxied_host
def mysql PRIMARY def mysql proxies_priv Proxied_user
def mysql PRIMARY def mysql servers Server_name
def mysql PRIMARY def mysql table_stat db_name
def mysql PRIMARY def mysql table_stat table_name
def mysql PRIMARY def mysql tables_priv Host
def mysql PRIMARY def mysql tables_priv Db
def mysql PRIMARY def mysql tables_priv User

View File

@ -85,6 +85,9 @@ INDEX_COMMENT varchar(1024) NO
SELECT table_catalog, table_schema, table_name, index_schema, index_name
FROM information_schema.statistics WHERE table_catalog IS NOT NULL;
table_catalog table_schema table_name index_schema index_name
def mysql column_stat mysql PRIMARY
def mysql column_stat mysql PRIMARY
def mysql column_stat mysql PRIMARY
def mysql columns_priv mysql PRIMARY
def mysql columns_priv mysql PRIMARY
def mysql columns_priv mysql PRIMARY
@ -107,6 +110,10 @@ def mysql help_topic mysql PRIMARY
def mysql help_topic mysql name
def mysql host mysql PRIMARY
def mysql host mysql PRIMARY
def mysql index_stat mysql PRIMARY
def mysql index_stat mysql PRIMARY
def mysql index_stat mysql PRIMARY
def mysql index_stat mysql PRIMARY
def mysql ndb_binlog_index mysql PRIMARY
def mysql plugin mysql PRIMARY
def mysql proc mysql PRIMARY
@ -124,6 +131,8 @@ def mysql proxies_priv mysql PRIMARY
def mysql proxies_priv mysql PRIMARY
def mysql proxies_priv mysql Grantor
def mysql servers mysql PRIMARY
def mysql table_stat mysql PRIMARY
def mysql table_stat mysql PRIMARY
def mysql tables_priv mysql PRIMARY
def mysql tables_priv mysql PRIMARY
def mysql tables_priv mysql PRIMARY

View File

@ -12,6 +12,9 @@ def mysql columns_priv 0 mysql PRIMARY 2 Db A #CARD# NULL NULL BTREE
def mysql columns_priv 0 mysql PRIMARY 3 User A #CARD# NULL NULL BTREE
def mysql columns_priv 0 mysql PRIMARY 4 Table_name A #CARD# NULL NULL BTREE
def mysql columns_priv 0 mysql PRIMARY 5 Column_name A #CARD# NULL NULL BTREE
def mysql column_stat 0 mysql PRIMARY 1 db_name A #CARD# NULL NULL BTREE
def mysql column_stat 0 mysql PRIMARY 2 table_name A #CARD# NULL NULL BTREE
def mysql column_stat 0 mysql PRIMARY 3 column_name A #CARD# NULL NULL BTREE
def mysql db 0 mysql PRIMARY 1 Host A #CARD# NULL NULL BTREE
def mysql db 0 mysql PRIMARY 2 Db A #CARD# NULL NULL BTREE
def mysql db 0 mysql PRIMARY 3 User A #CARD# NULL NULL BTREE
@ -29,6 +32,10 @@ def mysql help_topic 0 mysql name 1 name A #CARD# NULL NULL BTREE
def mysql help_topic 0 mysql PRIMARY 1 help_topic_id A #CARD# NULL NULL BTREE
def mysql host 0 mysql PRIMARY 1 Host A #CARD# NULL NULL BTREE
def mysql host 0 mysql PRIMARY 2 Db A #CARD# NULL NULL BTREE
def mysql index_stat 0 mysql PRIMARY 1 db_name A #CARD# NULL NULL BTREE
def mysql index_stat 0 mysql PRIMARY 2 table_name A #CARD# NULL NULL BTREE
def mysql index_stat 0 mysql PRIMARY 3 index_name A #CARD# NULL NULL BTREE
def mysql index_stat 0 mysql PRIMARY 4 prefix_arity A #CARD# NULL NULL BTREE
def mysql ndb_binlog_index 0 mysql PRIMARY 1 epoch A #CARD# NULL NULL BTREE
def mysql plugin 0 mysql PRIMARY 1 name A #CARD# NULL NULL BTREE
def mysql proc 0 mysql PRIMARY 1 db A #CARD# NULL NULL BTREE
@ -51,6 +58,8 @@ def mysql tables_priv 0 mysql PRIMARY 1 Host A #CARD# NULL NULL BTREE
def mysql tables_priv 0 mysql PRIMARY 2 Db A #CARD# NULL NULL BTREE
def mysql tables_priv 0 mysql PRIMARY 3 User A #CARD# NULL NULL BTREE
def mysql tables_priv 0 mysql PRIMARY 4 Table_name A #CARD# NULL NULL BTREE
def mysql table_stat 0 mysql PRIMARY 1 db_name A #CARD# NULL NULL BTREE
def mysql table_stat 0 mysql PRIMARY 2 table_name A #CARD# NULL NULL BTREE
def mysql time_zone 0 mysql PRIMARY 1 Time_zone_id A #CARD# NULL NULL BTREE
def mysql time_zone_leap_second 0 mysql PRIMARY 1 Transition_time A #CARD# NULL NULL BTREE
def mysql time_zone_name 0 mysql PRIMARY 1 Name A #CARD# NULL NULL BTREE

View File

@ -12,6 +12,9 @@ def mysql columns_priv 0 mysql PRIMARY 2 Db A #CARD# NULL NULL BTREE
def mysql columns_priv 0 mysql PRIMARY 3 User A #CARD# NULL NULL BTREE
def mysql columns_priv 0 mysql PRIMARY 4 Table_name A #CARD# NULL NULL BTREE
def mysql columns_priv 0 mysql PRIMARY 5 Column_name A #CARD# NULL NULL BTREE
def mysql column_stat 0 mysql PRIMARY 1 db_name A #CARD# NULL NULL BTREE
def mysql column_stat 0 mysql PRIMARY 2 table_name A #CARD# NULL NULL BTREE
def mysql column_stat 0 mysql PRIMARY 3 column_name A #CARD# NULL NULL BTREE
def mysql db 0 mysql PRIMARY 1 Host A #CARD# NULL NULL BTREE
def mysql db 0 mysql PRIMARY 2 Db A #CARD# NULL NULL BTREE
def mysql db 0 mysql PRIMARY 3 User A #CARD# NULL NULL BTREE
@ -29,6 +32,10 @@ def mysql help_topic 0 mysql name 1 name A #CARD# NULL NULL BTREE
def mysql help_topic 0 mysql PRIMARY 1 help_topic_id A #CARD# NULL NULL BTREE
def mysql host 0 mysql PRIMARY 1 Host A #CARD# NULL NULL BTREE
def mysql host 0 mysql PRIMARY 2 Db A #CARD# NULL NULL BTREE
def mysql index_stat 0 mysql PRIMARY 1 db_name A #CARD# NULL NULL BTREE
def mysql index_stat 0 mysql PRIMARY 2 table_name A #CARD# NULL NULL BTREE
def mysql index_stat 0 mysql PRIMARY 3 index_name A #CARD# NULL NULL BTREE
def mysql index_stat 0 mysql PRIMARY 4 prefix_arity A #CARD# NULL NULL BTREE
def mysql ndb_binlog_index 0 mysql PRIMARY 1 epoch A #CARD# NULL NULL BTREE
def mysql plugin 0 mysql PRIMARY 1 name A #CARD# NULL NULL BTREE
def mysql proc 0 mysql PRIMARY 1 db A #CARD# NULL NULL BTREE
@ -51,6 +58,8 @@ def mysql tables_priv 0 mysql PRIMARY 1 Host A #CARD# NULL NULL BTREE
def mysql tables_priv 0 mysql PRIMARY 2 Db A #CARD# NULL NULL BTREE
def mysql tables_priv 0 mysql PRIMARY 3 User A #CARD# NULL NULL BTREE
def mysql tables_priv 0 mysql PRIMARY 4 Table_name A #CARD# NULL NULL BTREE
def mysql table_stat 0 mysql PRIMARY 1 db_name A #CARD# NULL NULL BTREE
def mysql table_stat 0 mysql PRIMARY 2 table_name A #CARD# NULL NULL BTREE
def mysql time_zone 0 mysql PRIMARY 1 Time_zone_id A #CARD# NULL NULL BTREE
def mysql time_zone_leap_second 0 mysql PRIMARY 1 Transition_time A #CARD# NULL NULL BTREE
def mysql time_zone_name 0 mysql PRIMARY 1 Name A #CARD# NULL NULL BTREE
@ -70,6 +79,9 @@ def mysql columns_priv 0 mysql PRIMARY 2 Db A #CARD# NULL NULL BTREE
def mysql columns_priv 0 mysql PRIMARY 3 User A #CARD# NULL NULL BTREE
def mysql columns_priv 0 mysql PRIMARY 4 Table_name A #CARD# NULL NULL BTREE
def mysql columns_priv 0 mysql PRIMARY 5 Column_name A #CARD# NULL NULL BTREE
def mysql column_stat 0 mysql PRIMARY 1 db_name A #CARD# NULL NULL BTREE
def mysql column_stat 0 mysql PRIMARY 2 table_name A #CARD# NULL NULL BTREE
def mysql column_stat 0 mysql PRIMARY 3 column_name A #CARD# NULL NULL BTREE
def mysql db 0 mysql PRIMARY 1 Host A #CARD# NULL NULL BTREE
def mysql db 0 mysql PRIMARY 2 Db A #CARD# NULL NULL BTREE
def mysql db 0 mysql PRIMARY 3 User A #CARD# NULL NULL BTREE
@ -87,6 +99,10 @@ def mysql help_topic 0 mysql name 1 name A #CARD# NULL NULL BTREE
def mysql help_topic 0 mysql PRIMARY 1 help_topic_id A #CARD# NULL NULL BTREE
def mysql host 0 mysql PRIMARY 1 Host A #CARD# NULL NULL BTREE
def mysql host 0 mysql PRIMARY 2 Db A #CARD# NULL NULL BTREE
def mysql index_stat 0 mysql PRIMARY 1 db_name A #CARD# NULL NULL BTREE
def mysql index_stat 0 mysql PRIMARY 2 table_name A #CARD# NULL NULL BTREE
def mysql index_stat 0 mysql PRIMARY 3 index_name A #CARD# NULL NULL BTREE
def mysql index_stat 0 mysql PRIMARY 4 prefix_arity A #CARD# NULL NULL BTREE
def mysql ndb_binlog_index 0 mysql PRIMARY 1 epoch A #CARD# NULL NULL BTREE
def mysql plugin 0 mysql PRIMARY 1 name A #CARD# NULL NULL BTREE
def mysql proc 0 mysql PRIMARY 1 db A #CARD# NULL NULL BTREE
@ -109,6 +125,8 @@ def mysql tables_priv 0 mysql PRIMARY 1 Host A #CARD# NULL NULL BTREE
def mysql tables_priv 0 mysql PRIMARY 2 Db A #CARD# NULL NULL BTREE
def mysql tables_priv 0 mysql PRIMARY 3 User A #CARD# NULL NULL BTREE
def mysql tables_priv 0 mysql PRIMARY 4 Table_name A #CARD# NULL NULL BTREE
def mysql table_stat 0 mysql PRIMARY 1 db_name A #CARD# NULL NULL BTREE
def mysql table_stat 0 mysql PRIMARY 2 table_name A #CARD# NULL NULL BTREE
def mysql time_zone 0 mysql PRIMARY 1 Time_zone_id A #CARD# NULL NULL BTREE
def mysql time_zone_leap_second 0 mysql PRIMARY 1 Transition_time A #CARD# NULL NULL BTREE
def mysql time_zone_name 0 mysql PRIMARY 1 Name A #CARD# NULL NULL BTREE

View File

@ -57,6 +57,7 @@ table_schema, table_name
FROM information_schema.table_constraints
WHERE constraint_catalog IS NOT NULL;
constraint_catalog constraint_schema constraint_name table_schema table_name
def mysql PRIMARY mysql column_stat
def mysql PRIMARY mysql columns_priv
def mysql PRIMARY mysql db
def mysql PRIMARY mysql event
@ -69,12 +70,14 @@ def mysql PRIMARY mysql help_relation
def mysql PRIMARY mysql help_topic
def mysql name mysql help_topic
def mysql PRIMARY mysql host
def mysql PRIMARY mysql index_stat
def mysql PRIMARY mysql ndb_binlog_index
def mysql PRIMARY mysql plugin
def mysql PRIMARY mysql proc
def mysql PRIMARY mysql procs_priv
def mysql PRIMARY mysql proxies_priv
def mysql PRIMARY mysql servers
def mysql PRIMARY mysql table_stat
def mysql PRIMARY mysql tables_priv
def mysql PRIMARY mysql time_zone
def mysql PRIMARY mysql time_zone_leap_second

View File

@ -8,6 +8,7 @@ WHERE table_schema = 'mysql'
ORDER BY table_schema,table_name,constraint_name;
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_SCHEMA TABLE_NAME CONSTRAINT_TYPE
def mysql PRIMARY mysql columns_priv PRIMARY KEY
def mysql PRIMARY mysql column_stat PRIMARY KEY
def mysql PRIMARY mysql db PRIMARY KEY
def mysql PRIMARY mysql event PRIMARY KEY
def mysql PRIMARY mysql func PRIMARY KEY
@ -19,6 +20,7 @@ def mysql PRIMARY mysql help_relation PRIMARY KEY
def mysql name mysql help_topic UNIQUE
def mysql PRIMARY mysql help_topic PRIMARY KEY
def mysql PRIMARY mysql host PRIMARY KEY
def mysql PRIMARY mysql index_stat PRIMARY KEY
def mysql PRIMARY mysql ndb_binlog_index PRIMARY KEY
def mysql PRIMARY mysql plugin PRIMARY KEY
def mysql PRIMARY mysql proc PRIMARY KEY
@ -26,6 +28,7 @@ def mysql PRIMARY mysql procs_priv PRIMARY KEY
def mysql PRIMARY mysql proxies_priv PRIMARY KEY
def mysql PRIMARY mysql servers PRIMARY KEY
def mysql PRIMARY mysql tables_priv PRIMARY KEY
def mysql PRIMARY mysql table_stat PRIMARY KEY
def mysql PRIMARY mysql time_zone PRIMARY KEY
def mysql PRIMARY mysql time_zone_leap_second PRIMARY KEY
def mysql PRIMARY mysql time_zone_name PRIMARY KEY

View File

@ -8,6 +8,7 @@ WHERE table_schema = 'mysql'
ORDER BY table_schema,table_name,constraint_name;
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_SCHEMA TABLE_NAME CONSTRAINT_TYPE
def mysql PRIMARY mysql columns_priv PRIMARY KEY
def mysql PRIMARY mysql column_stat PRIMARY KEY
def mysql PRIMARY mysql db PRIMARY KEY
def mysql PRIMARY mysql event PRIMARY KEY
def mysql PRIMARY mysql func PRIMARY KEY
@ -19,6 +20,7 @@ def mysql PRIMARY mysql help_relation PRIMARY KEY
def mysql name mysql help_topic UNIQUE
def mysql PRIMARY mysql help_topic PRIMARY KEY
def mysql PRIMARY mysql host PRIMARY KEY
def mysql PRIMARY mysql index_stat PRIMARY KEY
def mysql PRIMARY mysql ndb_binlog_index PRIMARY KEY
def mysql PRIMARY mysql plugin PRIMARY KEY
def mysql PRIMARY mysql proc PRIMARY KEY
@ -26,6 +28,7 @@ def mysql PRIMARY mysql procs_priv PRIMARY KEY
def mysql PRIMARY mysql proxies_priv PRIMARY KEY
def mysql PRIMARY mysql servers PRIMARY KEY
def mysql PRIMARY mysql tables_priv PRIMARY KEY
def mysql PRIMARY mysql table_stat PRIMARY KEY
def mysql PRIMARY mysql time_zone PRIMARY KEY
def mysql PRIMARY mysql time_zone_leap_second PRIMARY KEY
def mysql PRIMARY mysql time_zone_name PRIMARY KEY
@ -38,6 +41,7 @@ WHERE table_schema = 'mysql'
ORDER BY table_schema,table_name,constraint_name;
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_SCHEMA TABLE_NAME CONSTRAINT_TYPE
def mysql PRIMARY mysql columns_priv PRIMARY KEY
def mysql PRIMARY mysql column_stat PRIMARY KEY
def mysql PRIMARY mysql db PRIMARY KEY
def mysql PRIMARY mysql event PRIMARY KEY
def mysql PRIMARY mysql func PRIMARY KEY
@ -49,6 +53,7 @@ def mysql PRIMARY mysql help_relation PRIMARY KEY
def mysql name mysql help_topic UNIQUE
def mysql PRIMARY mysql help_topic PRIMARY KEY
def mysql PRIMARY mysql host PRIMARY KEY
def mysql PRIMARY mysql index_stat PRIMARY KEY
def mysql PRIMARY mysql ndb_binlog_index PRIMARY KEY
def mysql PRIMARY mysql plugin PRIMARY KEY
def mysql PRIMARY mysql proc PRIMARY KEY
@ -56,6 +61,7 @@ def mysql PRIMARY mysql procs_priv PRIMARY KEY
def mysql PRIMARY mysql proxies_priv PRIMARY KEY
def mysql PRIMARY mysql servers PRIMARY KEY
def mysql PRIMARY mysql tables_priv PRIMARY KEY
def mysql PRIMARY mysql table_stat PRIMARY KEY
def mysql PRIMARY mysql time_zone PRIMARY KEY
def mysql PRIMARY mysql time_zone_leap_second PRIMARY KEY
def mysql PRIMARY mysql time_zone_name PRIMARY KEY

View File

@ -37,6 +37,29 @@ user_comment Column privileges
Separator -----------------------------------------------------
TABLE_CATALOG def
TABLE_SCHEMA mysql
TABLE_NAME column_stat
TABLE_TYPE BASE TABLE
ENGINE MYISAM_OR_MARIA
VERSION 10
ROW_FORMAT DYNAMIC_OR_PAGE
TABLE_ROWS #TBLR#
AVG_ROW_LENGTH #ARL#
DATA_LENGTH #DL#
MAX_DATA_LENGTH #MDL#
INDEX_LENGTH #IL#
DATA_FREE #DF#
AUTO_INCREMENT NULL
CREATE_TIME #CRT#
UPDATE_TIME #UT#
CHECK_TIME #CT#
TABLE_COLLATION utf8_bin
CHECKSUM NULL
CREATE_OPTIONS #CO#
TABLE_COMMENT #TC#
user_comment Statistics on Columns
Separator -----------------------------------------------------
TABLE_CATALOG def
TABLE_SCHEMA mysql
TABLE_NAME db
TABLE_TYPE BASE TABLE
ENGINE MYISAM_OR_MARIA
@ -244,6 +267,29 @@ user_comment Host privileges; Merged with database privileges
Separator -----------------------------------------------------
TABLE_CATALOG def
TABLE_SCHEMA mysql
TABLE_NAME index_stat
TABLE_TYPE BASE TABLE
ENGINE MYISAM_OR_MARIA
VERSION 10
ROW_FORMAT DYNAMIC_OR_PAGE
TABLE_ROWS #TBLR#
AVG_ROW_LENGTH #ARL#
DATA_LENGTH #DL#
MAX_DATA_LENGTH #MDL#
INDEX_LENGTH #IL#
DATA_FREE #DF#
AUTO_INCREMENT NULL
CREATE_TIME #CRT#
UPDATE_TIME #UT#
CHECK_TIME #CT#
TABLE_COLLATION utf8_bin
CHECKSUM NULL
CREATE_OPTIONS #CO#
TABLE_COMMENT #TC#
user_comment Statistics on Indexes
Separator -----------------------------------------------------
TABLE_CATALOG def
TABLE_SCHEMA mysql
TABLE_NAME ndb_binlog_index
TABLE_TYPE BASE TABLE
ENGINE MYISAM_OR_MARIA
@ -428,6 +474,29 @@ user_comment Table privileges
Separator -----------------------------------------------------
TABLE_CATALOG def
TABLE_SCHEMA mysql
TABLE_NAME table_stat
TABLE_TYPE BASE TABLE
ENGINE MYISAM_OR_MARIA
VERSION 10
ROW_FORMAT DYNAMIC_OR_PAGE
TABLE_ROWS #TBLR#
AVG_ROW_LENGTH #ARL#
DATA_LENGTH #DL#
MAX_DATA_LENGTH #MDL#
INDEX_LENGTH #IL#
DATA_FREE #DF#
AUTO_INCREMENT NULL
CREATE_TIME #CRT#
UPDATE_TIME #UT#
CHECK_TIME #CT#
TABLE_COLLATION utf8_bin
CHECKSUM NULL
CREATE_OPTIONS #CO#
TABLE_COMMENT #TC#
user_comment Statistics on Tables
Separator -----------------------------------------------------
TABLE_CATALOG def
TABLE_SCHEMA mysql
TABLE_NAME time_zone
TABLE_TYPE BASE TABLE
ENGINE MYISAM_OR_MARIA

View File

@ -37,6 +37,29 @@ user_comment Column privileges
Separator -----------------------------------------------------
TABLE_CATALOG def
TABLE_SCHEMA mysql
TABLE_NAME column_stat
TABLE_TYPE BASE TABLE
ENGINE MYISAM_OR_MARIA
VERSION 10
ROW_FORMAT DYNAMIC_OR_PAGE
TABLE_ROWS #TBLR#
AVG_ROW_LENGTH #ARL#
DATA_LENGTH #DL#
MAX_DATA_LENGTH #MDL#
INDEX_LENGTH #IL#
DATA_FREE #DF#
AUTO_INCREMENT NULL
CREATE_TIME #CRT#
UPDATE_TIME #UT#
CHECK_TIME #CT#
TABLE_COLLATION utf8_bin
CHECKSUM NULL
CREATE_OPTIONS #CO#
TABLE_COMMENT #TC#
user_comment Statistics on Columns
Separator -----------------------------------------------------
TABLE_CATALOG def
TABLE_SCHEMA mysql
TABLE_NAME db
TABLE_TYPE BASE TABLE
ENGINE MYISAM_OR_MARIA
@ -244,6 +267,29 @@ user_comment Host privileges; Merged with database privileges
Separator -----------------------------------------------------
TABLE_CATALOG def
TABLE_SCHEMA mysql
TABLE_NAME index_stat
TABLE_TYPE BASE TABLE
ENGINE MYISAM_OR_MARIA
VERSION 10
ROW_FORMAT DYNAMIC_OR_PAGE
TABLE_ROWS #TBLR#
AVG_ROW_LENGTH #ARL#
DATA_LENGTH #DL#
MAX_DATA_LENGTH #MDL#
INDEX_LENGTH #IL#
DATA_FREE #DF#
AUTO_INCREMENT NULL
CREATE_TIME #CRT#
UPDATE_TIME #UT#
CHECK_TIME #CT#
TABLE_COLLATION utf8_bin
CHECKSUM NULL
CREATE_OPTIONS #CO#
TABLE_COMMENT #TC#
user_comment Statistics on Indexes
Separator -----------------------------------------------------
TABLE_CATALOG def
TABLE_SCHEMA mysql
TABLE_NAME ndb_binlog_index
TABLE_TYPE BASE TABLE
ENGINE MYISAM_OR_MARIA
@ -428,6 +474,29 @@ user_comment Table privileges
Separator -----------------------------------------------------
TABLE_CATALOG def
TABLE_SCHEMA mysql
TABLE_NAME table_stat
TABLE_TYPE BASE TABLE
ENGINE MYISAM_OR_MARIA
VERSION 10
ROW_FORMAT DYNAMIC_OR_PAGE
TABLE_ROWS #TBLR#
AVG_ROW_LENGTH #ARL#
DATA_LENGTH #DL#
MAX_DATA_LENGTH #MDL#
INDEX_LENGTH #IL#
DATA_FREE #DF#
AUTO_INCREMENT NULL
CREATE_TIME #CRT#
UPDATE_TIME #UT#
CHECK_TIME #CT#
TABLE_COLLATION utf8_bin
CHECKSUM NULL
CREATE_OPTIONS #CO#
TABLE_COMMENT #TC#
user_comment Statistics on Tables
Separator -----------------------------------------------------
TABLE_CATALOG def
TABLE_SCHEMA mysql
TABLE_NAME time_zone
TABLE_TYPE BASE TABLE
ENGINE MYISAM_OR_MARIA
@ -605,6 +674,29 @@ user_comment Column privileges
Separator -----------------------------------------------------
TABLE_CATALOG def
TABLE_SCHEMA mysql
TABLE_NAME column_stat
TABLE_TYPE BASE TABLE
ENGINE MYISAM_OR_MARIA
VERSION 10
ROW_FORMAT DYNAMIC_OR_PAGE
TABLE_ROWS #TBLR#
AVG_ROW_LENGTH #ARL#
DATA_LENGTH #DL#
MAX_DATA_LENGTH #MDL#
INDEX_LENGTH #IL#
DATA_FREE #DF#
AUTO_INCREMENT NULL
CREATE_TIME #CRT#
UPDATE_TIME #UT#
CHECK_TIME #CT#
TABLE_COLLATION utf8_bin
CHECKSUM NULL
CREATE_OPTIONS #CO#
TABLE_COMMENT #TC#
user_comment Statistics on Columns
Separator -----------------------------------------------------
TABLE_CATALOG def
TABLE_SCHEMA mysql
TABLE_NAME db
TABLE_TYPE BASE TABLE
ENGINE MYISAM_OR_MARIA
@ -812,6 +904,29 @@ user_comment Host privileges; Merged with database privileges
Separator -----------------------------------------------------
TABLE_CATALOG def
TABLE_SCHEMA mysql
TABLE_NAME index_stat
TABLE_TYPE BASE TABLE
ENGINE MYISAM_OR_MARIA
VERSION 10
ROW_FORMAT DYNAMIC_OR_PAGE
TABLE_ROWS #TBLR#
AVG_ROW_LENGTH #ARL#
DATA_LENGTH #DL#
MAX_DATA_LENGTH #MDL#
INDEX_LENGTH #IL#
DATA_FREE #DF#
AUTO_INCREMENT NULL
CREATE_TIME #CRT#
UPDATE_TIME #UT#
CHECK_TIME #CT#
TABLE_COLLATION utf8_bin
CHECKSUM NULL
CREATE_OPTIONS #CO#
TABLE_COMMENT #TC#
user_comment Statistics on Indexes
Separator -----------------------------------------------------
TABLE_CATALOG def
TABLE_SCHEMA mysql
TABLE_NAME ndb_binlog_index
TABLE_TYPE BASE TABLE
ENGINE MYISAM_OR_MARIA
@ -996,6 +1111,29 @@ user_comment Table privileges
Separator -----------------------------------------------------
TABLE_CATALOG def
TABLE_SCHEMA mysql
TABLE_NAME table_stat
TABLE_TYPE BASE TABLE
ENGINE MYISAM_OR_MARIA
VERSION 10
ROW_FORMAT DYNAMIC_OR_PAGE
TABLE_ROWS #TBLR#
AVG_ROW_LENGTH #ARL#
DATA_LENGTH #DL#
MAX_DATA_LENGTH #MDL#
INDEX_LENGTH #IL#
DATA_FREE #DF#
AUTO_INCREMENT NULL
CREATE_TIME #CRT#
UPDATE_TIME #UT#
CHECK_TIME #CT#
TABLE_COLLATION utf8_bin
CHECKSUM NULL
CREATE_OPTIONS #CO#
TABLE_COMMENT #TC#
user_comment Statistics on Tables
Separator -----------------------------------------------------
TABLE_CATALOG def
TABLE_SCHEMA mysql
TABLE_NAME time_zone
TABLE_TYPE BASE TABLE
ENGINE MYISAM_OR_MARIA

View File

@ -17,6 +17,7 @@ substring(object_name, locate("no_index_tab", object_name)) as short_name
from performance_schema.events_waits_history_long
where operation not like "tell"
and event_name like "wait/io/file/myisam/%"
having short_name <> ""
order by thread_id, event_id;
event_name short_source operation number_of_bytes short_name
wait/io/file/myisam/kfile mi_create.c: create NULL no_index_tab.MYI

View File

@ -25,7 +25,7 @@ ERROR 1050 (42S01) at line 428: Table 'setup_consumers' already exists
ERROR 1050 (42S01) at line 445: Table 'setup_instruments' already exists
ERROR 1050 (42S01) at line 461: Table 'setup_timers' already exists
ERROR 1050 (42S01) at line 478: Table 'threads' already exists
ERROR 1644 (HY000) at line 1126: Unexpected content found in the performance_schema database.
ERROR 1644 (HY000) at line 1132: Unexpected content found in the performance_schema database.
FATAL ERROR: Upgrade failed
show tables like "user_table";
Tables_in_performance_schema (user_table)
@ -55,7 +55,7 @@ ERROR 1050 (42S01) at line 428: Table 'setup_consumers' already exists
ERROR 1050 (42S01) at line 445: Table 'setup_instruments' already exists
ERROR 1050 (42S01) at line 461: Table 'setup_timers' already exists
ERROR 1050 (42S01) at line 478: Table 'threads' already exists
ERROR 1644 (HY000) at line 1126: Unexpected content found in the performance_schema database.
ERROR 1644 (HY000) at line 1132: Unexpected content found in the performance_schema database.
FATAL ERROR: Upgrade failed
show tables like "user_view";
Tables_in_performance_schema (user_view)
@ -83,7 +83,7 @@ ERROR 1050 (42S01) at line 428: Table 'setup_consumers' already exists
ERROR 1050 (42S01) at line 445: Table 'setup_instruments' already exists
ERROR 1050 (42S01) at line 461: Table 'setup_timers' already exists
ERROR 1050 (42S01) at line 478: Table 'threads' already exists
ERROR 1644 (HY000) at line 1126: Unexpected content found in the performance_schema database.
ERROR 1644 (HY000) at line 1132: Unexpected content found in the performance_schema database.
FATAL ERROR: Upgrade failed
select name from mysql.proc where db='performance_schema';
name
@ -111,7 +111,7 @@ ERROR 1050 (42S01) at line 428: Table 'setup_consumers' already exists
ERROR 1050 (42S01) at line 445: Table 'setup_instruments' already exists
ERROR 1050 (42S01) at line 461: Table 'setup_timers' already exists
ERROR 1050 (42S01) at line 478: Table 'threads' already exists
ERROR 1644 (HY000) at line 1126: Unexpected content found in the performance_schema database.
ERROR 1644 (HY000) at line 1132: Unexpected content found in the performance_schema database.
FATAL ERROR: Upgrade failed
select name from mysql.proc where db='performance_schema';
name
@ -139,7 +139,7 @@ ERROR 1050 (42S01) at line 428: Table 'setup_consumers' already exists
ERROR 1050 (42S01) at line 445: Table 'setup_instruments' already exists
ERROR 1050 (42S01) at line 461: Table 'setup_timers' already exists
ERROR 1050 (42S01) at line 478: Table 'threads' already exists
ERROR 1644 (HY000) at line 1126: Unexpected content found in the performance_schema database.
ERROR 1644 (HY000) at line 1132: Unexpected content found in the performance_schema database.
FATAL ERROR: Upgrade failed
select name from mysql.event where db='performance_schema';
name

View File

@ -46,6 +46,7 @@ select event_name,
from performance_schema.events_waits_history_long
where operation not like "tell"
and event_name like "wait/io/file/myisam/%"
having short_name <> ""
order by thread_id, event_id;
# In case of failures, this will tell if file io are lost.

View File

@ -0,0 +1,95 @@
SET @start_global_value = @@global.use_stat_tables;
SELECT @start_global_value;
@start_global_value
NEVER
SET @start_session_value = @@session.use_stat_tables;
SELECT @start_session_value;
@start_session_value
NEVER
SET @@global.use_stat_tables = 2;
SET @@global.use_stat_tables = DEFAULT;
SELECT @@global.use_stat_tables;
@@global.use_stat_tables
NEVER
SET @@global.use_stat_tables = 0;
SELECT @@global.use_stat_tables;
@@global.use_stat_tables
NEVER
SET @@global.use_stat_tables = 1;
SELECT @@global.use_stat_tables;
@@global.use_stat_tables
COMPLEMENTARY
SET @@global.use_stat_tables = 2;
SELECT @@global.use_stat_tables;
@@global.use_stat_tables
PREFERABLY
SET @@global.use_stat_tables = NEVER;
SELECT @@global.use_stat_tables;
@@global.use_stat_tables
NEVER
SET @@global.use_stat_tables = COMPLEMENTARY;
SELECT @@global.use_stat_tables;
@@global.use_stat_tables
COMPLEMENTARY
SET @@global.use_stat_tables = PREFERABLY;
SELECT @@global.use_stat_tables;
@@global.use_stat_tables
PREFERABLY
SET @@session.use_stat_tables = 0;
SELECT @@session.use_stat_tables;
@@session.use_stat_tables
NEVER
SET @@session.use_stat_tables = 1;
SELECT @@session.use_stat_tables;
@@session.use_stat_tables
COMPLEMENTARY
SET @@session.use_stat_tables = 2;
SELECT @@session.use_stat_tables;
@@session.use_stat_tables
PREFERABLY
SET @@session.use_stat_tables = NEVER;
SELECT @@session.use_stat_tables;
@@session.use_stat_tables
NEVER
SET @@session.use_stat_tables = PREFERABLY;
SELECT @@session.use_stat_tables;
@@session.use_stat_tables
PREFERABLY
SET @@session.use_stat_tables = COMPLEMENTARY;
SELECT @@session.use_stat_tables;
@@session.use_stat_tables
COMPLEMENTARY
set sql_mode=TRADITIONAL;
SET @@global.use_stat_tables = 10;
ERROR 42000: Variable 'use_stat_tables' can't be set to the value of '10'
SET @@global.use_stat_tables = -1024;
ERROR 42000: Variable 'use_stat_tables' can't be set to the value of '-1024'
SET @@global.use_stat_tables = 2.4;
ERROR 42000: Incorrect argument type to variable 'use_stat_tables'
SET @@global.use_stat_tables = OFF;
ERROR 42000: Variable 'use_stat_tables' can't be set to the value of 'OFF'
SET @@session.use_stat_tables = 10;
ERROR 42000: Variable 'use_stat_tables' can't be set to the value of '10'
SET @@session.use_stat_tables = -2;
ERROR 42000: Variable 'use_stat_tables' can't be set to the value of '-2'
SET @@session.use_stat_tables = 1.2;
ERROR 42000: Incorrect argument type to variable 'use_stat_tables'
SET @@session.use_stat_tables = ON;
ERROR 42000: Variable 'use_stat_tables' can't be set to the value of 'ON'
SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
WHERE VARIABLE_NAME='use_stat_tables';
VARIABLE_NAME VARIABLE_VALUE
USE_STAT_TABLES PREFERABLY
SELECT * FROM INFORMATION_SCHEMA.SESSION_VARIABLES
WHERE VARIABLE_NAME='use_stat_tables';
VARIABLE_NAME VARIABLE_VALUE
USE_STAT_TABLES COMPLEMENTARY
SET @@global.use_stat_tables = @start_global_value;
SELECT @@global.use_stat_tables;
@@global.use_stat_tables
NEVER
SET @@session.use_stat_tables = @start_session_value;
SELECT @@session.use_stat_tables;
@@session.use_stat_tables
NEVER
set sql_mode='';

View File

@ -0,0 +1,100 @@
--source include/load_sysvars.inc
#############################################################
# Save initial value #
#############################################################
SET @start_global_value = @@global.use_stat_tables;
SELECT @start_global_value;
SET @start_session_value = @@session.use_stat_tables;
SELECT @start_session_value;
###############################################################
# Display the DEFAULT value of use_stat_tables #
###############################################################
SET @@global.use_stat_tables = 2;
SET @@global.use_stat_tables = DEFAULT;
SELECT @@global.use_stat_tables;
##################################################################################
# Change the value of use_stat_tables to a valid value for GLOBAL Scope #
##################################################################################
SET @@global.use_stat_tables = 0;
SELECT @@global.use_stat_tables;
SET @@global.use_stat_tables = 1;
SELECT @@global.use_stat_tables;
SET @@global.use_stat_tables = 2;
SELECT @@global.use_stat_tables;
SET @@global.use_stat_tables = NEVER;
SELECT @@global.use_stat_tables;
SET @@global.use_stat_tables = COMPLEMENTARY;
SELECT @@global.use_stat_tables;
SET @@global.use_stat_tables = PREFERABLY;
SELECT @@global.use_stat_tables;
####################################################################################
# Change the value of use_stat_tables to a valid value for SESSION Scope #
####################################################################################
SET @@session.use_stat_tables = 0;
SELECT @@session.use_stat_tables;
SET @@session.use_stat_tables = 1;
SELECT @@session.use_stat_tables;
SET @@session.use_stat_tables = 2;
SELECT @@session.use_stat_tables;
SET @@session.use_stat_tables = NEVER;
SELECT @@session.use_stat_tables;
SET @@session.use_stat_tables = PREFERABLY;
SELECT @@session.use_stat_tables;
SET @@session.use_stat_tables = COMPLEMENTARY;
SELECT @@session.use_stat_tables;
#####################################################################
# Change the value of use_stat_tables to an invalid value #
#####################################################################
set sql_mode=TRADITIONAL;
--Error ER_WRONG_VALUE_FOR_VAR
SET @@global.use_stat_tables = 10;
--Error ER_WRONG_VALUE_FOR_VAR
SET @@global.use_stat_tables = -1024;
--Error ER_WRONG_TYPE_FOR_VAR
SET @@global.use_stat_tables = 2.4;
--Error ER_WRONG_VALUE_FOR_VAR
SET @@global.use_stat_tables = OFF;
--Error ER_WRONG_VALUE_FOR_VAR
SET @@session.use_stat_tables = 10;
--Error ER_WRONG_VALUE_FOR_VAR
SET @@session.use_stat_tables = -2;
--Error ER_WRONG_TYPE_FOR_VAR
SET @@session.use_stat_tables = 1.2;
--Error ER_WRONG_VALUE_FOR_VAR
SET @@session.use_stat_tables = ON;
###############################################################################
# Check if the value in GLOBAL & SESSION Tables matches value in variable #
###############################################################################
SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
WHERE VARIABLE_NAME='use_stat_tables';
SELECT * FROM INFORMATION_SCHEMA.SESSION_VARIABLES
WHERE VARIABLE_NAME='use_stat_tables';
####################################
# Restore initial value #
####################################
SET @@global.use_stat_tables = @start_global_value;
SELECT @@global.use_stat_tables;
SET @@session.use_stat_tables = @start_session_value;
SELECT @@session.use_stat_tables;
set sql_mode='';
######################################################
# END OF use_stat_tables TESTS #
######################################################

View File

@ -0,0 +1,75 @@
CREATE TABLE A (
pk INTEGER AUTO_INCREMENT PRIMARY KEY,
fdate DATE
) ENGINE=MyISAM;
--delimiter |
CREATE PROCEDURE p_analyze()
BEGIN
DECLARE attempts INTEGER DEFAULT 100;
wl_loop: WHILE attempts > 0 DO
ANALYZE TABLE A;
SET attempts = attempts - 1;
END WHILE wl_loop;
END |
CREATE FUNCTION rnd3() RETURNS INT
BEGIN
RETURN ROUND(3 * RAND() + 0.5);
END |
--delimiter ;
SET GLOBAL use_stat_tables = PREFERABLY;
--let $trial = 100
--disable_query_log
--disable_result_log
--disable_warnings
while ($trial)
{
--connect (con1,localhost,root,,)
--send CALL p_analyze()
--connect (con2,localhost,root,,)
--send CALL p_analyze()
--let $run = 100
while ($run)
{
--connect (con3,localhost,root,,)
let $query = `SELECT CASE rnd3()
WHEN 1 THEN 'INSERT INTO A (pk) VALUES (NULL)'
WHEN 2 THEN 'DELETE FROM A LIMIT 1'
ELSE 'UPDATE A SET fdate = 2 LIMIT 1' END`;
--eval $query
--disconnect con3
--dec $run
}
--connection con2
--reap
--disconnect con2
--connection con1
--reap
--disconnect con1
--dec $trial
}
--enable_query_log
--enable_result_log
--enable_warnings
# Cleanup
--connection default
DROP TABLE A;
DROP PROCEDURE p_analyze;
DROP FUNCTION rnd3;
SET GLOBAL use_stat_tables = DEFAULT;

View File

@ -0,0 +1,207 @@
--source include/have_stat_tables.inc
select @@global.use_stat_tables;
select @@session.use_stat_tables;
set @save_use_stat_tables=@@use_stat_tables;
set use_stat_tables='preferably';
--disable_warnings
DROP DATABASE IF EXISTS dbt3_s001;
--enable_warnings
CREATE DATABASE dbt3_s001;
use dbt3_s001;
set @save_optimizer_switch=@@optimizer_switch;
set optimizer_switch='extended_keys=off';
--disable_query_log
--disable_result_log
--disable_warnings
--source include/dbt3_s001.inc
create index i_p_retailprice on part(p_retailprice);
delete from mysql.table_stat;
delete from mysql.column_stat;
delete from mysql.index_stat;
ANALYZE TABLE
customer, lineitem, nation, orders, part, partsupp, region, supplier;
FLUSH TABLE mysql.table_stat, mysql.index_stat;
--enable_warnings
--enable_result_log
--enable_query_log
select * from mysql.table_stat;
select * from mysql.index_stat;
set optimizer_switch=@save_optimizer_switch;
set @save_optimizer_switch=@@optimizer_switch;
set optimizer_switch='index_condition_pushdown=off';
let $Q5=
select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue
from customer, orders, lineitem, supplier, nation, region
where c_custkey = o_custkey and l_orderkey = o_orderkey
and l_suppkey = s_suppkey and c_nationkey = s_nationkey
and s_nationkey = n_nationkey and n_regionkey = r_regionkey
and r_name = 'AMERICA' and o_orderdate >= date '1995-01-01'
and o_orderdate < date '1995-01-01' + interval '1' year
group by n_name
order by revenue desc;
eval EXPLAIN $Q5;
eval $Q5;
set optimizer_switch=@save_optimizer_switch;
delete from mysql.index_stat;
--disable_query_log
--disable_result_log
--disable_warnings
ANALYZE TABLE
customer, lineitem, nation, orders, part, partsupp, region, supplier;
FLUSH TABLE mysql.table_stat, mysql.index_stat;
--enable_warnings
--enable_result_log
--enable_query_log
select * from mysql.table_stat;
select * from mysql.index_stat;
select * from mysql.table_stat where table_name='orders';
select * from mysql.index_stat where table_name='orders';
select (select cardinality from mysql.table_stat where table_name='orders') /
(select avg_frequency from mysql.index_stat
where index_name='i_o_orderdate' and prefix_arity=1) as n_distinct;
select count(distinct o_orderdate) from orders;
select (select cardinality from mysql.table_stat where table_name='orders') /
(select avg_frequency from mysql.index_stat
where index_name='i_o_custkey' and prefix_arity=1) as n_distinct;
select count(distinct o_custkey) from orders;
show index from orders;
select index_name, column_name, cardinality from information_schema.statistics
where table_name='orders';
set @save_optimizer_switch=@@optimizer_switch;
set optimizer_switch='index_condition_pushdown=off';
eval EXPLAIN $Q5;
eval $Q5;
set optimizer_switch=@save_optimizer_switch;
let $Q8=
select o_year,
sum(case when nation = 'UNITED STATES' then volume else 0 end) /
sum(volume) as mkt_share
from (select extract(year from o_orderdate) as o_year,
l_extendedprice * (1-l_discount) as volume,
n2.n_name as nation
from part, supplier, lineitem, orders, customer,
nation n1, nation n2, region
where p_partkey = l_partkey and s_suppkey = l_suppkey
and l_orderkey = o_orderkey and o_custkey = c_custkey
and c_nationkey = n1.n_nationkey and n1.n_regionkey = r_regionkey
and r_name = 'AMERICA' and s_nationkey = n2.n_nationkey
and o_orderdate between date '1995-01-01' and date '1996-12-31'
and p_type = 'STANDARD BRUSHED STEEL' ) as all_nations
group by o_year
order by o_year;
eval EXPLAIN $Q8;
eval $Q8;
let $Q9=
select nation, o_year, sum(amount) as sum_profit
from (select n_name as nation,
extract(year from o_orderdate) as o_year,
l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount
from part, supplier, lineitem, partsupp, orders, nation
where s_suppkey = l_suppkey and ps_suppkey = l_suppkey
and ps_partkey = l_partkey and p_partkey = l_partkey
and o_orderkey = l_orderkey and s_nationkey = n_nationkey
and p_name like '%green%') as profit
group by nation, o_year
order by nation, o_year desc;
eval EXPLAIN $Q9;
eval $Q9;
set @save_optimizer_switch=@@optimizer_switch;
set optimizer_switch='extended_keys=on';
let $QQ1=
select o_orderkey, p_partkey
from part, lineitem, orders
where p_retailprice > 1100 and o_orderdate='1997-01-01'
and o_orderkey=l_orderkey and p_partkey=l_partkey;
eval EXPLAIN $QQ1;
eval $QQ1;
set optimizer_switch=@save_optimizer_switch;
DROP DATABASE dbt3_s001;
use test;
--echo #
--echo # Bug mdev-473: ANALYZE table locked for write
--echo #
set use_stat_tables='complementary';
create table t1 (i int);
lock table t1 write;
analyze table t1;
alter table t1 add column a varchar(8);
drop table t1;
--echo #
--echo # Bug mdev-487: memory leak in ANALYZE with stat tables
--echo #
SET use_stat_tables = 'preferably';
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(2);
DELETE FROM t1 WHERE a=1;
ANALYZE TABLE t1;
DROP TABLE t1;
--echo #
--echo # Bug mdev-518: corrupted/missing statistical tables
--echo #
CREATE TABLE t1 (i int) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1),(2);
FLUSH TABLE t1;
SET use_stat_tables='never';
EXPLAIN SELECT * FROM t1;
--move_file $MYSQLTEST_VARDIR/mysqld.1/data/mysql/table_stat.MYD $MYSQLTEST_VARDIR/mysqld.1/data/mysql/table_stat.MYD.save
FLUSH TABLES;
SET use_stat_tables='preferably';
--disable_warnings
EXPLAIN SELECT * FROM t1;
--enable_warnings
# Cleanup
--move_file $MYSQLTEST_VARDIR/mysqld.1/data/mysql/table_stat.MYD.save $MYSQLTEST_VARDIR/mysqld.1/data/mysql/table_stat.MYD
DROP TABLE t1;
set use_stat_tables=@save_use_stat_tables;

View File

@ -0,0 +1,78 @@
--source include/have_innodb.inc
SET SESSION STORAGE_ENGINE='InnoDB';
select @@global.use_stat_tables;
select @@session.use_stat_tables;
set @save_use_stat_tables=@@use_stat_tables;
set use_stat_tables='preferably';
--disable_warnings
DROP DATABASE IF EXISTS dbt3_s001;
--enable_warnings
CREATE DATABASE dbt3_s001;
use dbt3_s001;
set @save_optimizer_switch=@@optimizer_switch;
set optimizer_switch='extended_keys=off';
--disable_query_log
--disable_result_log
--disable_warnings
--source include/dbt3_s001.inc
delete from mysql.table_stat;
delete from mysql.column_stat;
delete from mysql.index_stat;
ANALYZE TABLE
customer, lineitem, nation, orders, part, partsupp, region, supplier;
--enable_warnings
--enable_result_log
--enable_query_log
--echo #
--echo # Bug mdev-503: optimizer ignores setting use_stat_tables='preferably'
--echo #
flush tables
customer, lineitem, nation, orders, part, partsupp, region, supplier;
let $Q3S=
select sql_calc_found_rows straight_join
l_orderkey, sum(l_extendedprice*(1-l_discount)) as revenue,
o_orderdate, o_shippriority
from orders, customer, lineitem
where c_mktsegment = 'BUILDING' and c_custkey = o_custkey
and l_orderkey = o_orderkey and o_orderdate < date '1995-03-15'
and l_shipdate > date '1995-03-15'
group by l_orderkey, o_orderdate, o_shippriority
order by revenue desc, o_orderdate
limit 10;
set use_stat_tables='never';
--replace_column 9 #
eval EXPLAIN $Q3S;
set use_stat_tables='preferably';
--replace_result 2 1
eval EXPLAIN $Q3S;
flush tables customer, orders, lineitem;
eval EXPLAIN $Q3S;
--echo # End of the test case for mdev-503
set optimizer_switch=@save_optimizer_switch;
DROP DATABASE dbt3_s001;
use test;
set use_stat_tables=@save_use_stat_tables;
SET SESSION STORAGE_ENGINE=DEFAULT;

View File

@ -0,0 +1,12 @@
--source include/have_innodb.inc
SET SESSION STORAGE_ENGINE='InnoDB';
set @save_optimizer_switch_for_stat_tables_test=@@optimizer_switch;
set optimizer_switch='extended_keys=on';
--source stat_tables.test
set optimizer_switch=@save_optimizer_switch_for_stat_tables_test;
SET SESSION STORAGE_ENGINE=DEFAULT;

View File

@ -0,0 +1,153 @@
--source include/have_stat_tables.inc
--source include/have_debug_sync.inc
--source include/not_embedded.inc
set @save_use_stat_tables=@@use_stat_tables;
set use_stat_tables='preferably';
--disable_warnings
DROP DATABASE IF EXISTS dbt3_s001;
--enable_warnings
CREATE DATABASE dbt3_s001;
use dbt3_s001;
set @save_optimizer_switch=@@optimizer_switch;
set optimizer_switch='extended_keys=off';
--disable_query_log
--disable_result_log
--disable_warnings
--source include/dbt3_s001.inc
delete from mysql.table_stat;
delete from mysql.column_stat;
delete from mysql.index_stat;
ANALYZE TABLE
customer, lineitem, nation, orders, part, partsupp, region, supplier;
--enable_warnings
--enable_result_log
--enable_query_log
select * from mysql.table_stat;
select * from mysql.index_stat;
#
# Test for parallel memory allocation for statistical data
#
# assumes that start the code of memory allocation for stats data has this line:
#
# DEBUG_SYNC(thd, "statistics_mem_alloc_start1");
# DEBUG_SYNC(thd, "statistics_mem_alloc_start2");
#
let $Q6=
select sum(l_extendedprice*l_discount) as revenue
from lineitem
where l_shipdate >= date '1994-01-01'
and l_shipdate < date '1994-01-01' + interval '1' year
and l_discount between 0.06 - 0.01 and 0.06 + 0.01
and l_quantity < 24;
flush table lineitem;
set use_stat_tables='never';
eval $Q6;
connect (con1, localhost, root,,);
connect (con2, localhost, root,,);
connection con1;
set debug_sync='statistics_mem_alloc_start1 WAIT_FOR second_thread_started_too';
set debug_sync='statistics_mem_alloc_start2 SIGNAL first_thread_working';
use dbt3_s001;
set use_stat_tables='preferably';
--send_eval $Q6
connection con2;
set debug_sync='statistics_mem_alloc_start1 SIGNAL second_thread_started_too';
set debug_sync='statistics_mem_alloc_start2 WAIT_FOR first_thread_working';
use dbt3_s001;
set use_stat_tables='preferably';
--send_eval $Q6
connection con1;
--reap
connection con2;
--reap
connection default;
set use_stat_tables='preferably';
disconnect con1;
disconnect con2;
set debug_sync='RESET';
#
# Test for parallel statistics collection
#
# assumes that start of stats collection code has this line:
#
# DEBUG_SYNC(thd, "statistics_collection_start1");
# DEBUG_SYNC(thd, "statistics_collection_start2");
#
select * from mysql.index_stat where table_name='lineitem' order by index_name;
delete from mysql.index_stat
where table_name='lineitem' and
index_name in ('i_l_shipdate', 'i_l_receiptdate');
select * from mysql.index_stat where table_name='lineitem' order by index_name;
--disable_result_log
--disable_warnings
analyze table lineitem persistent for columns() indexes (i_l_shipdate);
--enable_warnings
--enable_result_log
select * from mysql.index_stat where table_name='lineitem' order by index_name;
delete from mysql.index_stat
where table_name='lineitem' and index_name= 'i_l_shipdate';
select * from mysql.index_stat where table_name='lineitem' order by index_name;
connect (con1, localhost, root,,);
connect (con2, localhost, root,,);
connection con1;
set debug_sync='statistics_collection_start1 WAIT_FOR second_thread_started_too';
set debug_sync='statistics_collection_start2 SIGNAL first_thread_working';
use dbt3_s001;
set use_stat_tables='preferably';
--send analyze table lineitem persistent for columns() indexes (i_l_shipdate)
connection con2;
set debug_sync='statistics_collection_start1 SIGNAL second_thread_started_too';
set debug_sync='statistics_collection_start2 WAIT_FOR first_thread_working';
use dbt3_s001;
set use_stat_tables='preferably';
--send analyze table lineitem persistent for columns() indexes (i_l_receiptdate)
connection con1;
--disable_result_log
--disable_warnings
--reap
--enable_warnings
--enable_result_log
connection con2;
--disable_result_log
--disable_warnings
--reap
--enable_warnings
--enable_result_log
connection default;
disconnect con1;
disconnect con2;
set debug_sync='RESET';
select * from mysql.index_stat where table_name='lineitem' order by index_name;
DROP DATABASE dbt3_s001;
use test;
set use_stat_tables=@save_use_stat_tables;

View File

@ -0,0 +1,12 @@
--source include/have_innodb.inc
SET SESSION STORAGE_ENGINE='InnoDB';
set @save_optimizer_switch_for_stat_tables_test=@@optimizer_switch;
set optimizer_switch='extended_keys=on';
--source stat_tables_par.test
set optimizer_switch=@save_optimizer_switch_for_stat_tables_test;
SET SESSION STORAGE_ENGINE=DEFAULT;

View File

@ -0,0 +1,31 @@
--source include/have_binlog_format_row.inc
--source include/have_innodb.inc
--source include/have_partition.inc
--echo #
--echo # Bug mdev-463: assertion failure when running ANALYZE with RBR on
--echo #
SET GLOBAL use_stat_tables = PREFERABLY;
--connect (con1,localhost,root,,)
CREATE TABLE t1 (i INT) ENGINE=InnoDB;
ANALYZE TABLE t1;
# Cleanup
DROP TABLE t1;
SET GLOBAL use_stat_tables = DEFAULT;
--disconnect con1
--connection default
SET use_stat_tables = PREFERABLY;
CREATE TABLE t1 ( a INT ) ENGINE=MyISAM PARTITION BY HASH(a) PARTITIONS 2;
ALTER TABLE t1 ANALYZE PARTITION p1;
--replace_regex /\/\* xid=.* \*\//\/* XID *\// /Server ver: .*, Binlog ver: .*/Server ver: #, Binlog ver: #/ /table_id: [0-9]+/table_id: #/
SHOW BINLOG EVENTS;
SET use_stat_tables = DEFAULT;
DROP TABLE t1;

View File

@ -0,0 +1,58 @@
--source include/have_stat_tables.inc
--source include/master-slave.inc
--source include/have_binlog_format_row.inc
--echo #
--echo # Bug mdev-485: unexpected failure with replication of DROP/ALTER table
--echo # when RBR is on
--echo #
CREATE TABLE t1 ( a int, b int ) ENGINE=MyISAM;
INSERT INTO t1 VALUES (2,20), (1,20), (3,30);
ANALYZE TABLE t1;
DROP TABLE t1;
--sync_slave_with_master
--connection master
CREATE TABLE t1 ( a int, b int, INDEX idx1(b) ) ENGINE=MyISAM;
INSERT INTO t1 VALUES (2,20), (1,20), (3,30);
ANALYZE TABLE t1;
DROP INDEX idx1 ON t1;
--sync_slave_with_master
--connection master
DROP TABLE t1;
CREATE TABLE t1 ( a int, b int, INDEX idx1(b) ) ENGINE=MyISAM;
INSERT INTO t1 VALUES (2,20), (1,20), (3,30);
ANALYZE TABLE t1;
ALTER TABLE t1 DROP COLUMN b;
--sync_slave_with_master
--connection master
DROP TABLE t1;
CREATE TABLE t1 ( a int, b int, INDEX idx1(b) ) ENGINE=MyISAM;
INSERT INTO t1 VALUES (2,20), (1,20), (3,30);
ANALYZE TABLE t1;
ALTER TABLE t1 RENAME to s;
--sync_slave_with_master
--connection master
DROP TABLE s;
CREATE TABLE t1 ( a int, b int, INDEX idx1(b) ) ENGINE=MyISAM;
INSERT INTO t1 VALUES (2,20), (1,20), (3,30);
ANALYZE TABLE t1;
ALTER TABLE t1 CHANGE COLUMN b c int ;
--sync_slave_with_master
--connection master
DROP TABLE t1;
--source include/rpl_end.inc

View File

@ -0,0 +1,504 @@
--source include/have_stat_tables.inc
--source include/have_innodb.inc
--disable_warnings
drop table if exists t1,t2;
--enable_warnings
set @save_use_stat_tables=@@use_stat_tables;
DELETE FROM mysql.table_stat;
DELETE FROM mysql.column_stat;
DELETE FROM mysql.index_stat;
set use_stat_tables='preferably';
CREATE TABLE t1 (
a int NOT NULL PRIMARY KEY,
b varchar(32),
c char(16),
d date,
e double,
f bit(3),
INDEX idx1 (b, e),
INDEX idx2 (c, d),
INDEX idx3 (d),
INDEX idx4 (e, b, d)
) ENGINE= MYISAM;
INSERT INTO t1 VALUES
(0, NULL, NULL, NULL, NULL, NULL),
(7, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'dddddddd', '1990-05-15', 0.1, b'100'),
(17, 'vvvvvvvvvvvvv', 'aaaa', '1989-03-12', 0.01, b'101'),
(1, 'vvvvvvvvvvvvv', NULL, '1989-03-12', 0.01, b'100'),
(12, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'dddddddd', '1999-07-23', 0.112, b'001'),
(23, 'vvvvvvvvvvvvv', 'dddddddd', '1999-07-23', 0.1, b'100'),
(8, 'vvvvvvvvvvvvv', 'aaaa', '1999-07-23', 0.1, b'100'),
(22, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'aaaa', '1989-03-12', 0.112, b'001'),
(31, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'aaaa', '1999-07-23', 0.01, b'001'),
(10, NULL, 'aaaa', NULL, 0.01, b'010'),
(5, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'dddddddd', '1999-07-23', 0.1, b'100'),
(15, 'vvvvvvvvvvvvv', 'ccccccccc', '1990-05-15', 0.1, b'010'),
(30, NULL, 'bbbbbb', NULL, NULL, b'100'),
(38, 'zzzzzzzzzzzzzzzzzz', 'bbbbbb', NULL, NULL, NULL),
(18, 'zzzzzzzzzzzzzzzzzz', 'ccccccccc', '1990-05-15', 0.01, b'010'),
(9, 'yyy', 'bbbbbb', '1998-08-28', 0.01, NULL),
(29, 'vvvvvvvvvvvvv', 'dddddddd', '1999-07-23', 0.012, b'010'),
(3, 'yyy', 'dddddddd', '1990-05-15', 0.112, b'010'),
(39, 'zzzzzzzzzzzzzzzzzz', 'bbbbbb', NULL, 0.01, b'100'),
(14, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'ccccccccc', '1990-05-15', 0.1, b'100'),
(40, 'zzzzzzzzzzzzzzzzzz', 'bbbbbb', '1989-03-12', NULL, NULL),
(44, NULL, 'aaaa', '1989-03-12', NULL, b'010'),
(19, 'vvvvvvvvvvvvv', 'ccccccccc', '1990-05-15', 0.012, b'011'),
(21, 'zzzzzzzzzzzzzzzzzz', 'dddddddd', '1989-03-12', 0.112, b'100'),
(45, NULL, NULL, '1989-03-12', NULL, b'011'),
(2, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'ccccccccc', '1990-05-15', 0.1, b'001'),
(35, 'yyy', 'aaaa', '1990-05-15', 0.05, b'011'),
(4, 'vvvvvvvvvvvvv', 'dddddddd', '1999-07-23', 0.01, b'101'),
(47, NULL, 'aaaa', '1990-05-15', 0.05, b'010'),
(42, NULL, 'ccccccccc', '1989-03-12', 0.01, b'010'),
(32, NULL, 'bbbbbb', '1990-05-15', 0.01, b'011'),
(49, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww' , 'aaaa', '1990-05-15', NULL, NULL),
(43, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww' , 'bbbbbb', '1990-05-15', NULL, b'100'),
(37, 'yyy', NULL, '1989-03-12', 0.05, b'011'),
(41, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'ccccccccc', '1990-05-15', 0.05, NULL),
(34, 'yyy', NULL, NULL, NULL, NULL),
(33, 'zzzzzzzzzzzzzzzzzz', 'dddddddd', '1989-03-12', 0.05, b'011'),
(24, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'dddddddd', '1990-05-15', 0.01, b'101'),
(11, 'yyy', 'ccccccccc', '1999-07-23', 0.1, NULL),
(25, 'zzzzzzzzzzzzzzzzzz', 'bbb', '1989-03-12', 0.01, b'101');
ANALYZE TABLE t1;
SELECT * FROM mysql.table_stat;
SELECT * FROM mysql.column_stat;
SELECT * FROM mysql.index_stat;
SELECT COUNT(*) FROM t1;
SELECT * FROM mysql.column_stat
WHERE db_name='test' AND table_name='t1' AND column_name='a';
SELECT MIN(t1.a), MAX(t1.a),
(SELECT COUNT(*) FROM t1 WHERE t1.b IS NULL) /
(SELECT COUNT(*) FROM t1) AS "NULLS_RATIO(t1.a)",
(SELECT COUNT(t1.a) FROM t1) /
(SELECT COUNT(DISTINCT t1.a) FROM t1) AS "AVG_FREQUENCY(t1.a)"
FROM t1;
SELECT * FROM mysql.column_stat
WHERE db_name='test' AND table_name='t1' AND column_name='b';
SELECT MIN(t1.b), MAX(t1.b),
(SELECT COUNT(*) FROM t1 WHERE t1.b IS NULL) /
(SELECT COUNT(*) FROM t1) AS "NULLS_RATIO(t1.b)",
(SELECT COUNT(t1.b) FROM t1) /
(SELECT COUNT(DISTINCT t1.b) FROM t1) AS "AVG_FREQUENCY(t1.b)"
FROM t1;
SELECT * FROM mysql.column_stat
WHERE db_name='test' AND table_name='t1' AND column_name='c';
SELECT MIN(t1.c), MAX(t1.c),
(SELECT COUNT(*) FROM t1 WHERE t1.c IS NULL) /
(SELECT COUNT(*) FROM t1) AS "NULLS_RATIO(t1.c)",
(SELECT COUNT(t1.c) FROM t1) /
(SELECT COUNT(DISTINCT t1.c) FROM t1) AS "AVG_FREQUENCY(t1.c)"
FROM t1;
SELECT * FROM mysql.column_stat
WHERE db_name='test' AND table_name='t1' AND column_name='d';
SELECT MIN(t1.d), MAX(t1.d),
(SELECT COUNT(*) FROM t1 WHERE t1.d IS NULL) /
(SELECT COUNT(*) FROM t1) AS "NULLS_RATIO(t1.d)",
(SELECT COUNT(t1.d) FROM t1) /
(SELECT COUNT(DISTINCT t1.d) FROM t1) AS "AVG_FREQUENCY(t1.d)"
FROM t1;
SELECT * FROM mysql.column_stat
WHERE db_name='test' AND table_name='t1' AND column_name='e';
SELECT MIN(t1.e), MAX(t1.e),
(SELECT COUNT(*) FROM t1 WHERE t1.e IS NULL) /
(SELECT COUNT(*) FROM t1) AS "NULLS_RATIO(t1.e)",
(SELECT COUNT(t1.e) FROM t1) /
(SELECT COUNT(DISTINCT t1.e) FROM t1) AS "AVG_FREQUENCY(t1.e)"
FROM t1;
SELECT * FROM mysql.index_stat
WHERE db_name='test' AND table_name='t1' AND index_name='idx1';
SELECT
(SELECT COUNT(*) FROM t1 WHERE t1.b IS NOT NULL) /
(SELECT COUNT(DISTINCT t1.b) FROM t1 WHERE t1.b IS NOT NULL)
AS 'ARITY 1',
(SELECT COUNT(*) FROM t1 WHERE t1.b IS NOT NULL AND t1.e IS NOT NULL) /
(SELECT COUNT(DISTINCT t1.b, t1.e) FROM t1
WHERE t1.b IS NOT NULL AND t1.e IS NOT NULL)
AS 'ARITY 2';
SELECT * FROM mysql.index_stat
WHERE db_name='test' AND table_name='t1' AND index_name='idx2';
SELECT
(SELECT COUNT(*) FROM t1 WHERE t1.c IS NOT NULL) /
(SELECT COUNT(DISTINCT t1.c) FROM t1 WHERE t1.c IS NOT NULL)
AS 'ARITY 1',
(SELECT COUNT(*) FROM t1 WHERE t1.c IS NOT NULL AND t1.d IS NOT NULL) /
(SELECT COUNT(DISTINCT t1.c, t1.d) FROM t1
WHERE t1.c IS NOT NULL AND t1.d IS NOT NULL)
AS 'ARITY 2';
SELECT * FROM mysql.index_stat
WHERE db_name='test' AND table_name='t1' AND index_name='idx3';
SELECT
(SELECT COUNT(*) FROM t1 WHERE t1.d IS NOT NULL) /
(SELECT COUNT(DISTINCT t1.d) FROM t1 WHERE t1.d IS NOT NULL)
AS 'ARITY 1';
SELECT * FROM mysql.index_stat
WHERE db_name='test' AND table_name='t1' AND index_name='idx4';
SELECT
(SELECT COUNT(*) FROM t1 WHERE t1.e IS NOT NULL) /
(SELECT COUNT(DISTINCT t1.e) FROM t1 WHERE t1.e IS NOT NULL)
AS 'ARITY 1',
(SELECT COUNT(*) FROM t1 WHERE t1.e IS NOT NULL AND t1.b IS NOT NULL) /
(SELECT COUNT(DISTINCT t1.e, t1.b) FROM t1
WHERE t1.e IS NOT NULL AND t1.b IS NOT NULL)
AS 'ARITY 2',
(SELECT COUNT(*) FROM t1
WHERE t1.e IS NOT NULL AND t1.b IS NOT NULL AND t1.d IS NOT NULL) /
(SELECT COUNT(DISTINCT t1.e, t1.b, t1.d) FROM t1
WHERE t1.e IS NOT NULL AND t1.b IS NOT NULL AND t1.d IS NOT NULL)
AS 'ARITY 3';
CREATE TABLE t3 (
a int NOT NULL PRIMARY KEY,
b varchar(32),
c char(16),
INDEX idx (c)
) ENGINE=MYISAM;
INSERT INTO t3 VALUES
(0, NULL, NULL),
(7, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'dddddddd'),
(17, 'vvvvvvvvvvvvv', 'aaaa'),
(1, 'vvvvvvvvvvvvv', NULL),
(12, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'dddddddd'),
(23, 'vvvvvvvvvvvvv', 'dddddddd'),
(8, 'vvvvvvvvvvvvv', 'aaaa'),
(22, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'aaaa'),
(31, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'aaaa'),
(10, NULL, 'aaaa'),
(5, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'dddddddd'),
(15, 'vvvvvvvvvvvvv', 'ccccccccc'),
(30, NULL, 'bbbbbb'),
(38, 'zzzzzzzzzzzzzzzzzz', 'bbbbbb'),
(18, 'zzzzzzzzzzzzzzzzzz', 'ccccccccc'),
(9, 'yyy', 'bbbbbb'),
(29, 'vvvvvvvvvvvvv', 'dddddddd');
ANALYZE TABLE t3;
SELECT * FROM mysql.table_stat;
SELECT * FROM mysql.column_stat;
SELECT * FROM mysql.index_stat;
ALTER TABLE t1 RENAME TO s1;
SELECT * FROM mysql.table_stat;
SELECT * FROM mysql.column_stat;
SELECT * FROM mysql.index_stat;
RENAME TABLE s1 TO t1;
SELECT * FROM mysql.table_stat;
SELECT * FROM mysql.column_stat;
SELECT * FROM mysql.index_stat;
DROP TABLE t3;
SELECT * FROM mysql.table_stat;
SELECT * FROM mysql.column_stat;
SELECT * FROM mysql.index_stat;
CREATE TEMPORARY TABLE t0 (
a int NOT NULL PRIMARY KEY,
b varchar(32)
);
INSERT INTO t0 SELECT a,b FROM t1;
ALTER TABLE t1 CHANGE COLUMN b x varchar(32),
CHANGE COLUMN e y double;
SHOW CREATE TABLE t1;
SELECT * FROM mysql.column_stat;
ALTER TABLE t1 CHANGE COLUMN x b varchar(32),
CHANGE COLUMN y e double;
SHOW CREATE TABLE t1;
SELECT * FROM mysql.column_stat;
ALTER TABLE t1 RENAME TO s1, CHANGE COLUMN b x varchar(32);
SHOW CREATE TABLE s1;
SELECT * FROM mysql.table_stat;
SELECT * FROM mysql.column_stat;
SELECT * FROM mysql.index_stat;
ALTER TABLE s1 RENAME TO t1, CHANGE COLUMN x b varchar(32);
SHOW CREATE TABLE t1;
SELECT * FROM mysql.table_stat;
SELECT * FROM mysql.column_stat;
SELECT * FROM mysql.index_stat;
ALTER TABLE t1 CHANGE COLUMN b x varchar(30);
SHOW CREATE TABLE t1;
SELECT * FROM mysql.column_stat;
SELECT * FROM mysql.index_stat;
ALTER TABLE t1 CHANGE COLUMN x b varchar(32);
SHOW CREATE TABLE t1;
SELECT * FROM mysql.column_stat;
SELECT * FROM mysql.index_stat;
ANALYZE TABLE t1 PERSISTENT FOR COLUMNS(b) INDEXES(idx1, idx4);
SELECT * FROM mysql.column_stat;
SELECT * FROM mysql.index_stat;
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
eval
SELECT * INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/save_column_stat'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n'
FROM mysql.column_stat WHERE column_name='b';
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
eval
SELECT * INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/save_index_stat'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n'
FROM mysql.index_stat WHERE index_name IN ('idx1', 'idx4');
ALTER TABLE t1 CHANGE COLUMN b x varchar(30);
SHOW CREATE TABLE t1;
SELECT * FROM mysql.column_stat;
SELECT * FROM mysql.index_stat;
ALTER TABLE t1 CHANGE COLUMN x b varchar(32);
SHOW CREATE TABLE t1;
SELECT * FROM mysql.column_stat;
SELECT * FROM mysql.index_stat;
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
eval
LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/save_column_stat'
INTO TABLE mysql.column_stat
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n';
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
eval
LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/save_index_stat'
INTO TABLE mysql.index_stat
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n';
SELECT * FROM mysql.column_stat;
SELECT * FROM mysql.index_stat;
remove_file $MYSQLTEST_VARDIR/tmp/save_column_stat;
remove_file $MYSQLTEST_VARDIR/tmp/save_index_stat;
ALTER TABLE t1 DROP COLUMN b;
SHOW CREATE TABLE t1;
SELECT * FROM mysql.column_stat;
SELECT * FROM mysql.index_stat;
DROP INDEX idx2 ON t1;
SHOW CREATE TABLE t1;
SELECT * FROM mysql.index_stat;
DROP INDEX idx1 ON t1;
DROP INDEX idx4 ON t1;
SHOW CREATE TABLE t1;
ALTER TABLE t1 ADD COLUMN b varchar(32);
CREATE INDEX idx1 ON t1(b, e);
CREATE INDEX idx2 ON t1(c, d);
CREATE INDEX idx4 ON t1(e, b, d);
SHOW CREATE TABLE t1;
SELECT * FROM mysql.column_stat;
SELECT * FROM mysql.index_stat;
ANALYZE TABLE t1 PERSISTENT FOR COLUMNS(b) INDEXES(idx1, idx2, idx4);
SELECT * FROM mysql.column_stat;
SELECT * FROM mysql.index_stat;
UPDATE t1 SET b=(SELECT b FROM t0 WHERE t0.a= t1.a);
ANALYZE TABLE t1 PERSISTENT FOR COLUMNS(b) INDEXES(idx1, idx2, idx4);
SELECT * FROM mysql.column_stat;
SELECT * FROM mysql.index_stat;
ALTER TABLE t1 DROP COLUMN b,
DROP INDEX idx1, DROP INDEX idx2, DROP INDEX idx4;
SHOW CREATE TABLE t1;
SELECT * FROM mysql.column_stat;
SELECT * FROM mysql.index_stat;
ALTER TABLE t1 ADD COLUMN b varchar(32);
ALTER TABLE t1
ADD INDEX idx1 (b, e), ADD INDEX idx2 (c, d), ADD INDEX idx4 (e, b, d);
UPDATE t1 SET b=(SELECT b FROM t0 WHERE t0.a= t1.a);
SHOW CREATE TABLE t1;
SELECT * FROM mysql.column_stat;
SELECT * FROM mysql.index_stat;
ANALYZE TABLE t1 PERSISTENT FOR COLUMNS(b) INDEXES(idx1, idx2, idx4);
SELECT * FROM mysql.column_stat;
SELECT * FROM mysql.index_stat;
DELETE FROM mysql.table_stat;
DELETE FROM mysql.column_stat;
DELETE FROM mysql.index_stat;
ANALYZE TABLE t1 PERSISTENT FOR COLUMNS() INDEXES();
SELECT * FROM mysql.table_stat;
SELECT * FROM mysql.column_stat;
SELECT * FROM mysql.index_stat;
ANALYZE TABLE t1 PERSISTENT FOR COLUMNS(c,e,b) INDEXES(idx2,idx4);
SELECT * FROM mysql.table_stat;
SELECT * FROM mysql.column_stat;
SELECT * FROM mysql.index_stat;
DELETE FROM mysql.index_stat WHERE table_name='t1' AND index_name='primary';
SELECT * FROM mysql.index_stat;
ANALYZE TABLE t1 PERSISTENT FOR COLUMNS() INDEXES(primary);
SELECT * FROM mysql.index_stat;
DELETE FROM mysql.table_stat;
DELETE FROM mysql.column_stat;
DELETE FROM mysql.index_stat;
ANALYZE TABLE t1 PERSISTENT FOR COLUMNS ALL INDEXES ALL;
SELECT * FROM mysql.table_stat;
SELECT * FROM mysql.column_stat;
SELECT * FROM mysql.index_stat;
CREATE TABLE t2 LIKE t1;
ALTER TABLE t2 ENGINE=InnoDB;
INSERT INTO t2 SELECT * FROM t1;
ANALYZE TABLE t2;
SELECT * FROM mysql.table_stat;
SELECT * FROM mysql.column_stat ORDER BY column_name;
SELECT * FROM mysql.index_stat ORDER BY index_name, prefix_arity, table_name;
DELETE FROM mysql.table_stat;
DELETE FROM mysql.column_stat;
DELETE FROM mysql.index_stat;
ALTER TABLE t1
DROP INDEX idx1,
DROP INDEX idx4;
ALTER TABLE t1
MODIFY COLUMN b text,
ADD INDEX idx1 (b(4), e),
ADD INDEX idx4 (e, b(4), d);
ANALYZE TABLE t1;
SELECT * FROM mysql.column_stat;
SELECT * FROM mysql.index_stat;
DROP TABLE t1,t2;
DELETE FROM mysql.table_stat;
DELETE FROM mysql.column_stat;
DELETE FROM mysql.index_stat;
set use_stat_tables='never';
set names utf8;
CREATE DATABASE world;
use world;
--source include/world_schema_utf8.inc
--disable_query_log
--disable_result_log
--disable_warnings
--source include/world.inc
--enable_warnings
--enable_result_log
--enable_query_log
set use_stat_tables='preferably';
--disable_result_log
ANALYZE TABLE Country, City, CountryLanguage;
--enable_result_log
SELECT UPPER(db_name), UPPER(table_name), cardinality
FROM mysql.table_stat;
SELECT UPPER(db_name), UPPER(table_name),
column_name, min_value, max_value, nulls_ratio, avg_length, avg_frequency
FROM mysql.column_stat;
SELECT UPPER(db_name), UPPER(table_name),
index_name, prefix_arity, avg_frequency
FROM mysql.index_stat;
use test;
set use_stat_tables='never';
CREATE DATABASE world_innodb;
use world_innodb;
--source include/world_schema_utf8.inc
ALTER TABLE Country ENGINE=InnoDB;
ALTER TABLE City ENGINE=InnoDB;
ALTER TABLE CountryLanguage ENGINE=InnoDB;
--disable_query_log
--disable_result_log
--disable_warnings
--source include/world.inc
--enable_warnings
--enable_result_log
--enable_query_log
set use_stat_tables='preferably';
--disable_result_log
ANALYZE TABLE Country, City, CountryLanguage;
--enable_result_log
SELECT UPPER(db_name), UPPER(table_name), cardinality
FROM mysql.table_stat;
SELECT UPPER(db_name), UPPER(table_name),
column_name, min_value, max_value, nulls_ratio, avg_length, avg_frequency
FROM mysql.column_stat;
SELECT UPPER(db_name), UPPER(table_name),
index_name, prefix_arity, avg_frequency
FROM mysql.index_stat;
use test;
DROP DATABASE world;
SELECT UPPER(db_name), UPPER(table_name), cardinality
FROM mysql.table_stat;
SELECT UPPER(db_name), UPPER(table_name),
column_name, min_value, max_value, nulls_ratio, avg_length, avg_frequency
FROM mysql.column_stat;
SELECT UPPER(db_name), UPPER(table_name),
index_name, prefix_arity, avg_frequency
FROM mysql.index_stat;
DROP DATABASE world_innodb;
SELECT UPPER(db_name), UPPER(table_name), cardinality
FROM mysql.table_stat;
SELECT UPPER(db_name), UPPER(table_name),
column_name, min_value, max_value, nulls_ratio, avg_length, avg_frequency
FROM mysql.column_stat;
SELECT UPPER(db_name), UPPER(table_name),
index_name, prefix_arity, avg_frequency
FROM mysql.index_stat;
DELETE FROM mysql.table_stat;
DELETE FROM mysql.column_stat;
DELETE FROM mysql.index_stat;
set use_stat_tables=@save_use_stat_tables;

View File

@ -59,6 +59,11 @@ CREATE TABLE time_zone_transition_type ( Time_zone_id int unsigned NOT NULL,
CREATE TABLE time_zone_leap_second ( Transition_time bigint signed NOT NULL, Correction int signed NOT NULL, PRIMARY KEY TranTime (Transition_time) ) engine=MyISAM CHARACTER SET utf8 comment='Leap seconds information for time zones';
CREATE TABLE table_stat (db_name varchar(64) NOT NULL, table_name varchar(64) NOT NULL, cardinality bigint(21) unsigned DEFAULT NULL, PRIMARY KEY (db_name,table_name) ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Statistics on Tables';
CREATE TABLE column_stat (db_name varchar(64) NOT NULL, table_name varchar(64) NOT NULL, column_name varchar(64) NOT NULL, min_value varchar(255) DEFAULT NULL, max_value varchar(255) DEFAULT NULL, nulls_ratio double DEFAULT NULL, avg_length double DEFAULT NULL, avg_frequency double DEFAULT NULL, PRIMARY KEY (db_name,table_name,column_name) ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Statistics on Columns';
CREATE TABLE index_stat (db_name varchar(64) NOT NULL, table_name varchar(64) NOT NULL, index_name varchar(64) NOT NULL, prefix_arity int(11) unsigned NOT NULL, avg_frequency double DEFAULT NULL, PRIMARY KEY (db_name,table_name,index_name,prefix_arity) ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Statistics on Indexes';
# Run the mysql_fix_privilege_tables.sql using "mysql --force"
--exec $MYSQL --force test < $MYSQL_FIX_PRIVILEGE_TABLES
@ -72,7 +77,7 @@ CREATE TABLE time_zone_leap_second ( Transition_time bigint signed NOT NULL,
-- disable_query_log
# Drop all tables created by this test
DROP TABLE db, host, user, func, plugin, tables_priv, columns_priv, procs_priv, servers, help_category, help_keyword, help_relation, help_topic, proc, time_zone, time_zone_leap_second, time_zone_name, time_zone_transition, time_zone_transition_type, general_log, slow_log, event, ndb_binlog_index, proxies_priv;
DROP TABLE db, host, user, func, plugin, tables_priv, columns_priv, procs_priv, servers, help_category, help_keyword, help_relation, help_topic, proc, time_zone, time_zone_leap_second, time_zone_name, time_zone_transition, time_zone_transition_type, general_log, slow_log, event, ndb_binlog_index, proxies_priv, table_stat, column_stat, index_stat;
-- enable_query_log

View File

@ -66,6 +66,12 @@ CREATE TABLE servers ( Server_name char(64) NOT NULL DEFAULT '', Host char(64) N
INSERT INTO servers VALUES ('test','localhost','test','root','', 0,'','mysql','root');
CREATE TABLE table_stat (db_name varchar(64) NOT NULL, table_name varchar(64) NOT NULL, cardinality bigint(21) unsigned DEFAULT NULL, PRIMARY KEY (db_name,table_name) ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Statistics on Tables';
CREATE TABLE column_stat (db_name varchar(64) NOT NULL, table_name varchar(64) NOT NULL, column_name varchar(64) NOT NULL, min_value varchar(255) DEFAULT NULL, max_value varchar(255) DEFAULT NULL, nulls_ratio double DEFAULT NULL, avg_length double DEFAULT NULL, avg_frequency double DEFAULT NULL, PRIMARY KEY (db_name,table_name,column_name) ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Statistics on Columns';
CREATE TABLE index_stat (db_name varchar(64) NOT NULL, table_name varchar(64) NOT NULL, index_name varchar(64) NOT NULL, prefix_arity int(11) unsigned NOT NULL, avg_frequency double DEFAULT NULL, PRIMARY KEY (db_name,table_name,index_name,prefix_arity) ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Statistics on Indexes';
# Run the mysql_fix_privilege_tables.sql using "mysql --force"
--exec $MYSQL --force test < $MYSQL_FIX_PRIVILEGE_TABLES
@ -78,7 +84,7 @@ INSERT INTO servers VALUES ('test','localhost','test','root','', 0,'','mysql','r
-- disable_query_log
# Drop all tables created by this test
DROP TABLE db, host, user, func, plugin, tables_priv, columns_priv, procs_priv, servers, help_category, help_keyword, help_relation, help_topic, proc, time_zone, time_zone_leap_second, time_zone_name, time_zone_transition, time_zone_transition_type, general_log, slow_log, event, ndb_binlog_index, proxies_priv;
DROP TABLE db, host, user, func, plugin, tables_priv, columns_priv, procs_priv, servers, help_category, help_keyword, help_relation, help_topic, proc, time_zone, time_zone_leap_second, time_zone_name, time_zone_transition, time_zone_transition_type, general_log, slow_log, event, ndb_binlog_index, proxies_priv, table_stat, column_stat, index_stat;
-- enable_query_log

View File

@ -85,6 +85,12 @@ CREATE TABLE IF NOT EXISTS event ( db char(64) CHARACTER SET utf8 COLLATE utf8_b
CREATE TABLE IF NOT EXISTS ndb_binlog_index (Position BIGINT UNSIGNED NOT NULL, File VARCHAR(255) NOT NULL, epoch BIGINT UNSIGNED NOT NULL, inserts BIGINT UNSIGNED NOT NULL, updates BIGINT UNSIGNED NOT NULL, deletes BIGINT UNSIGNED NOT NULL, schemaops BIGINT UNSIGNED NOT NULL, PRIMARY KEY(epoch)) ENGINE=MYISAM;
CREATE TABLE table_stat (db_name varchar(64) NOT NULL, table_name varchar(64) NOT NULL, cardinality bigint(21) unsigned DEFAULT NULL, PRIMARY KEY (db_name,table_name) ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Statistics on Tables';
CREATE TABLE column_stat (db_name varchar(64) NOT NULL, table_name varchar(64) NOT NULL, column_name varchar(64) NOT NULL, min_value varchar(255) DEFAULT NULL, max_value varchar(255) DEFAULT NULL, nulls_ratio double DEFAULT NULL, avg_length double DEFAULT NULL, avg_frequency double DEFAULT NULL, PRIMARY KEY (db_name,table_name,column_name) ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Statistics on Columns';
CREATE TABLE index_stat (db_name varchar(64) NOT NULL, table_name varchar(64) NOT NULL, index_name varchar(64) NOT NULL, prefix_arity int(11) unsigned NOT NULL, avg_frequency double DEFAULT NULL, PRIMARY KEY (db_name,table_name,index_name,prefix_arity) ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Statistics on Indexes';
# Run the mysql_fix_privilege_tables.sql using "mysql --force"
--exec $MYSQL --force test < $MYSQL_FIX_PRIVILEGE_TABLES
@ -97,7 +103,7 @@ CREATE TABLE IF NOT EXISTS ndb_binlog_index (Position BIGINT UNSIGNED NOT NULL,
-- disable_query_log
# Drop all tables created by this test
DROP TABLE db, host, user, func, plugin, tables_priv, columns_priv, procs_priv, servers, help_category, help_keyword, help_relation, help_topic, proc, time_zone, time_zone_leap_second, time_zone_name, time_zone_transition, time_zone_transition_type, general_log, slow_log, event, ndb_binlog_index, proxies_priv;
DROP TABLE db, host, user, func, plugin, tables_priv, columns_priv, procs_priv, servers, help_category, help_keyword, help_relation, help_topic, proc, time_zone, time_zone_leap_second, time_zone_name, time_zone_transition, time_zone_transition_type, general_log, slow_log, event, ndb_binlog_index, proxies_priv, table_stat, column_stat, index_stat;
-- enable_query_log

View File

@ -482,3 +482,9 @@ CREATE TABLE IF NOT EXISTS proxies_priv (Host char(60) binary DEFAULT '' NOT NUL
-- Remember for later if proxies_priv table already existed
set @had_proxies_priv_table= @@warning_count != 0;
CREATE TABLE IF NOT EXISTS table_stat (db_name varchar(64) NOT NULL, table_name varchar(64) NOT NULL, cardinality bigint(21) unsigned DEFAULT NULL, PRIMARY KEY (db_name,table_name) ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Statistics on Tables';
CREATE TABLE IF NOT EXISTS column_stat (db_name varchar(64) NOT NULL, table_name varchar(64) NOT NULL, column_name varchar(64) NOT NULL, min_value varchar(255) DEFAULT NULL, max_value varchar(255) DEFAULT NULL, nulls_ratio decimal(12,4) DEFAULT NULL, avg_length decimal(12,4) DEFAULT NULL, avg_frequency decimal(12,4) DEFAULT NULL, PRIMARY KEY (db_name,table_name,column_name) ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Statistics on Columns';
CREATE TABLE IF NOT EXISTS index_stat (db_name varchar(64) NOT NULL, table_name varchar(64) NOT NULL, index_name varchar(64) NOT NULL, prefix_arity int(11) unsigned NOT NULL, avg_frequency decimal(12,4) DEFAULT NULL, PRIMARY KEY (db_name,table_name,index_name,prefix_arity) ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Statistics on Indexes';

View File

@ -62,7 +62,8 @@ SET (SQL_SOURCE
sql_list.cc sql_load.cc sql_manager.cc sql_parse.cc
sql_partition.cc sql_plugin.cc sql_prepare.cc sql_rename.cc
debug_sync.cc debug_sync.h
sql_repl.cc sql_select.cc sql_show.cc sql_state.c sql_string.cc
sql_repl.cc sql_select.cc sql_show.cc sql_state.c
sql_statistics.cc sql_string.cc
sql_table.cc sql_test.cc sql_trigger.cc sql_udf.cc sql_union.cc
sql_update.cc sql_view.cc strfunc.cc table.cc thr_malloc.cc
sql_time.cc tztime.cc uniques.cc unireg.cc item_xmlfunc.cc

View File

@ -76,7 +76,7 @@ const char field_separator=',';
((ulong) ((LL(1) << min(arg, 4) * 8) - LL(1)))
#define ASSERT_COLUMN_MARKED_FOR_READ DBUG_ASSERT(!table || (!table->read_set || bitmap_is_set(table->read_set, field_index)))
#define ASSERT_COLUMN_MARKED_FOR_WRITE_OR_COMPUTED DBUG_ASSERT(!table || (!table->write_set || bitmap_is_set(table->write_set, field_index) || bitmap_is_set(table->vcol_set, field_index)))
#define ASSERT_COLUMN_MARKED_FOR_WRITE_OR_COMPUTED DBUG_ASSERT(is_stat_field || !table || (!table->write_set || bitmap_is_set(table->write_set, field_index) || bitmap_is_set(table->vcol_set, field_index)))
#define FLAGSTR(S,F) ((S) & (F) ? #F " " : "")
@ -1180,11 +1180,11 @@ int Field_num::check_int(CHARSET_INFO *cs, const char *str, int length,
if (str == int_end || error == MY_ERRNO_EDOM)
{
ErrConvString err(str, length, cs);
push_warning_printf(table->in_use, MYSQL_ERROR::WARN_LEVEL_WARN,
push_warning_printf(get_thd(), MYSQL_ERROR::WARN_LEVEL_WARN,
ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
"integer", err.ptr(), field_name,
(ulong) table->in_use->warning_info->current_row_for_warning());
(ulong) get_thd()->warning_info->current_row_for_warning());
return 1;
}
/* Test if we have garbage at the end of the given string. */
@ -1253,7 +1253,7 @@ bool Field_num::get_int(CHARSET_INFO *cs, const char *from, uint len,
goto out_of_range;
}
}
if (table->in_use->count_cuted_fields &&
if (get_thd()->count_cuted_fields &&
check_int(cs, from, len, end, error))
return 1;
return 0;
@ -1324,13 +1324,16 @@ Field::Field(uchar *ptr_arg,uint32 length_arg,uchar *null_ptr_arg,
option_struct(0), key_start(0), part_of_key(0),
part_of_key_not_clustered(0), part_of_sortkey(0),
unireg_check(unireg_check_arg), field_length(length_arg),
null_bit(null_bit_arg), is_created_from_null_item(FALSE), vcol_info(0),
null_bit(null_bit_arg), is_created_from_null_item(FALSE),
read_stats(NULL), collected_stats(0),
vcol_info(0),
stored_in_db(TRUE)
{
flags=null_ptr ? 0: NOT_NULL_FLAG;
comment.str= (char*) "";
comment.length=0;
field_index= 0;
field_index= 0;
is_stat_field= FALSE;
}
@ -1430,10 +1433,11 @@ int Field::store(const char *to, uint length, CHARSET_INFO *cs,
enum_check_fields check_level)
{
int res;
enum_check_fields old_check_level= table->in_use->count_cuted_fields;
table->in_use->count_cuted_fields= check_level;
THD *thd= get_thd();
enum_check_fields old_check_level= thd->count_cuted_fields;
thd->count_cuted_fields= check_level;
res= store(to, length, cs);
table->in_use->count_cuted_fields= old_check_level;
thd->count_cuted_fields= old_check_level;
return res;
}
@ -1855,6 +1859,32 @@ Field *Field::clone(MEM_ROOT *root, TABLE *new_table)
}
Field *Field::clone(MEM_ROOT *root, TABLE *new_table, my_ptrdiff_t diff,
bool stat_flag)
{
Field *tmp;
if ((tmp= (Field*) memdup_root(root,(char*) this,size_of())))
{
tmp->init(new_table);
tmp->move_field_offset(diff);
}
tmp->is_stat_field= stat_flag;
return tmp;
}
Field *Field::clone(MEM_ROOT *root, my_ptrdiff_t diff)
{
Field *tmp;
if ((tmp= (Field*) memdup_root(root,(char*) this,size_of())))
{
tmp->move_field_offset(diff);
}
return tmp;
}
/****************************************************************************
Field_null, a field that always return NULL
****************************************************************************/
@ -1969,7 +1999,7 @@ int Field_decimal::store(const char *from_arg, uint len, CHARSET_INFO *cs)
uchar *left_wall,*right_wall;
uchar tmp_char;
/*
To remember if table->in_use->cuted_fields has already been incremented,
To remember if get_thd()->cuted_fields has already been incremented,
to do that only once
*/
bool is_cuted_fields_incr=0;
@ -2060,7 +2090,7 @@ int Field_decimal::store(const char *from_arg, uint len, CHARSET_INFO *cs)
it makes the code easer to read.
*/
if (table->in_use->count_cuted_fields)
if (get_thd()->count_cuted_fields)
{
// Skip end spaces
for (;from != end && my_isspace(&my_charset_bin, *from); from++) ;
@ -2212,7 +2242,7 @@ int Field_decimal::store(const char *from_arg, uint len, CHARSET_INFO *cs)
/*
Write digits of the frac_% parts ;
Depending on table->in_use->count_cutted_fields, we may also want
Depending on get_thd()->count_cutted_fields, we may also want
to know if some non-zero tail of these parts will
be truncated (for example, 0.002->0.00 will generate a warning,
while 0.000->0.00 will not)
@ -2230,7 +2260,7 @@ int Field_decimal::store(const char *from_arg, uint len, CHARSET_INFO *cs)
{
if (pos == right_wall)
{
if (table->in_use->count_cuted_fields && !is_cuted_fields_incr)
if (get_thd()->count_cuted_fields && !is_cuted_fields_incr)
break; // Go on below to see if we lose non zero digits
return 0;
}
@ -2651,20 +2681,21 @@ int Field_new_decimal::store(const char *from, uint length,
ASSERT_COLUMN_MARKED_FOR_WRITE_OR_COMPUTED;
int err;
my_decimal decimal_value;
THD *thd= get_thd();
DBUG_ENTER("Field_new_decimal::store(char*)");
if ((err= str2my_decimal(E_DEC_FATAL_ERROR &
~(E_DEC_OVERFLOW | E_DEC_BAD_NUM),
from, length, charset_arg,
&decimal_value)) &&
table->in_use->abort_on_warning)
thd->abort_on_warning)
{
ErrConvString errmsg(from, length, &my_charset_bin);
push_warning_printf(table->in_use, MYSQL_ERROR::WARN_LEVEL_WARN,
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
"decimal", errmsg.ptr(), field_name,
(ulong) table->in_use->warning_info->current_row_for_warning());
(ulong) thd->warning_info->current_row_for_warning());
DBUG_RETURN(err);
}
@ -2680,11 +2711,11 @@ int Field_new_decimal::store(const char *from, uint length,
case E_DEC_BAD_NUM:
{
ErrConvString errmsg(from, length, &my_charset_bin);
push_warning_printf(table->in_use, MYSQL_ERROR::WARN_LEVEL_WARN,
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
"decimal", errmsg.ptr(), field_name,
(ulong) table->in_use->warning_info->
(ulong) thd->warning_info->
current_row_for_warning());
my_decimal_set_zero(&decimal_value);
break;
@ -2712,6 +2743,7 @@ int Field_new_decimal::store(double nr)
ASSERT_COLUMN_MARKED_FOR_WRITE_OR_COMPUTED;
my_decimal decimal_value;
int err;
THD *thd= get_thd();
DBUG_ENTER("Field_new_decimal::store(double)");
err= double2my_decimal(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW, nr,
@ -2721,11 +2753,11 @@ int Field_new_decimal::store(double nr)
if (check_overflow(err))
set_value_on_overflow(&decimal_value, decimal_value.sign());
/* Only issue a warning if store_value doesn't issue an warning */
table->in_use->got_warning= 0;
thd->got_warning= 0;
}
if (store_value(&decimal_value))
err= 1;
else if (err && !table->in_use->got_warning)
else if (err && !thd->got_warning)
err= warn_if_overflow(err);
DBUG_RETURN(err);
}
@ -2743,11 +2775,11 @@ int Field_new_decimal::store(longlong nr, bool unsigned_val)
if (check_overflow(err))
set_value_on_overflow(&decimal_value, decimal_value.sign());
/* Only issue a warning if store_value doesn't issue an warning */
table->in_use->got_warning= 0;
get_thd()->got_warning= 0;
}
if (store_value(&decimal_value))
err= 1;
else if (err && !table->in_use->got_warning)
else if (err && !get_thd()->got_warning)
err= warn_if_overflow(err);
return err;
}
@ -3643,7 +3675,7 @@ longlong Field_long::val_int(void)
ASSERT_COLUMN_MARKED_FOR_READ;
int32 j;
/* See the comment in Field_long::store(long long) */
DBUG_ASSERT(table->in_use == current_thd);
DBUG_ASSERT(!table || table->in_use == current_thd);
j=sint4korr(ptr);
return unsigned_flag ? (longlong) (uint32) j : (longlong) j;
}
@ -3725,7 +3757,7 @@ int Field_longlong::store(const char *from,uint len,CHARSET_INFO *cs)
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
error= 1;
}
else if (table->in_use->count_cuted_fields &&
else if (get_thd()->count_cuted_fields &&
check_int(cs, from, len, end, error))
error= 1;
else
@ -3877,7 +3909,7 @@ int Field_float::store(const char *from,uint len,CHARSET_INFO *cs)
char *end;
double nr= my_strntod(cs,(char*) from,len,&end,&error);
if (error || (!len || ((uint) (end-from) != len &&
table->in_use->count_cuted_fields)))
get_thd()->count_cuted_fields)))
{
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
(error ? ER_WARN_DATA_OUT_OF_RANGE : WARN_DATA_TRUNCATED), 1);
@ -4065,7 +4097,7 @@ int Field_double::store(const char *from,uint len,CHARSET_INFO *cs)
char *end;
double nr= my_strntod(cs,(char*) from, len, &end, &error);
if (error || (!len || ((uint) (end-from) != len &&
table->in_use->count_cuted_fields)))
get_thd()->count_cuted_fields)))
{
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
(error ? ER_WARN_DATA_OUT_OF_RANGE : WARN_DATA_TRUNCATED), 1);
@ -4513,10 +4545,11 @@ int Field_timestamp::store_TIME_with_warning(THD *thd, MYSQL_TIME *l_time,
int Field_timestamp::store_time_dec(MYSQL_TIME *ltime, uint dec)
{
THD *thd= table->in_use;
int unused;
MYSQL_TIME l_time= *ltime;
ErrConvTime str(ltime);
THD *thd= get_thd();
bool valid= !check_date(&l_time, pack_time(&l_time) != 0,
(thd->variables.sql_mode & MODE_NO_ZERO_DATE) |
MODE_NO_ZERO_IN_DATE, &unused);
@ -4531,7 +4564,7 @@ int Field_timestamp::store(const char *from,uint len,CHARSET_INFO *cs)
int error;
int have_smth_to_conv;
ErrConvString str(from, len, cs);
THD *thd= table->in_use;
THD *thd= get_thd();
/* We don't want to store invalid or fuzzy datetime values in TIMESTAMP */
have_smth_to_conv= (str_to_datetime(cs, from, len, &l_time,
@ -4548,7 +4581,7 @@ int Field_timestamp::store(double nr)
MYSQL_TIME l_time;
int error;
ErrConvDouble str(nr);
THD *thd= table->in_use;
THD *thd= get_thd();
longlong tmp= double_to_datetime(nr, &l_time, (thd->variables.sql_mode &
MODE_NO_ZERO_DATE) |
@ -4562,7 +4595,7 @@ int Field_timestamp::store(longlong nr, bool unsigned_val)
MYSQL_TIME l_time;
int error;
ErrConvInteger str(nr);
THD *thd= table->in_use;
THD *thd= get_thd();
/* We don't want to store invalid or fuzzy datetime values in TIMESTAMP */
longlong tmp= number_to_datetime(nr, 0, &l_time, (thd->variables.sql_mode &
@ -4654,7 +4687,7 @@ String *Field_timestamp::val_str(String *val_buffer, String *val_ptr)
bool Field_timestamp::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate)
{
THD *thd= table->in_use;
THD *thd= get_thd();
thd->time_zone_used= 1;
ulong sec_part;
my_time_t temp= get_timestamp(&sec_part);
@ -4707,7 +4740,7 @@ void Field_timestamp::sql_type(String &res) const
int Field_timestamp::set_time()
{
THD *thd= table->in_use;
THD *thd= get_thd();
set_notnull();
store_TIME(thd->query_start(), 0);
return 0;
@ -4856,7 +4889,7 @@ int Field_timestamp_hires::store_decimal(const my_decimal *d)
int error;
MYSQL_TIME ltime;
longlong tmp;
THD *thd= table->in_use;
THD *thd= get_thd();
ErrConvDecimal str(d);
if (my_decimal2seconds(d, &nr, &sec_part))
@ -4874,7 +4907,7 @@ int Field_timestamp_hires::store_decimal(const my_decimal *d)
int Field_timestamp_hires::set_time()
{
THD *thd= table->in_use;
THD *thd= get_thd();
set_notnull();
store_TIME(thd->query_start(), thd->query_start_sec_part());
return 0;
@ -4993,7 +5026,7 @@ int Field_temporal::store(const char *from,uint len,CHARSET_INFO *cs)
MYSQL_TIME ltime;
int error;
enum enum_mysql_timestamp_type func_res;
THD *thd= table->in_use;
THD *thd= get_thd();
ErrConvString str(from, len, cs);
func_res= str_to_datetime(cs, from, len, &ltime,
@ -5010,7 +5043,7 @@ int Field_temporal::store(double nr)
{
int error= 0;
MYSQL_TIME ltime;
THD *thd= table->in_use;
THD *thd= get_thd();
ErrConvDouble str(nr);
longlong tmp= double_to_datetime(nr, &ltime,
@ -5028,7 +5061,7 @@ int Field_temporal::store(longlong nr, bool unsigned_val)
int error;
MYSQL_TIME ltime;
longlong tmp;
THD *thd= table->in_use;
THD *thd= get_thd();
ErrConvInteger str(nr);
tmp= number_to_datetime(nr, 0, &ltime, (TIME_FUZZY_DATE |
@ -5093,7 +5126,7 @@ int Field_time::store(const char *from,uint len,CHARSET_INFO *cs)
int was_cut;
int have_smth_to_conv=
str_to_time(cs, from, len, &ltime,
table->in_use->variables.sql_mode &
get_thd()->variables.sql_mode &
(MODE_NO_ZERO_DATE | MODE_NO_ZERO_IN_DATE |
MODE_INVALID_DATES),
&was_cut) > MYSQL_TIMESTAMP_ERROR;
@ -5199,7 +5232,7 @@ String *Field_time::val_str(String *val_buffer,
bool Field_time::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate)
{
THD *thd= table->in_use;
THD *thd= get_thd();
if (!(fuzzydate & (TIME_FUZZY_DATE|TIME_TIME_ONLY)))
{
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
@ -5389,7 +5422,7 @@ int Field_year::store(const char *from, uint len,CHARSET_INFO *cs)
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
return 1;
}
if (table->in_use->count_cuted_fields &&
if (get_thd()->count_cuted_fields &&
(error= check_int(cs, from, len, end, error)))
{
if (error == 1) /* empty or incorrect string */
@ -5849,7 +5882,7 @@ int Field_datetime_hires::store_decimal(const my_decimal *d)
int error;
MYSQL_TIME ltime;
longlong tmp;
THD *thd= table->in_use;
THD *thd= get_thd();
ErrConvDecimal str(d);
if (my_decimal2seconds(d, &nr, &sec_part))
@ -5986,7 +6019,9 @@ check_string_copy_error(Field_str *field,
{
const char *pos;
char tmp[32];
THD *thd= field->table->in_use;
THD *thd;
thd= field->get_thd();
if (!(pos= well_formed_error_pos) &&
!(pos= cannot_convert_error_pos))
@ -6028,11 +6063,12 @@ int
Field_longstr::report_if_important_data(const char *pstr, const char *end,
bool count_spaces)
{
if ((pstr < end) && table->in_use->count_cuted_fields)
THD *thd= get_thd();
if ((pstr < end) && thd->count_cuted_fields)
{
if (test_if_important_data(field_charset, pstr, end))
{
if (table->in_use->abort_on_warning)
if (thd->abort_on_warning)
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_DATA_TOO_LONG, 1);
else
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
@ -6059,7 +6095,7 @@ int Field_string::store(const char *from,uint length,CHARSET_INFO *cs)
const char *from_end_pos;
/* See the comment for Field_long::store(long long) */
DBUG_ASSERT(table->in_use == current_thd);
DBUG_ASSERT(!table || table->in_use == current_thd);
copy_length= well_formed_copy_nchars(field_charset,
(char*) ptr, field_length,
@ -6105,7 +6141,7 @@ int Field_str::store(double nr)
if (error)
{
if (table->in_use->abort_on_warning)
if (get_thd()->abort_on_warning)
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_DATA_TOO_LONG, 1);
else
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
@ -6165,7 +6201,7 @@ double Field_string::val_real(void)
double result;
result= my_strntod(cs,(char*) ptr,field_length,&end,&error);
if (!table->in_use->no_errors &&
if (!get_thd()->no_errors &&
(error || (field_length != (uint32)(end - (char*) ptr) &&
!check_if_only_end_space(cs, end,
(char*) ptr + field_length))))
@ -6189,7 +6225,7 @@ longlong Field_string::val_int(void)
longlong result;
result= my_strntoll(cs, (char*) ptr,field_length,10,&end,&error);
if (!table->in_use->no_errors &&
if (!get_thd()->no_errors &&
(error || (field_length != (uint32)(end - (char*) ptr) &&
!check_if_only_end_space(cs, end,
(char*) ptr + field_length))))
@ -6209,9 +6245,9 @@ String *Field_string::val_str(String *val_buffer __attribute__((unused)),
{
ASSERT_COLUMN_MARKED_FOR_READ;
/* See the comment for Field_long::store(long long) */
DBUG_ASSERT(table->in_use == current_thd);
DBUG_ASSERT(!table || table->in_use == current_thd);
uint length;
if (table->in_use->variables.sql_mode &
if (get_thd()->variables.sql_mode &
MODE_PAD_CHAR_TO_FULL_LENGTH)
length= my_charpos(field_charset, ptr, ptr + field_length,
field_length / field_charset->mbmaxlen);
@ -6228,7 +6264,7 @@ my_decimal *Field_string::val_decimal(my_decimal *decimal_value)
ASSERT_COLUMN_MARKED_FOR_READ;
int err= str2my_decimal(E_DEC_FATAL_ERROR, (char*) ptr, field_length,
charset(), decimal_value);
if (!table->in_use->no_errors && err)
if (!get_thd()->no_errors && err)
{
ErrConvString errmsg((char*) ptr, field_length, charset());
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
@ -6612,7 +6648,7 @@ double Field_varstring::val_real(void)
uint length= length_bytes == 1 ? (uint) *ptr : uint2korr(ptr);
result= my_strntod(cs, (char*)ptr+length_bytes, length, &end, &error);
if (!table->in_use->no_errors &&
if (!get_thd()->no_errors &&
(error || (length != (uint)(end - (char*)ptr+length_bytes) &&
!check_if_only_end_space(cs, end, (char*)ptr+length_bytes+length))))
{
@ -6635,7 +6671,7 @@ longlong Field_varstring::val_int(void)
longlong result= my_strntoll(cs, (char*) ptr+length_bytes, length, 10,
&end, &error);
if (!table->in_use->no_errors &&
if (!get_thd()->no_errors &&
(error || (length != (uint)(end - (char*)ptr+length_bytes) &&
!check_if_only_end_space(cs, end, (char*)ptr+length_bytes+length))))
{
@ -6664,7 +6700,7 @@ my_decimal *Field_varstring::val_decimal(my_decimal *decimal_value)
int error= str2my_decimal(E_DEC_FATAL_ERROR, (char*) ptr+length_bytes, length,
cs, decimal_value);
if (!table->in_use->no_errors && error)
if (!get_thd()->no_errors && error)
{
push_numerical_conversion_warning(current_thd, (char*)ptr+length_bytes,
length, cs, "DECIMAL",
@ -7645,7 +7681,7 @@ int Field_enum::store(const char *from,uint length,CHARSET_INFO *cs)
tmp=0;
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
}
if (!table->in_use->count_cuted_fields)
if (!get_thd()->count_cuted_fields)
err= 0;
}
else
@ -7669,7 +7705,7 @@ int Field_enum::store(longlong nr, bool unsigned_val)
if ((ulonglong) nr > typelib->count || nr == 0)
{
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
if (nr != 0 || table->in_use->count_cuted_fields)
if (nr != 0 || get_thd()->count_cuted_fields)
{
nr= 0;
error= 1;
@ -8199,7 +8235,7 @@ int Field_bit::store(const char *from, uint length, CHARSET_INFO *cs)
{
set_rec_bits((1 << bit_len) - 1, bit_ptr, bit_ofs, bit_len);
memset(ptr, 0xff, bytes_in_rec);
if (table->in_use->really_abort_on_warning())
if (get_thd()->really_abort_on_warning())
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_DATA_TOO_LONG, 1);
else
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
@ -8634,7 +8670,7 @@ int Field_bit_as_char::store(const char *from, uint length, CHARSET_INFO *cs)
memset(ptr, 0xff, bytes_in_rec);
if (bits)
*ptr&= ((1 << bits) - 1); /* set first uchar */
if (table->in_use->really_abort_on_warning())
if (get_thd()->really_abort_on_warning())
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_DATA_TOO_LONG, 1);
else
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
@ -9750,7 +9786,7 @@ void Field::set_datetime_warning(MYSQL_ERROR::enum_warning_level level,
uint code, const ErrConv *str,
timestamp_type ts_type, int cuted_increment)
{
THD *thd= table->in_use;
THD *thd= get_thd();
if (thd->really_abort_on_warning() && level >= MYSQL_ERROR::WARN_LEVEL_WARN)
make_truncated_value_warning(thd, level, str, ts_type, field_name);
else

View File

@ -36,6 +36,8 @@ class Protocol;
class Create_field;
class Relay_log_info;
class Field;
class Column_statistics;
class Column_statistics_collected;
enum enum_check_fields
{
@ -66,6 +68,8 @@ enum Derivation
/* The length of the header part for each virtual column in the .frm file */
#define FRM_VCOL_HEADER_SIZE(b) (3 + test(b))
class Count_distinct_field;
struct ha_field_option_struct;
struct st_cache_field;
@ -216,6 +220,19 @@ public:
*/
bool is_created_from_null_item;
bool is_stat_field; /* TRUE in Field objects created for column min/max values */
/*
This structure is used for statistical data on the column
that has been read from the statistical table column_stat
*/
Column_statistics *read_stats;
/*
This structure is used for statistical data on the column that
is collected by the function collect_statistics_for_table
*/
Column_statistics_collected *collected_stats;
/*
This is additional data provided for any computed(virtual) field.
In particular it includes a pointer to the item by which this field
@ -308,6 +325,26 @@ public:
virtual uint32 data_length() { return pack_length(); }
virtual uint32 sort_length() const { return pack_length(); }
/*
Get the number bytes occupied by the value in the field.
CHAR values are stripped of trailing spaces.
Flexible values are stripped of their length.
*/
virtual uint32 value_length()
{
uint len;
if (!zero_pack() &&
(type() == MYSQL_TYPE_STRING &&
(len= pack_length()) >= 4 && len < 256))
{
uchar *str, *end;
for (str= ptr, end= str+len; end > str && end[-1] == ' '; end--) {}
len=(uint) (end-str);
return len;
}
return data_length();
}
/**
Get the maximum size of the data in packed format.
@ -349,6 +386,36 @@ public:
{ return cmp(a, b); }
virtual int key_cmp(const uchar *str, uint length)
{ return cmp(ptr,str); }
/*
Update the value m of the 'min_val' field with the current value v
of this field if force_update is set to TRUE or if v < m.
Return TRUE if the value has been updated.
*/
virtual bool update_min(Field *min_val, bool force_update)
{
bool update_fl= force_update || cmp(ptr, min_val->ptr) < 0;
if (update_fl)
{
min_val->set_notnull();
memcpy(min_val->ptr, ptr, pack_length());
}
return update_fl;
}
/*
Update the value m of the 'max_val' field with the current value v
of this field if force_update is set to TRUE or if v > m.
Return TRUE if the value has been updated.
*/
virtual bool update_max(Field *max_val, bool force_update)
{
bool update_fl= force_update || cmp(ptr, max_val->ptr) > 0;
if (update_fl)
{
max_val->set_notnull();
memcpy(max_val->ptr, ptr, pack_length());
}
return update_fl;
}
virtual uint decimals() const { return 0; }
/*
Caller beware: sql_type can change str.Ptr, so check
@ -384,6 +451,8 @@ public:
*/
inline bool real_maybe_null(void) { return null_ptr != 0; }
inline THD *get_thd() { return table ? table->in_use : current_thd; }
enum {
LAST_NULL_BYTE_UNDEF= 0
};
@ -420,6 +489,9 @@ public:
uchar *new_ptr, uchar *new_null_ptr,
uint new_null_bit);
Field *clone(MEM_ROOT *mem_root, TABLE *new_table);
Field *clone(MEM_ROOT *mem_root, TABLE *new_table, my_ptrdiff_t diff,
bool stat_flag= FALSE);
Field *clone(MEM_ROOT *mem_root, my_ptrdiff_t diff);
inline void move_field(uchar *ptr_arg,uchar *null_ptr_arg,uchar null_bit_arg)
{
ptr=ptr_arg; null_ptr=null_ptr_arg; null_bit=null_bit_arg;
@ -1811,6 +1883,10 @@ public:
int cmp_binary(const uchar *a,const uchar *b, uint32 max_length=~0L);
int key_cmp(const uchar *,const uchar*);
int key_cmp(const uchar *str, uint length);
/* Never update the value of min_val for a blob field */
bool update_min(Field *min_val, bool force_update) { return FALSE; }
/* Never update the value of max_val for a blob field */
bool update_max(Field *max_val, bool force_update) { return FALSE; }
uint32 key_length() const { return 0; }
void sort_string(uchar *buff,uint length);
uint32 pack_length() const
@ -1828,6 +1904,7 @@ public:
{ return (uint32) (packlength); }
uint row_pack_length() { return pack_length_no_ptr(); }
uint32 sort_length() const;
uint32 value_length() { return get_length(); }
virtual uint32 max_data_length() const
{
return (uint32) (((ulonglong) 1 << (packlength*8)) -1);
@ -2099,6 +2176,28 @@ public:
{ return cmp_binary((uchar *) a, (uchar *) b); }
int key_cmp(const uchar *str, uint length);
int cmp_offset(uint row_offset);
bool update_min(Field *min_val, bool force_update)
{
longlong val= val_int();
bool update_fl= force_update || val < min_val->val_int();
if (update_fl)
{
min_val->set_notnull();
min_val->store(val, FALSE);
}
return update_fl;
}
bool update_max(Field *max_val, bool force_update)
{
longlong val= val_int();
bool update_fl= force_update || val > max_val->val_int();
if (update_fl)
{
max_val->set_notnull();
max_val->store(val, FALSE);
}
return update_fl;
}
void get_image(uchar *buff, uint length, CHARSET_INFO *cs)
{ get_key_image(buff, length, itRAW); }
void set_image(const uchar *buff,uint length, CHARSET_INFO *cs)

View File

@ -636,13 +636,24 @@ void Item_sum::cleanup()
@retval > 0 if key1 > key2
*/
static int simple_str_key_cmp(void* arg, uchar* key1, uchar* key2)
int simple_str_key_cmp(void* arg, uchar* key1, uchar* key2)
{
Field *f= (Field*) arg;
return f->cmp(key1, key2);
}
C_MODE_START
int count_distinct_walk(void *elem, element_count count, void *arg)
{
(*((ulonglong*)arg))++;
return 0;
}
C_MODE_END
/**
Correctly compare composite keys.
@ -710,13 +721,13 @@ C_MODE_START
/* Declarations for auxilary C-callbacks */
static int simple_raw_key_cmp(void* arg, const void* key1, const void* key2)
int simple_raw_key_cmp(void* arg, const void* key1, const void* key2)
{
return memcmp(key1, key2, *(uint *) arg);
}
static int item_sum_distinct_walk(void *element, element_count num_of_dups,
int item_sum_distinct_walk(void *element, element_count num_of_dups,
void *item)
{
return ((Aggregator_distinct*) (item))->unique_walk_function(element);

View File

@ -1201,7 +1201,7 @@ bool DsMrr_impl::setup_buffer_sharing(uint key_size_in_keybuf,
uint parts= my_count_bits(key_tuple_map);
ulong rpc;
ulonglong rowids_size= rowid_buf_elem_size;
if ((rpc= key_info->rec_per_key[parts - 1]))
if ((rpc= key_info->real_rec_per_key(parts - 1)))
rowids_size= rowid_buf_elem_size * rpc;
double fraction_for_rowids=

View File

@ -488,6 +488,7 @@ ulong executed_events=0;
query_id_t global_query_id;
my_atomic_rwlock_t global_query_id_lock;
my_atomic_rwlock_t thread_running_lock;
my_atomic_rwlock_t statistics_lock;
ulong aborted_threads, aborted_connects;
ulong delayed_insert_timeout, delayed_insert_limit, delayed_queue_size;
ulong delayed_insert_threads, delayed_insert_writes, delayed_rows_in_use;
@ -1872,6 +1873,7 @@ void clean_up(bool print_message)
sys_var_end();
my_atomic_rwlock_destroy(&global_query_id_lock);
my_atomic_rwlock_destroy(&thread_running_lock);
my_atomic_rwlock_destroy(&statistics_lock);
mysql_mutex_lock(&LOCK_thread_count);
DBUG_PRINT("quit", ("got thread count lock"));
ready_to_exit=1;
@ -6084,6 +6086,7 @@ error:
*/
struct my_option my_long_options[]=
{
{"help", '?', "Display this help and exit.",
&opt_help, &opt_help, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
@ -7308,6 +7311,7 @@ static int mysql_init_variables(void)
global_query_id= thread_id= 1L;
my_atomic_rwlock_init(&global_query_id_lock);
my_atomic_rwlock_init(&thread_running_lock);
my_atomic_rwlock_init(&statistics_lock);
strmov(server_version, MYSQL_SERVER_VERSION);
threads.empty();
thread_cache.empty();

View File

@ -105,6 +105,7 @@ extern char* opt_secure_backup_file_priv;
extern size_t opt_secure_backup_file_priv_len;
extern my_bool opt_log_slow_admin_statements, opt_log_slow_slave_statements;
extern my_bool sp_automatic_privileges, opt_noacl;
extern ulong use_stat_tables;
extern my_bool opt_old_style_user_limits, trust_function_creators;
extern uint opt_crash_binlog_innodb;
extern char *shared_memory_base_name, *mysqld_unix_port;
@ -433,6 +434,7 @@ enum enum_query_type
typedef int64 query_id_t;
extern query_id_t global_query_id;
extern my_atomic_rwlock_t global_query_id_lock;
extern my_atomic_rwlock_t statistics_lock;
void unireg_end(void) __attribute__((noreturn));

View File

@ -2914,7 +2914,7 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use,
DBUG_PRINT("enter",("keys_to_use: %lu prev_tables: %lu const_tables: %lu",
(ulong) keys_to_use.to_ulonglong(), (ulong) prev_tables,
(ulong) const_tables));
DBUG_PRINT("info", ("records: %lu", (ulong) head->file->stats.records));
DBUG_PRINT("info", ("records: %lu", (ulong) head->stat_records()));
delete quick;
quick=0;
needed_reg.clear_all();
@ -2922,7 +2922,7 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use,
DBUG_ASSERT(!head->is_filled_at_execution());
if (keys_to_use.is_clear_all() || head->is_filled_at_execution())
DBUG_RETURN(0);
records= head->file->stats.records;
records= head->stat_records();
if (!records)
records++; /* purecov: inspected */
scan_time= (double) records / TIME_FOR_COMPARE + 1;
@ -3059,7 +3059,7 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use,
if (group_trp)
{
param.table->quick_condition_rows= min(group_trp->records,
head->file->stats.records);
head->stat_records());
if (group_trp->read_cost < best_read_time)
{
best_trp= group_trp;
@ -4665,7 +4665,7 @@ TABLE_READ_PLAN *get_best_disjunct_quick(PARAM *param, SEL_IMERGE *imerge,
DBUG_PRINT("info", ("index_merge scans cost %g", imerge_cost));
if (imerge_too_expensive || (imerge_cost > read_time) ||
((non_cpk_scan_records+cpk_scan_records >=
param->table->file->stats.records) &&
param->table->stat_records()) &&
read_time != DBL_MAX))
{
/*
@ -4736,7 +4736,7 @@ TABLE_READ_PLAN *get_best_disjunct_quick(PARAM *param, SEL_IMERGE *imerge,
imerge_trp->read_cost= imerge_cost;
imerge_trp->records= non_cpk_scan_records + cpk_scan_records;
imerge_trp->records= min(imerge_trp->records,
param->table->file->stats.records);
param->table->stat_records());
imerge_trp->range_scans= range_scans;
imerge_trp->range_scans_end= range_scans + n_child_scans;
read_time= imerge_cost;
@ -4807,7 +4807,7 @@ skip_to_ror_scan:
((TRP_ROR_INTERSECT*)(*cur_roru_plan))->index_scan_costs;
roru_total_records += (*cur_roru_plan)->records;
roru_intersect_part *= (*cur_roru_plan)->records /
param->table->file->stats.records;
param->table->stat_records();
}
/*
@ -4817,7 +4817,7 @@ skip_to_ror_scan:
in disjunction do not share key parts.
*/
roru_total_records -= (ha_rows)(roru_intersect_part*
param->table->file->stats.records);
param->table->stat_records());
/* ok, got a ROR read plan for each of the disjuncts
Calculate cost:
cost(index_union_scan(scan_1, ... scan_n)) =
@ -5094,12 +5094,12 @@ static inline
ha_rows get_table_cardinality_for_index_intersect(TABLE *table)
{
if (table->file->ha_table_flags() & HA_STATS_RECORDS_IS_EXACT)
return table->file->stats.records;
return table->stat_records();
else
{
ha_rows d;
double q;
for (q= (double)table->file->stats.records, d= 1 ; q >= 10; q/= 10, d*= 10 ) ;
for (q= (double)table->stat_records(), d= 1 ; q >= 10; q/= 10, d*= 10 ) ;
return (ha_rows) (floor(q+0.5) * d);
}
}
@ -5502,9 +5502,8 @@ ha_rows records_in_index_intersect_extension(PARTIAL_INDEX_INTERSECT_INFO *curr,
ha_rows ext_records= ext_index_scan->records;
if (i < used_key_parts)
{
ulong *rec_per_key= key_info->rec_per_key+i-1;
ulong f1= rec_per_key[0] ? rec_per_key[0] : 1;
ulong f2= rec_per_key[1] ? rec_per_key[1] : 1;
ulong f1= key_info->real_rec_per_key(i-1);
ulong f2= key_info->real_rec_per_key(i);
ext_records= (ha_rows) ((double) ext_records / f2 * f1);
}
if (ext_records < table_cardinality)
@ -5996,7 +5995,7 @@ ROR_INTERSECT_INFO* ror_intersect_init(const PARAM *param)
info->is_covering= FALSE;
info->index_scan_costs= 0.0;
info->index_records= 0;
info->out_rows= (double) param->table->file->stats.records;
info->out_rows= (double) param->table->stat_records();
bitmap_clear_all(&info->covered_fields);
return info;
}
@ -6122,7 +6121,7 @@ static double ror_scan_selectivity(const ROR_INTERSECT_INFO *info,
min_range.flag= HA_READ_KEY_EXACT;
max_range.key= key_val;
max_range.flag= HA_READ_AFTER_KEY;
ha_rows prev_records= info->param->table->file->stats.records;
ha_rows prev_records= info->param->table->stat_records();
DBUG_ENTER("ror_scan_selectivity");
for (sel_arg= scan->sel_arg; sel_arg;
@ -6349,7 +6348,7 @@ TRP_ROR_INTERSECT *get_best_ror_intersect(const PARAM *param, SEL_TREE *tree,
double min_cost= DBL_MAX;
DBUG_ENTER("get_best_ror_intersect");
if ((tree->n_ror_scans < 2) || !param->table->file->stats.records ||
if ((tree->n_ror_scans < 2) || !param->table->stat_records() ||
!optimizer_flag(param->thd, OPTIMIZER_SWITCH_INDEX_MERGE_INTERSECT))
DBUG_RETURN(NULL);
@ -12629,14 +12628,14 @@ void cost_group_min_max(TABLE* table, KEY *index_info, uint used_key_parts,
double cpu_cost= 0; /* TODO: CPU cost of index_read calls? */
DBUG_ENTER("cost_group_min_max");
table_records= table->file->stats.records;
table_records= table->stat_records();
keys_per_block= (table->file->stats.block_size / 2 /
(index_info->key_length + table->file->ref_length)
+ 1);
num_blocks= (uint)(table_records / keys_per_block) + 1;
/* Compute the number of keys in a group. */
keys_per_group= index_info->rec_per_key[group_key_parts - 1];
keys_per_group= index_info->real_rec_per_key(group_key_parts - 1);
if (keys_per_group == 0) /* If there is no statistics try to guess */
/* each group contains 10% of all records */
keys_per_group= (uint)(table_records / 10) + 1;
@ -12656,7 +12655,7 @@ void cost_group_min_max(TABLE* table, KEY *index_info, uint used_key_parts,
Compute the probability that two ends of a subgroup are inside
different blocks.
*/
keys_per_subgroup= index_info->rec_per_key[used_key_parts - 1];
keys_per_subgroup= index_info->real_rec_per_key(used_key_parts - 1);
if (keys_per_subgroup >= keys_per_block) /* If a subgroup is bigger than */
p_overlap= 1.0; /* a block, it will overlap at least two blocks. */
else

View File

@ -27,6 +27,7 @@
#include "sql_acl.h" // *_ACL
#include "sp.h" // Sroutine_hash_entry
#include "sql_parse.h" // check_table_access
#include "strfunc.h"
#include "sql_admin.h"
/* Prepare, run and cleanup for mysql_recreate_table() */
@ -320,7 +321,9 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
Protocol *protocol= thd->protocol;
LEX *lex= thd->lex;
int result_code;
int compl_result_code;
bool need_repair_or_alter= 0;
DBUG_ENTER("mysql_admin_table");
DBUG_PRINT("enter", ("extra_open_options: %u", extra_open_options));
@ -640,9 +643,84 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
}
}
DBUG_PRINT("admin", ("calling operator_func '%s'", operator_name));
result_code = (table->table->file->*operator_func)(thd, check_opt);
DBUG_PRINT("admin", ("operator_func returned: %d", result_code));
result_code= compl_result_code= HA_ADMIN_OK;
if (operator_func == &handler::ha_analyze)
{
TABLE *tab= table->table;
Field **field_ptr= tab->field;
if (!lex->column_list)
{
uint fields= 0;
for ( ; *field_ptr; field_ptr++, fields++) ;
bitmap_set_prefix(tab->read_set, fields);
}
else
{
int pos;
LEX_STRING *column_name;
List_iterator_fast<LEX_STRING> it(*lex->column_list);
bitmap_clear_all(tab->read_set);
while ((column_name= it++))
{
if (tab->s->fieldnames.type_names == 0 ||
(pos= find_type(&tab->s->fieldnames, column_name->str,
column_name->length, 1)) <= 0)
{
compl_result_code= result_code= HA_ADMIN_INVALID;
break;
}
bitmap_set_bit(tab->read_set, pos-1);
}
tab->file->column_bitmaps_signal();
}
if (!lex->index_list)
{
tab->keys_in_use_for_query.init(tab->s->keys);
}
else
{
int pos;
LEX_STRING *index_name;
List_iterator_fast<LEX_STRING> it(*lex->index_list);
tab->keys_in_use_for_query.clear_all();
while ((index_name= it++))
{
if (tab->s->keynames.type_names == 0 ||
(pos= find_type(&tab->s->keynames, index_name->str,
index_name->length, 1)) <= 0)
{
compl_result_code= result_code= HA_ADMIN_INVALID;
break;
}
tab->keys_in_use_for_query.set_bit(--pos);
}
}
}
if (result_code == HA_ADMIN_OK)
{
DBUG_PRINT("admin", ("calling operator_func '%s'", operator_name));
result_code = (table->table->file->*operator_func)(thd, check_opt);
DBUG_PRINT("admin", ("operator_func returned: %d", result_code));
}
if (compl_result_code == HA_ADMIN_OK &&
operator_func == &handler::ha_analyze &&
thd->variables.use_stat_tables > 0)
{
if (!(compl_result_code=
alloc_statistics_for_table(thd, table->table)) &&
!(compl_result_code=
collect_statistics_for_table(thd, table->table)))
compl_result_code= update_statistics_for_table(thd, table->table);
if (compl_result_code)
result_code= HA_ADMIN_FAILED;
}
if (result_code == HA_ADMIN_NOT_IMPLEMENTED && need_repair_or_alter)
{

View File

@ -3142,6 +3142,16 @@ retry_share:
while (table_cache_count > table_cache_size && unused_tables)
free_cache_entry(unused_tables);
if (thd->variables.use_stat_tables > 0)
{
if (share->table_category != TABLE_CATEGORY_SYSTEM)
{
if (!share->stats_can_be_read &&
!alloc_statistics_for_table_share(thd, share, TRUE))
share->stats_can_be_read= TRUE;
}
}
mysql_mutex_unlock(&LOCK_open);
/* make a new table */
@ -4624,6 +4634,29 @@ open_and_process_table(THD *thd, LEX *lex, TABLE_LIST *tables,
goto end;
}
if (thd->variables.use_stat_tables > 0 && tables->table)
{
TABLE_SHARE *table_share= tables->table->s;
if (table_share && table_share->table_category != TABLE_CATEGORY_SYSTEM)
{
if (!table_share->stats_can_be_read &&
!alloc_statistics_for_table_share(thd, table_share, FALSE))
{
KEY *key_info= table_share->key_info;
KEY *key_info_end= key_info + table_share->keys;
KEY *table_key_info= tables->table->key_info;
for ( ; key_info < key_info_end; key_info++, table_key_info++)
table_key_info->read_stats= key_info->read_stats;
Field **field_ptr= table_share->field;
Field **table_field_ptr= tables->table->field;
for ( ; *field_ptr; field_ptr++, table_field_ptr++)
(*table_field_ptr)->read_stats= (*field_ptr)->read_stats;
table_share->stats_can_be_read= TRUE;
}
}
}
process_view_routines:
/*
Again we may need cache all routines used by this view and add
@ -5571,6 +5604,8 @@ bool open_and_lock_tables(THD *thd, TABLE_LIST *tables,
if (lock_tables(thd, tables, counter, flags))
goto err;
(void) read_statistics_for_tables_if_needed(thd, tables);
if (derived)
{
if (mysql_handle_derived(thd->lex, DT_INIT))
@ -9604,6 +9639,70 @@ open_system_tables_for_read(THD *thd, TABLE_LIST *table_list,
}
/*
Unlock opened tables and open and lock system tables for write.
SYNOPSIS
unlock_tables_n_open_system_tables_for_write()
thd Thread context.
table_list List of tables to open.
backup Pointer to Open_tables_state instance where
information about currently open tables will be
saved, and from which will be restored when we will
end work with system tables.
DESCRIPTION
The function first unlocks the opened tables, but do not close them.
Then it opens and locks for write the specified system tables.
NOTE
The system tables cannot be locked for write without unlocking
the current opened tables. Yet in some cases we still need valid TABLE
structures for these tables to be able to extract data that is to be
written into the system tables.
This function is used when updating the statistical tables.
RETURN
FALSE Success
TRUE Error
*/
bool
unlock_tables_n_open_system_tables_for_write(THD *thd,
TABLE_LIST *table_list,
Open_tables_backup *backup)
{
Query_tables_list query_tables_list_backup;
LEX *lex= thd->lex;
DBUG_ENTER("unlock_tables_n_open_system_tables_for_write");
lex->reset_n_backup_query_tables_list(&query_tables_list_backup);
thd->reset_n_backup_open_tables_state(backup);
if (open_and_lock_tables(thd, table_list, FALSE,
MYSQL_OPEN_IGNORE_FLUSH | MYSQL_LOCK_IGNORE_TIMEOUT))
{
lex->restore_backup_query_tables_list(&query_tables_list_backup);
goto error;
}
for (TABLE_LIST *tables= table_list; tables; tables= tables->next_global)
{
DBUG_ASSERT(tables->table->s->table_category == TABLE_CATEGORY_SYSTEM);
tables->table->use_all_columns();
}
lex->restore_backup_query_tables_list(&query_tables_list_backup);
DBUG_RETURN(FALSE);
error:
close_system_tables(thd, backup);
DBUG_RETURN(TRUE);
}
/*
Close system tables, opened with open_system_tables_for_read().

View File

@ -275,6 +275,9 @@ bool is_equal(const LEX_STRING *a, const LEX_STRING *b);
/* Functions to work with system tables. */
bool open_system_tables_for_read(THD *thd, TABLE_LIST *table_list,
Open_tables_backup *backup);
bool unlock_tables_n_open_system_tables_for_write(THD *thd,
TABLE_LIST *table_list,
Open_tables_backup *backup);
void close_system_tables(THD *thd, Open_tables_backup *backup);
void close_mysql_tables(THD *thd);
TABLE *open_system_table_for_update(THD *thd, TABLE_LIST *one_table);
@ -306,6 +309,29 @@ bool check_if_table_exists(THD *thd, TABLE_LIST *table, bool *exists);
int update_virtual_fields(THD *thd, TABLE *table, bool ignore_stored= FALSE);
int dynamic_column_error_message(enum_dyncol_func_result rc);
/* open_and_lock_tables with optional derived handling */
int open_and_lock_tables_derived(THD *thd, TABLE_LIST *tables, bool derived);
int read_statistics_for_tables_if_needed(THD *thd, TABLE_LIST *tables);
int collect_statistics_for_table(THD *thd, TABLE *table);
int alloc_statistics_for_table_share(THD* thd, TABLE_SHARE *share,
bool is_safe);
int alloc_statistics_for_table(THD *thd, TABLE *table);
int update_statistics_for_table(THD *thd, TABLE *table);
int delete_statistics_for_table(THD *thd, LEX_STRING *db, LEX_STRING *tab);
int delete_statistics_for_column(THD *thd, TABLE *tab, Field *col);
int delete_statistics_for_index(THD *thd, TABLE *tab, KEY *key_info);
int rename_table_in_stat_tables(THD *thd, LEX_STRING *db, LEX_STRING *tab,
LEX_STRING *new_db, LEX_STRING *new_tab);
int rename_column_in_stat_tables(THD *thd, TABLE *tab, Field *col,
const char *new_name);
void set_statistics_for_table(THD *thd, TABLE *table);
extern "C" int simple_raw_key_cmp(void* arg, const void* key1,
const void* key2);
extern "C" int count_distinct_walk(void *elem, element_count count, void *arg);
int simple_str_key_cmp(void* arg, uchar* key1, uchar* key2);
extern TABLE *unused_tables;
extern Item **not_found_item;
extern Field *not_found_field;
@ -472,7 +498,6 @@ open_tables(THD *thd, TABLE_LIST **tables, uint *counter, uint flags)
return open_tables(thd, tables, counter, flags, &prelocking_strategy);
}
inline TABLE *open_n_lock_single_table(THD *thd, TABLE_LIST *table_l,
thr_lock_type lock_type, uint flags)
{

View File

@ -502,6 +502,7 @@ typedef struct system_variables
ulong net_write_timeout;
ulong optimizer_prune_level;
ulong optimizer_search_depth;
ulong use_stat_tables;
ulong preload_buff_size;
ulong profiling_history_size;
ulong read_buff_size;

View File

@ -816,6 +816,17 @@ bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
lock_db_routines(thd, db))
goto exit;
if (!in_bootstrap)
{
for (table= tables; table; table= table->next_local)
{
LEX_STRING db_name= { table->db, table->db_length };
LEX_STRING table_name= { table->table_name, table->table_name_length };
if (table->open_type == OT_BASE_ONLY || !find_temporary_table(thd, table))
(void) delete_statistics_for_table(thd, &db_name, &table_name);
}
}
/* mysql_ha_rm_tables() requires a non-null TABLE_LIST. */
if (tables)
mysql_ha_rm_tables(thd, tables);

View File

@ -200,6 +200,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
#endif
/* Update the table->file->stats.records number */
table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);
set_statistics_for_table(thd, table);
table->covering_keys.clear_all();
table->quick_keys.clear_all(); // Can't use 'only index'

View File

@ -3812,7 +3812,7 @@ uint JOIN_TAB_SCAN_MRR::aux_buffer_incr(ulong recno)
uint incr= 0;
TABLE_REF *ref= &join_tab->ref;
TABLE *tab= join_tab->table;
uint rec_per_key= tab->key_info[ref->key].rec_per_key[ref->key_parts-1];
uint rec_per_key= tab->key_info[ref->key].real_rec_per_key(ref->key_parts-1);
set_if_bigger(rec_per_key, 1);
if (recno == 1)
incr= ref->key_length + tab->file->ref_length;

View File

@ -458,6 +458,8 @@ void lex_start(THD *thd)
lex->set_var_list.empty();
lex->param_list.empty();
lex->view_list.empty();
lex->column_list= NULL;
lex->index_list= NULL;
lex->prepared_stmt_params.empty();
lex->auxiliary_table_list.empty();
lex->unit.next= lex->unit.master=

View File

@ -2391,6 +2391,8 @@ struct LEX: public Query_tables_list
List<Item_func_set_user_var> set_var_list; // in-query assignment list
List<Item_param> param_list;
List<LEX_STRING> view_list; // view list (list of field names in view)
List<LEX_STRING> *column_list; // list of column names (in ANALYZE)
List<LEX_STRING> *index_list; // list of index names (in ANALYZE)
/*
A stack of name resolution contexts for the query. This stack is used
at parse time to set local name resolution contexts for various parts

View File

@ -327,6 +327,7 @@ enum enum_yes_no_unknown
};
#ifdef MYSQL_SERVER
/*
External variables
*/

View File

@ -279,6 +279,12 @@ do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db, char *new_table_name,
ren_table->db, old_alias,
new_db, new_alias, 0)))
{
LEX_STRING db_name= { ren_table->db, ren_table->db_length };
LEX_STRING table_name= { ren_table->table_name,
ren_table->table_name_length };
LEX_STRING new_table= { (char *) new_alias, strlen(new_alias) };
(void) rename_table_in_stat_tables(thd, &db_name, &table_name,
&db_name, &new_table);
if ((rc= Table_triggers_list::change_table_name(thd, ren_table->db,
old_alias,
ren_table->table_name,

View File

@ -51,6 +51,7 @@
#include "opt_subselect.h"
#include "log_slow.h"
#include "sql_derived.h"
#include "sql_statistics.h"
#include "debug_sync.h" // DEBUG_SYNC
#include <m_ctype.h>
@ -3182,6 +3183,7 @@ make_join_statistics(JOIN *join, List<TABLE_LIST> &tables_list,
table_vector[i]=s->table=table=tables->table;
table->pos_in_table_list= tables;
error= tables->fetch_number_of_rows();
set_statistics_for_table(join->thd, table);
#ifdef WITH_PARTITION_STORAGE_ENGINE
const bool no_partitions_used= table->no_partitions_used;
@ -3213,8 +3215,8 @@ make_join_statistics(JOIN *join, List<TABLE_LIST> &tables_list,
s->dependent= tables->dep_tables;
if (tables->schema_table)
table->file->stats.records= 2;
table->quick_condition_rows= table->file->stats.records;
table->file->stats.records= table->used_stat_records= 2;
table->quick_condition_rows= table->stat_records();
s->on_expr_ref= &tables->on_expr;
if (*s->on_expr_ref)
@ -3447,7 +3449,7 @@ make_join_statistics(JOIN *join, List<TABLE_LIST> &tables_list,
// All dep. must be constants
if (s->dependent & ~(found_const_table_map))
continue;
if (table->file->stats.records <= 1L &&
if (table->stat_records() <= 1L &&
(table->file->ha_table_flags() & HA_STATS_RECORDS_IS_EXACT) &&
!table->pos_in_table_list->embedding &&
!((outer_join & table->map) &&
@ -5415,7 +5417,7 @@ best_access_path(JOIN *join,
else
{
uint key_parts= table->actual_n_key_parts(keyinfo);
if (!(records=keyinfo->rec_per_key[key_parts-1]))
if (!(records= keyinfo->real_rec_per_key(key_parts-1)))
{ /* Prefer longer keys */
records=
((double) s->records / (double) rec *
@ -5515,7 +5517,7 @@ best_access_path(JOIN *join,
else
{
/* Check if we have statistic about the distribution */
if ((records= keyinfo->rec_per_key[max_key_part-1]))
if ((records= keyinfo->real_rec_per_key(max_key_part-1)))
{
/*
Fix for the case where the index statistics is too
@ -7730,6 +7732,7 @@ static bool create_hj_key_for_table(JOIN *join, JOIN_TAB *join_tab,
keyinfo->key_length=0;
keyinfo->algorithm= HA_KEY_ALG_UNDEF;
keyinfo->flags= HA_GENERATED_KEY;
keyinfo->is_statistics_from_stat_tables= FALSE;
keyinfo->name= (char *) "$hj";
keyinfo->rec_per_key= (ulong*) thd->calloc(sizeof(ulong)*key_parts);
if (!keyinfo->rec_per_key)
@ -10290,7 +10293,7 @@ double JOIN_TAB::scan_time()
}
else
{
found_records= records= table->file->stats.records;
found_records= records= table->stat_records();
read_time= table->file->scan_time();
/*
table->quick_condition_rows has already been set to
@ -10301,7 +10304,7 @@ double JOIN_TAB::scan_time()
}
else
{
found_records= records=table->file->stats.records;
found_records= records=table->stat_records();
read_time= found_records ? (double)found_records: 10.0;// TODO:fix this stub
res= read_time;
}
@ -10342,7 +10345,7 @@ ha_rows JOIN_TAB::get_examined_rows()
handler->info(HA_STATUS_VARIABLE) has been called in
make_join_statistics()
*/
examined_rows= table->file->stats.records;
examined_rows= table->stat_records();
}
}
}
@ -14684,8 +14687,11 @@ create_tmp_table(THD *thd, TMP_TABLE_PARAM *param, List<Item> &fields,
keyinfo->usable_key_parts=keyinfo->key_parts= param->group_parts;
keyinfo->ext_key_parts= keyinfo->key_parts;
keyinfo->key_length=0;
keyinfo->rec_per_key=0;
keyinfo->rec_per_key=NULL;
keyinfo->read_stats= NULL;
keyinfo->collected_stats= NULL;
keyinfo->algorithm= HA_KEY_ALG_UNDEF;
keyinfo->is_statistics_from_stat_tables= FALSE;
keyinfo->name= (char*) "group_key";
ORDER *cur_group= group;
for (; cur_group ; cur_group= cur_group->next, key_part_info++)
@ -14798,7 +14804,10 @@ create_tmp_table(THD *thd, TMP_TABLE_PARAM *param, List<Item> &fields,
keyinfo->key_length= 0; // Will compute the sum of the parts below.
keyinfo->name= (char*) "distinct_key";
keyinfo->algorithm= HA_KEY_ALG_UNDEF;
keyinfo->is_statistics_from_stat_tables= FALSE;
keyinfo->rec_per_key=0;
keyinfo->read_stats= NULL;
keyinfo->collected_stats= NULL;
/*
Create an extra field to hold NULL bits so that unique indexes on
@ -18576,7 +18585,7 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
uint saved_best_key_parts= 0;
int best_key_direction= 0;
JOIN *join= tab->join;
ha_rows table_records= table->file->stats.records;
ha_rows table_records= table->stat_records();
test_if_cheaper_ordering(tab, order, table, usable_keys,
ref_key, select_limit,
@ -18691,7 +18700,7 @@ check_reverse_order:
{
tab->ref.key= -1;
tab->ref.key_parts= 0;
if (select_limit < table->file->stats.records)
if (select_limit < table->stat_records())
tab->limit= select_limit;
table->disable_keyread();
}
@ -18931,7 +18940,7 @@ create_sort_index(THD *thd, JOIN *join, ORDER *order,
if (!tab->preread_init_done && tab->preread_init())
goto err;
if (table->s->tmp_table)
table->file->info(HA_STATUS_VARIABLE); // Get record count
table->file->info(HA_STATUS_VARIABLE); // Get record count
table->sort.found_records=filesort(thd, table,join->sortorder, length,
select, filesort_limit, 0,
&examined_rows);
@ -22700,7 +22709,7 @@ test_if_cheaper_ordering(const JOIN_TAB *tab, ORDER *order, TABLE *table,
int best_key= -1;
bool is_best_covering= FALSE;
double fanout= 1;
ha_rows table_records= table->file->stats.records;
ha_rows table_records= table->stat_records();
bool group= join && join->group && order == join->group_list;
ha_rows ref_key_quick_rows= HA_POS_ERROR;
@ -22790,7 +22799,7 @@ test_if_cheaper_ordering(const JOIN_TAB *tab, ORDER *order, TABLE *table,
if (used_key_parts > used_index_parts)
used_pk_parts= used_key_parts-used_index_parts;
rec_per_key= used_key_parts ?
keyinfo->rec_per_key[used_key_parts-1] : 1;
keyinfo->real_rec_per_key(used_key_parts-1) : 1;
/* Take into account the selectivity of the used pk prefix */
if (used_pk_parts)
{
@ -22805,8 +22814,8 @@ test_if_cheaper_ordering(const JOIN_TAB *tab, ORDER *order, TABLE *table,
rec_per_key= 1;
if (rec_per_key > 1)
{
rec_per_key*= pkinfo->rec_per_key[used_pk_parts-1];
rec_per_key/= pkinfo->rec_per_key[0];
rec_per_key*= pkinfo->real_rec_per_key(used_pk_parts-1);
rec_per_key/= pkinfo->real_rec_per_key(0);
/*
The value of rec_per_key for the extended key has
to be adjusted accordingly if some components of
@ -22820,9 +22829,9 @@ test_if_cheaper_ordering(const JOIN_TAB *tab, ORDER *order, TABLE *table,
We presume here that for any index rec_per_key[i] != 0
if rec_per_key[0] != 0.
*/
DBUG_ASSERT(pkinfo->rec_per_key[i]);
rec_per_key*= pkinfo->rec_per_key[i-1];
rec_per_key/= pkinfo->rec_per_key[i];
DBUG_ASSERT(pkinfo->real_rec_per_key(i));
rec_per_key*= pkinfo->real_rec_per_key(i-1);
rec_per_key/= pkinfo->real_rec_per_key(i);
}
}
}
@ -22867,7 +22876,7 @@ test_if_cheaper_ordering(const JOIN_TAB *tab, ORDER *order, TABLE *table,
select_limit= (ha_rows) (select_limit *
(double) table_records /
table->quick_condition_rows);
rec_per_key= keyinfo->rec_per_key[keyinfo->key_parts-1];
rec_per_key= keyinfo->real_rec_per_key(keyinfo->key_parts-1);
set_if_bigger(rec_per_key, 1);
/*
Here we take into account the fact that rows are
@ -23008,7 +23017,7 @@ uint get_index_for_order(ORDER *order, TABLE *table, SQL_SELECT *select,
Update quick_condition_rows since single table UPDATE/DELETE procedures
don't call make_join_statistics() and leave this variable uninitialized.
*/
table->quick_condition_rows= table->file->stats.records;
table->quick_condition_rows= table->stat_records();
int key, direction;
if (test_if_cheaper_ordering(NULL, order, table,

View File

@ -5727,9 +5727,12 @@ static int get_schema_stat_record(THD *thd, TABLE_LIST *tables,
TABLE *show_table= tables->table;
KEY *key_info=show_table->s->key_info;
if (show_table->file)
{
show_table->file->info(HA_STATUS_VARIABLE |
HA_STATUS_NO_LOCK |
HA_STATUS_TIME);
set_statistics_for_table(thd, show_table);
}
for (uint i=0 ; i < show_table->s->keys ; i++,key_info++)
{
KEY_PART_INFO *key_part= key_info->key_part;
@ -5760,8 +5763,8 @@ static int get_schema_stat_record(THD *thd, TABLE_LIST *tables,
KEY *key=show_table->key_info+i;
if (key->rec_per_key[j])
{
ha_rows records=(show_table->file->stats.records /
key->rec_per_key[j]);
ha_rows records=((double) show_table->stat_records() /
key->real_rec_per_key(j));
table->field[9]->store((longlong) records, TRUE);
table->field[9]->set_notnull();
}

2925
sql/sql_statistics.cc Normal file

File diff suppressed because it is too large Load Diff

218
sql/sql_statistics.h Normal file
View File

@ -0,0 +1,218 @@
/* Copyright 2006-2008 MySQL AB, 2008 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#ifndef SQL_STATISTICS_H
#define SQL_STATISTICS_H
/*
These enumeration types comprise the dictionary of three
statistical tables table_stat, column_stat and index_stat
as they defined in ../scripts/mysql_system_tables.sql.
It would be nice if the declarations of these types were
generated automatically by the table definitions.
*/
enum enum_stat_tables
{
TABLE_STAT,
COLUMN_STAT,
INDEX_STAT,
};
enum enum_table_stat_col
{
TABLE_STAT_DB_NAME,
TABLE_STAT_TABLE_NAME,
TABLE_STAT_CARDINALITY
};
enum enum_column_stat_col
{
COLUMN_STAT_DB_NAME,
COLUMN_STAT_TABLE_NAME,
COLUMN_STAT_COLUMN_NAME,
COLUMN_STAT_MIN_VALUE,
COLUMN_STAT_MAX_VALUE,
COLUMN_STAT_NULLS_RATIO,
COLUMN_STAT_AVG_LENGTH,
COLUMN_STAT_AVG_FREQUENCY
};
enum enum_index_stat_col
{
INDEX_STAT_DB_NAME,
INDEX_STAT_TABLE_NAME,
INDEX_STAT_INDEX_NAME,
INDEX_STAT_PREFIX_ARITY,
INDEX_STAT_AVG_FREQUENCY
};
class Columns_statistics;
class Index_statistics;
/* Statistical data on a table */
class Table_statistics
{
public:
my_bool cardinality_is_null; /* TRUE if the cardinality is unknown */
ha_rows cardinality; /* Number of rows in the table */
Column_statistics *column_stats; /* Array of statistical data for columns */
Index_statistics *index_stats; /* Array of statistical data for indexes */
ulong *idx_avg_frequency; /* Array of records per key for index prefixes */
};
/* Statistical data on a column */
class Column_statistics
{
private:
static const uint Scale_factor_nulls_ratio= 100000;
static const uint Scale_factor_avg_length= 100000;
static const uint Scale_factor_avg_frequency= 100000;
public:
/*
Bitmap indicating what statistical characteristics
are available for the column
*/
uint32 column_stat_nulls;
/* Minimum value for the column */
Field *min_value;
/* Maximum value for the column */
Field *max_value;
private:
/*
The ratio Z/N multiplied by the scale factor Scale_factor_nulls_ratio,
where
N is the total number of rows,
Z is the number of nulls in the column
*/
ulong nulls_ratio;
/*
Average number of bytes occupied by the representation of a
value of the column in memory buffers such as join buffer
multiplied by the scale factor Scale_factor_avg_length.
CHAR values are stripped of trailing spaces.
Flexible values are stripped of their length prefixes.
*/
ulong avg_length;
/*
The ratio N/D multiplied by the scale factor Scale_factor_avg_frequency,
where
N is the number of rows with not null value in the column,
D the number of distinct values among them
*/
ulong avg_frequency;
public:
void set_all_nulls()
{
column_stat_nulls=
((1 << (COLUMN_STAT_AVG_FREQUENCY-COLUMN_STAT_COLUMN_NAME))-1) <<
(COLUMN_STAT_COLUMN_NAME+1);
}
void set_not_null(uint stat_field_no)
{
column_stat_nulls&= ~(1 << stat_field_no);
}
bool is_null(uint stat_field_no)
{
return test(column_stat_nulls & (1 << stat_field_no));
}
double get_nulls_ratio()
{
return (double) nulls_ratio / Scale_factor_nulls_ratio;
}
double get_avg_length()
{
return (double) avg_length / Scale_factor_avg_length;
}
double get_avg_frequency()
{
return (double) avg_frequency / Scale_factor_avg_frequency;
}
void set_nulls_ratio (double val)
{
nulls_ratio= (ulong) (val * Scale_factor_nulls_ratio);
}
void set_avg_length (double val)
{
avg_length= (ulong) (val * Scale_factor_avg_length);
}
void set_avg_frequency (double val)
{
avg_frequency= (ulong) (val * Scale_factor_avg_frequency);
}
};
/* Statistical data on an index prefixes */
class Index_statistics
{
private:
static const uint Scale_factor_avg_frequency= 100000;
/*
The k-th element of this array contains the ratio N/D
multiplied by the scale factor Scale_factor_avg_frequency,
where N is the number of index entries without nulls
in the first k components, and D is the number of distinct
k-component prefixes among them
*/
ulong *avg_frequency;
public:
void init_avg_frequency(ulong *ptr) { avg_frequency= ptr; }
bool avg_frequency_is_inited() { return avg_frequency != NULL; }
double get_avg_frequency(uint i)
{
return (double) avg_frequency[i] / Scale_factor_avg_frequency;
}
void set_avg_frequency(uint i, double val)
{
avg_frequency[i]= (ulong) (val * Scale_factor_avg_frequency);
}
};
#endif /* SQL_STATISTICS_H */

View File

@ -1886,6 +1886,17 @@ bool mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists,
}
}
if (!in_bootstrap)
{
for (table= tables; table; table= table->next_local)
{
LEX_STRING db_name= { table->db, table->db_length };
LEX_STRING table_name= { table->table_name, table->table_name_length };
if (table->open_type == OT_BASE_ONLY || !find_temporary_table(thd, table))
(void) delete_statistics_for_table(thd, &db_name, &table_name);
}
}
mysql_ha_rm_tables(thd, tables);
if (!drop_temporary)
@ -1896,6 +1907,7 @@ bool mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists,
MYSQL_OPEN_SKIP_TEMPORARY))
DBUG_RETURN(true);
for (table= tables; table; table= table->next_local)
tdc_remove_table(thd, TDC_RT_REMOVE_ALL, table->db, table->table_name,
false);
}
@ -5146,6 +5158,21 @@ mysql_compare_tables(TABLE *table,
thd->calloc(sizeof(void*) * table->s->keys)) == NULL)
DBUG_RETURN(1);
tmp_new_field_it.init(tmp_alter_info.create_list);
for (i= 0, f_ptr= table->field, tmp_new_field= tmp_new_field_it++;
(field= *f_ptr);
i++, f_ptr++, tmp_new_field= tmp_new_field_it++)
{
if (field->is_equal(tmp_new_field) == IS_EQUAL_NO &&
table->s->tmp_table == NO_TMP_TABLE)
(void) delete_statistics_for_column(thd, table, field);
else if (my_strcasecmp(system_charset_info,
field->field_name,
tmp_new_field->field_name))
(void) rename_column_in_stat_tables(thd, table, field,
tmp_new_field->field_name);
}
/*
Use transformed info to evaluate possibility of in-place ALTER TABLE
but use the preserved field to persist modifications.
@ -5206,7 +5233,12 @@ mysql_compare_tables(TABLE *table,
if (my_strcasecmp(system_charset_info,
field->field_name,
tmp_new_field->field_name))
field->flags|= FIELD_IS_RENAMED;
{
field->flags|= FIELD_IS_RENAMED;
if (table->s->tmp_table == NO_TMP_TABLE)
rename_column_in_stat_tables(thd, table, field,
tmp_new_field->field_name);
}
/* Evaluate changes bitmap and send to check_if_incompatible_data() */
if (!(tmp= field->is_equal(tmp_new_field)))
@ -5309,6 +5341,8 @@ mysql_compare_tables(TABLE *table,
field= table->field[key_part->fieldnr];
field->flags|= FIELD_IN_ADD_INDEX;
}
if (table->s->tmp_table == NO_TMP_TABLE)
(void) delete_statistics_for_index(thd, table, table_key);
DBUG_PRINT("info", ("index changed: '%s'", table_key->name));
}
/*end of for (; table_key < table_key_end;) */
@ -5566,6 +5600,8 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
}
if (drop)
{
if (table->s->tmp_table == NO_TMP_TABLE)
(void) delete_statistics_for_column(thd, table, field);
drop_it.remove();
/*
ALTER TABLE DROP COLUMN always changes table data even in cases
@ -5718,12 +5754,15 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
}
if (drop)
{
if (table->s->tmp_table == NO_TMP_TABLE)
(void) delete_statistics_for_index(thd, table, key_info);
drop_it.remove();
continue;
}
KEY_PART_INFO *key_part= key_info->key_part;
key_parts.empty();
bool delete_index_stat= FALSE;
for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
{
if (!key_part->field)
@ -5746,7 +5785,10 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
break;
}
if (!cfield)
{
delete_index_stat= TRUE;
continue; // Field is removed
}
key_part_length= key_part->length;
if (cfield->field) // Not new field
{
@ -5788,6 +5830,8 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
strlen(cfield->field_name),
key_part_length));
}
if (delete_index_stat && table->s->tmp_table == NO_TMP_TABLE)
(void) delete_statistics_for_index(thd, table, key_info);
if (key_parts.elements)
{
KEY_CREATE_INFO key_create_info;
@ -5967,6 +6011,9 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
enum ha_extra_function extra_func= thd->locked_tables_mode
? HA_EXTRA_NOT_USED
: HA_EXTRA_FORCE_REOPEN;
LEX_STRING old_db_name= { table_list->db, table_list->db_length };
LEX_STRING old_table_name= { table_list->table_name,
table_list->table_name_length };
DBUG_ENTER("mysql_alter_table");
/*
@ -6285,6 +6332,12 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
else
{
*fn_ext(new_name)=0;
LEX_STRING new_db_name= { new_db, strlen(new_db) };
LEX_STRING new_table_name= { new_alias, strlen(new_alias) };
(void) rename_table_in_stat_tables(thd, &old_db_name, &old_table_name,
&new_db_name, &new_table_name);
if (mysql_rename_table(old_db_type,db,table_name,new_db,new_alias, 0))
error= -1;
else if (Table_triggers_list::change_table_name(thd, db,
@ -7029,6 +7082,15 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
table is renamed and the SE is also changed, then an intermediate table
is created and the additional call will not take place.
*/
if (new_name != table_name || new_db != db)
{
LEX_STRING new_db_name= { new_db, strlen(new_db) };
LEX_STRING new_table_name= { new_name, strlen(new_name) };
(void) rename_table_in_stat_tables(thd, &old_db_name, &old_table_name,
&new_db_name, &new_table_name);
}
if (need_copy_table == ALTER_TABLE_METADATA_ONLY)
{
DBUG_ASSERT(new_db_type == old_db_type);

View File

@ -1594,7 +1594,12 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
show describe load alter optimize keycache preload flush
reset purge begin commit rollback savepoint release
slave master_def master_defs master_file_def slave_until_opts
repair analyze check start checksum
repair analyze
analyze_table_list analyze_table_elem_spec
opt_persistent_stat_clause persistent_stat_spec
persistent_column_stat_spec persistent_index_stat_spec
table_column_list table_index_list table_index_name
check start checksum
field_list field_list_item field_spec kill column_def key_def
keycache_list keycache_list_or_parts assign_to_keycache
assign_to_keycache_parts
@ -7229,7 +7234,7 @@ analyze:
/* Will be overriden during execution. */
YYPS->m_lock_type= TL_UNLOCK;
}
table_list
analyze_table_list
{
THD *thd= YYTHD;
LEX* lex= thd->lex;
@ -7240,6 +7245,93 @@ analyze:
}
;
analyze_table_list:
analyze_table_elem_spec
| analyze_table_list ',' analyze_table_elem_spec
;
analyze_table_elem_spec:
table_name opt_persistent_stat_clause
;
opt_persistent_stat_clause:
/* empty */
{}
| PERSISTENT_SYM FOR_SYM persistent_stat_spec
{}
;
persistent_stat_spec:
ALL
{}
| COLUMNS persistent_column_stat_spec INDEXES persistent_index_stat_spec
{}
persistent_column_stat_spec:
ALL {}
| '('
{
THD *thd= YYTHD;
LEX* lex= thd->lex;
lex->column_list= new List<LEX_STRING>;
if (lex->column_list == NULL)
MYSQL_YYABORT;
}
table_column_list
')'
;
persistent_index_stat_spec:
ALL {}
| '('
{
THD *thd= YYTHD;
LEX* lex= thd->lex;
lex->index_list= new List<LEX_STRING>;
if (lex->index_list == NULL)
MYSQL_YYABORT;
}
table_index_list
')'
;
table_column_list:
/* empty */
{}
| ident
{
Lex->column_list->push_back((LEX_STRING*)
sql_memdup(&$1, sizeof(LEX_STRING)));
}
| table_column_list ',' ident
{
Lex->column_list->push_back((LEX_STRING*)
sql_memdup(&$3, sizeof(LEX_STRING)));
}
;
table_index_list:
/* empty */
{}
| table_index_name
| table_index_list ',' table_index_name
;
table_index_name:
ident
{
Lex->index_list->push_back(
(LEX_STRING*) sql_memdup(&$1, sizeof(LEX_STRING)));
}
|
PRIMARY_SYM
{
LEX_STRING str= {(char*) "PRIMARY", 7};
Lex->index_list->push_back(
(LEX_STRING*) sql_memdup(&str, sizeof(LEX_STRING)));
}
;
binlog_base64_event:
BINLOG_SYM TEXT_STRING_sys
{

View File

@ -29,6 +29,7 @@
struct TABLE;
class Field;
class Index_statistics;
class THD;
@ -96,6 +97,11 @@ typedef struct st_key {
uint block_size;
uint name_length;
enum ha_key_alg algorithm;
/*
The flag is on if statistical data for the index prefixes
has to be taken from the system statistical tables.
*/
bool is_statistics_from_stat_tables;
/*
Note that parser is used when the table is opened for use, and
parser_name is used when the table is being created.
@ -115,6 +121,18 @@ typedef struct st_key {
For temporary heap tables this member is NULL.
*/
ulong *rec_per_key;
/*
This structure is used for statistical data on the index
that has been read from the statistical table index_stat
*/
Index_statistics *read_stats;
/*
This structure is used for statistical data on the index that
is collected by the function collect_statistics_for_table
*/
Index_statistics *collected_stats;
union {
int bdb_return_if_eq;
} handler;
@ -123,6 +141,9 @@ typedef struct st_key {
/** reference to the list of options or NULL */
engine_option_value *option_list;
ha_index_option_struct *option_struct; /* structure with parsed options */
double real_rec_per_key(uint i);
} KEY;

View File

@ -3791,6 +3791,15 @@ static Sys_var_ulong Sys_progress_report_time(
SESSION_VAR(progress_report_time), CMD_LINE(REQUIRED_ARG),
VALID_RANGE(0, UINT_MAX), DEFAULT(56), BLOCK_SIZE(1));
const char *use_stat_tables_modes[] =
{"NEVER", "COMPLEMENTARY", "PREFERABLY", 0};
static Sys_var_enum Sys_optimizer_use_stat_tables(
"use_stat_tables",
"Specifies how to use system statistics tables. Possible values are "
"NEVER, COMPLEMENTARY, PREVERABLY",
SESSION_VAR(use_stat_tables), CMD_LINE(REQUIRED_ARG),
use_stat_tables_modes, DEFAULT(0));
static Sys_var_mybool Sys_no_thread_alarm(
"debug_no_thread_alarm",
"Disable system thread alarm calls. Disabling it may be useful "

View File

@ -39,6 +39,7 @@
#include "my_bit.h"
#include "sql_select.h"
#include "sql_derived.h"
#include "sql_statistics.h"
#include "mdl.h" // MDL_wait_for_graph_visitor
/* INFORMATION_SCHEMA name */
@ -544,6 +545,12 @@ inline bool is_system_table_name(const char *name, uint length)
my_tolower(ci, name[2]) == 'm' &&
my_tolower(ci, name[3]) == 'e') ||
/* one of mysql.*_stat tables */
(my_tolower(ci, name[length-4]) == 's' &&
my_tolower(ci, name[length-3]) == 't' &&
my_tolower(ci, name[length-2]) == 'a' &&
my_tolower(ci, name[length-1]) == 't') ||
/* mysql.event table */
(my_tolower(ci, name[0]) == 'e' &&
my_tolower(ci, name[1]) == 'v' &&
@ -753,7 +760,7 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head,
uchar forminfo[288];
uchar *record;
uchar *disk_buff, *strpos, *null_flags, *null_pos;
ulong pos, record_offset;
ulong pos, record_offset;
ulong *rec_per_key= NULL;
ulong rec_buff_length;
handler *handler_file= 0;
@ -5971,6 +5978,7 @@ bool TABLE::add_tmp_key(uint key, uint key_parts,
keyinfo->algorithm= HA_KEY_ALG_UNDEF;
keyinfo->flags= HA_GENERATED_KEY;
keyinfo->ext_key_flags= keyinfo->flags;
keyinfo->is_statistics_from_stat_tables= FALSE;
if (unique)
keyinfo->flags|= HA_NOSAME;
sprintf(buf, "key%i", key);
@ -5981,6 +5989,8 @@ bool TABLE::add_tmp_key(uint key, uint key_parts,
if (!keyinfo->rec_per_key)
return TRUE;
bzero(keyinfo->rec_per_key, sizeof(ulong)*key_parts);
keyinfo->read_stats= NULL;
keyinfo->collected_stats= NULL;
for (i= 0; i < key_parts; i++)
{
@ -6671,6 +6681,7 @@ int TABLE_LIST::fetch_number_of_rows()
{
table->file->stats.records= ((select_union*)derived->result)->records;
set_if_bigger(table->file->stats.records, 2);
table->used_stat_records= table->file->stats.records;
}
else
error= table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);
@ -6767,6 +6778,14 @@ uint TABLE_SHARE::actual_n_key_parts(THD *thd)
}
double KEY::real_rec_per_key(uint i)
{
if (rec_per_key == 0)
return 0;
return (is_statistics_from_stat_tables ?
read_stats->get_avg_frequency(i) : (double) rec_per_key[i]);
}
/*****************************************************************************
** Instansiate templates
*****************************************************************************/

View File

@ -45,6 +45,7 @@ struct TABLE_LIST;
class ACL_internal_schema_access;
class ACL_internal_table_access;
class Field;
class Table_statistics;
/*
Used to identify NESTED_JOIN structures within a join (applicable only to
@ -577,6 +578,15 @@ struct TABLE_SHARE
KEY *key_info; /* data of keys in database */
uint *blob_field; /* Index to blobs in Field arrray*/
bool stats_can_be_read; /* Memory for statistical data is allocated */
bool stats_is_read; /* Statistical data for table has been read
from statistical tables */
/*
This structure is used for statistical data on the table
that has been read from the statistical table table_stat
*/
Table_statistics *read_stats;
uchar *default_values; /* row with default values */
LEX_STRING comment; /* Comment about table */
CHARSET_INFO *table_charset; /* Default charset of string fields */
@ -1007,6 +1017,15 @@ public:
*/
query_id_t query_id;
/*
This structure is used for statistical data on the table that
is collected by the function collect_statistics_for_table
*/
Table_statistics *collected_stats;
/* The estimate of the number of records in the table used by optimizer */
ha_rows used_stat_records;
/*
For each key that has quick_keys.is_set(key) == TRUE: estimate of #records
and max #key parts that range access would use.
@ -1258,6 +1277,7 @@ public:
bool update_const_key_parts(COND *conds);
uint actual_n_key_parts(KEY *keyinfo);
ulong actual_key_flags(KEY *keyinfo);
inline ha_rows stat_records() { return used_stat_records; }
};