1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
|
mysql> show create table TABLES\G *************************** 1. row *************************** Table: TABLES Create Table: CREATE TEMPORARY TABLE `TABLES` ( `TABLE_CATALOG` varchar(512) NOT NULL DEFAULT '', `TABLE_SCHEMA` varchar(64) NOT NULL DEFAULT '', `TABLE_NAME` varchar(64) NOT NULL DEFAULT '', `TABLE_TYPE` varchar(64) NOT NULL DEFAULT '', `ENGINE` varchar(64) DEFAULT NULL, `VERSION` bigint(21) unsigned DEFAULT NULL, `ROW_FORMAT` varchar(10) DEFAULT NULL, `TABLE_ROWS` bigint(21) unsigned DEFAULT NULL, `AVG_ROW_LENGTH` bigint(21) unsigned DEFAULT NULL, `DATA_LENGTH` bigint(21) unsigned DEFAULT NULL, `MAX_DATA_LENGTH` bigint(21) unsigned DEFAULT NULL, `INDEX_LENGTH` bigint(21) unsigned DEFAULT NULL, `DATA_FREE` bigint(21) unsigned DEFAULT NULL, `AUTO_INCREMENT` bigint(21) unsigned DEFAULT NULL, `CREATE_TIME` datetime DEFAULT NULL, `UPDATE_TIME` datetime DEFAULT NULL, `CHECK_TIME` datetime DEFAULT NULL, `TABLE_COLLATION` varchar(32) DEFAULT NULL, `CHECKSUM` bigint(21) unsigned DEFAULT NULL, `CREATE_OPTIONS` varchar(255) DEFAULT NULL, `TABLE_COMMENT` varchar(2048) NOT NULL DEFAULT '' ) ENGINE=MEMORY DEFAULT CHARSET=utf8 1 row in set (0.00 sec)
mysql> show create table STATISTICS\G *************************** 1. row *************************** Table: STATISTICS Create Table: CREATE TEMPORARY TABLE `STATISTICS` ( `TABLE_CATALOG` varchar(512) NOT NULL DEFAULT '', `TABLE_SCHEMA` varchar(64) NOT NULL DEFAULT '', `TABLE_NAME` varchar(64) NOT NULL DEFAULT '', `NON_UNIQUE` bigint(1) NOT NULL DEFAULT '0', `INDEX_SCHEMA` varchar(64) NOT NULL DEFAULT '', `INDEX_NAME` varchar(64) NOT NULL DEFAULT '', `SEQ_IN_INDEX` bigint(2) NOT NULL DEFAULT '0', `COLUMN_NAME` varchar(64) NOT NULL DEFAULT '', `COLLATION` varchar(1) DEFAULT NULL, `CARDINALITY` bigint(21) DEFAULT NULL, `SUB_PART` bigint(3) DEFAULT NULL, `PACKED` varchar(10) DEFAULT NULL, `NULLABLE` varchar(3) NOT NULL DEFAULT '', `INDEX_TYPE` varchar(16) NOT NULL DEFAULT '', `COMMENT` varchar(16) DEFAULT NULL, `INDEX_COMMENT` varchar(1024) NOT NULL DEFAULT '' ) ENGINE=MEMORY DEFAULT CHARSET=utf8 1 row in set (0.00 sec)
mysql> select -> table_schema, table_name, index_name, -> max(seq_in_index) -> from -> STATISTICS -> group by table_schema , table_name , index_name\G
*************************** 10. row *************************** table_schema: burn_test table_name: test_index_2 index_name: idx_mul_ab max(seq_in_index): 2
mysql> select -> table_schema, table_name, index_name, cardinality -> from -> STATISTICS -> where -> (table_schema , table_name, index_name, seq_in_index) in -> (select -> table_schema, table_name, -> index_name, max(seq_in_index) -> from -> STATISTICS -> group by table_schema , table_name , index_name)\G
*************************** 1. row *************************** table_schema: burn_test table_name: Orders index_name: PRIMARY cardinality: 5 *************************** 2. row *************************** table_schema: burn_test table_name: Orders_MV index_name: product_name cardinality: 3 *************************** 3. row *************************** table_schema: burn_test table_name: child index_name: par_ind cardinality: 0 *************************** 4. row *************************** table_schema: burn_test table_name: parent index_name: PRIMARY cardinality: 1 *************************** 5. row *************************** table_schema: burn_test table_name: t4 index_name: PRIMARY cardinality: 4
SELECT t.TABLE_SCHEMA,t.TABLE_NAME,INDEX_NAME, CARDINALITY, TABLE_ROWS, CARDINALITY/TABLE_ROWS AS SELECTIVITY FROM TABLES t, ( SELECT table_schema, table_name, index_name, cardinality FROM STATISTICS WHERE (table_schema,table_name,index_name,seq_in_index) IN ( SELECT table_schema, table_name, index_name, MAX(seq_in_index) FROM STATISTICS GROUP BY table_schema , table_name , index_name ) ) s WHERE t.table_schema = s.table_schema AND t.table_name = s.table_name AND t.table_schema = 'employees' ORDER BY SELECTIVITY;
+ | TABLE_SCHEMA | TABLE_NAME | index_name | cardinality | TABLE_ROWS | SELECTIVITY | + | employees | dept_emp | dept_no | 8 | 330400 | 0.0000 | | employees | salaries | PRIMARY | 286271 | 2760952 | 0.1037 | | employees | dept_manager | dept_no | 9 | 24 | 0.3750 | | employees | titles | PRIMARY | 296887 | 440887 | 0.6734 | | employees | dept_emp | PRIMARY | 298761 | 330400 | 0.9042 | | employees | titles | PRIMARY | 440166 | 440887 | 0.9984 | | employees | salaries | PRIMARY | 2760952 | 2760952 | 1.0000 | | employees | dept_manager | PRIMARY | 24 | 24 | 1.0000 | | employees | titles | PRIMARY | 440887 | 440887 | 1.0000 | | employees | departments | PRIMARY | 9 | 9 | 1.0000 | | employees | employees | PRIMARY | 298124 | 298124 | 1.0000 | | employees | dept_emp | PRIMARY | 330400 | 330400 | 1.0000 | | employees | dept_manager | PRIMARY | 24 | 24 | 1.0000 | | employees | departments | dept_name | 9 | 9 | 1.0000 | +
mysql> select * from x$schema_index_statistics limit 1\G *************************** 1. row *************************** table_schema: employees table_name: employees index_name: PRIMARY rows_selected: 300024 select_latency: 370177723990 rows_inserted: 0 insert_latency: 0 rows_updated: 0 update_latency: 0 rows_deleted: 0 delete_latency: 0 1 row in set (0.00 sec)
|