polardbxengine/mysql-test/suite/xengine_main/r/information_schema_statisti...

104 lines
4.7 KiB
Plaintext

CREATE TABLE t1 (f0 INT KEY AUTO_INCREMENT, f1 INT, f2 INT);
CREATE TABLE t2 (f0 INT KEY AUTO_INCREMENT, f1 INT, f2 INT) ENGINE=MYISAM;
CREATE TABLE t3 (f0 INT KEY AUTO_INCREMENT, f1 INT, f2 INT, KEY (f0), KEY (f1), KEY (f1, f2));
INSERT INTO t1 (f1, f2) VALUES (1,1 ),(2,2),(3,3),(4,4);
INSERT INTO t1 (f1, f2) SELECT f1, f2 FROM t1;
INSERT INTO t1 (f1, f2) SELECT f1, f2 FROM t1;
INSERT INTO t1 (f1, f2) SELECT f1, f2 FROM t1;
INSERT INTO t2 (f1, f2) SELECT f1, f2 FROM t1;
INSERT INTO t3 (f1, f2) SELECT f1, f2 FROM t1;
DELETE FROM t1 WHERE f1=1;
DELETE FROM t2 WHERE f1=1;
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
ANALYZE TABLE t2;
Table Op Msg_type Msg_text
test.t2 analyze status OK
ANALYZE TABLE t3;
Table Op Msg_type Msg_text
test.t3 analyze status OK
SELECT COUNT(*) FROM t1;
COUNT(*)
24
SELECT COUNT(*) FROM t2;
COUNT(*)
24
SELECT COUNT(*) FROM t3;
COUNT(*)
32
Case 1: IS query uses mysql.table_stats to read dynamic table statistics
SET SESSION information_schema_stats_expiry=default;
SELECT table_rows, avg_row_length, data_length, max_data_length, index_length,
data_free, auto_increment, checksum, update_time, check_time
FROM information_schema.tables WHERE table_name in ('t1', 't2');
TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE AUTO_INCREMENT CHECKSUM UPDATE_TIME CHECK_TIME
32 65536 2097152 0 0 0 33 NULL # NULL
24 13 416 3659174697238527 2048 104 33 NULL # NULL
SELECT * FROM information_schema.statistics WHERE table_name='t3'
ORDER BY index_name, seq_in_index;
TABLE_CATALOG TABLE_SCHEMA TABLE_NAME NON_UNIQUE INDEX_SCHEMA INDEX_NAME SEQ_IN_INDEX COLUMN_NAME COLLATION CARDINALITY SUB_PART PACKED NULLABLE INDEX_TYPE COMMENT INDEX_COMMENT IS_VISIBLE EXPRESSION
def test t3 1 test f0 1 f0 A 32 NULL NULL SE_SPECIFIC YES NULL
def test t3 1 test f1 1 f1 A 16 NULL NULL YES SE_SPECIFIC YES NULL
def test t3 1 test f1_2 1 f1 A 8 NULL NULL YES SE_SPECIFIC YES NULL
def test t3 1 test f1_2 2 f2 A 16 NULL NULL YES SE_SPECIFIC YES NULL
def test t3 0 test PRIMARY 1 f0 A 32 NULL NULL SE_SPECIFIC YES NULL
Case 2: IS query uses UDF's to read dynamic table statistics
SET SESSION information_schema_stats_expiry=0;
SELECT table_rows, avg_row_length, data_length, max_data_length, index_length,
data_free, auto_increment, checksum, update_time, check_time
FROM information_schema.tables WHERE table_name in ('t1', 't2');
TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE AUTO_INCREMENT CHECKSUM UPDATE_TIME CHECK_TIME
32 65536 2097152 0 0 0 33 NULL # NULL
24 13 416 3659174697238527 2048 104 33 NULL # NULL
SELECT * FROM information_schema.statistics WHERE table_name='t3'
ORDER BY index_name, seq_in_index;
TABLE_CATALOG TABLE_SCHEMA TABLE_NAME NON_UNIQUE INDEX_SCHEMA INDEX_NAME SEQ_IN_INDEX COLUMN_NAME COLLATION CARDINALITY SUB_PART PACKED NULLABLE INDEX_TYPE COMMENT INDEX_COMMENT IS_VISIBLE EXPRESSION
def test t3 1 test f0 1 f0 A 32 NULL NULL SE_SPECIFIC YES NULL
def test t3 1 test f1 1 f1 A 16 NULL NULL YES SE_SPECIFIC YES NULL
def test t3 1 test f1_2 1 f1 A 8 NULL NULL YES SE_SPECIFIC YES NULL
def test t3 1 test f1_2 2 f2 A 16 NULL NULL YES SE_SPECIFIC YES NULL
def test t3 0 test PRIMARY 1 f0 A 32 NULL NULL SE_SPECIFIC YES NULL
SET SESSION information_schema_stats_expiry=default;
DROP TABLE t1;
DROP TABLE t2;
DROP TABLE t3;
CREATE TEMPORARY TABLE t1 (f1 int, f2 int primary key, UNIQUE KEY (f1));
SHOW COLUMNS FROM t1;
Field Type Null Key Default Extra
f1 int(11) YES UNI NULL NULL
f2 int(11) NO PRI NULL NULL
SHOW INDEXES FROM t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression
t1 0 PRIMARY 1 f2 A 0 NULL NULL BTREE YES NULL
t1 0 f1 1 f1 A 0 NULL NULL YES BTREE YES NULL
SELECT * FROM information_schema.tmp_tables_columns;
ERROR 42S02: Unknown table 'TMP_TABLES_COLUMNS' in information_schema
SELECT * FROM information_schema.tmp_tables_keys;
ERROR 42S02: Unknown table 'TMP_TABLES_KEYS' in information_schema
DROP TEMPORARY TABLE t1;
CREATE TABLE t1 (f1 int);
SELECT TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE
FROM information_schema.tables WHERE table_name='t1';
TABLE_SCHEMA TABLE_NAME TABLE_TYPE
test t1 BASE TABLE
LOCK TABLE t1 READ;
SELECT TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE
FROM information_schema.tables WHERE table_name='t1';
TABLE_SCHEMA TABLE_NAME TABLE_TYPE
test t1 BASE TABLE
PREPARE st2 FROM
"SELECT TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE FROM
information_schema.tables WHERE table_name='t1'";
EXECUTE st2;
TABLE_SCHEMA TABLE_NAME TABLE_TYPE
test t1 BASE TABLE
DEALLOCATE PREPARE st2;
UNLOCK TABLES;
DROP TABLE t1;
CREATE DATABASE abc;
CREATE TABLE abc.memorytable (id INT NOT NULL) ENGINE=MEMORY;
# restart
SELECT * FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'abc';
DROP DATABASE abc;