CREATE TABLE table_name (col1, col2,... COLUMNSTORE INDEX [index_name] [(col1, col2,...)]);
CREATE COLUMNSTORE INDEX [index_name] ON table_name[(col1, col2,...)];ALTER TABLE table_name ADD COLUMNSTORE INDEX [index_name] [(col1, col2,...)];
ALTER TABLE table_name DROP INDEX index_name;
ALTER TABLE table_name RENAME index old_index_name to new_index_name;
SELECT a FROM t IGNORE INDEX (csi);
SELECT a FROM t FORCE INDEX (csi);
SELECT /*+PARALLEL(2)*/ a FROM t FORCE INDEX (csi);
CREATE TABLE t (a int, columnstore index csi (a));INSERT INTO t VALUES (0), (1), (2);SHOW CREATE TABLE t;SHOW INDEX FROM t;
MySQL [test]> CREATE TABLE t (a int, columnstore index csi (a));Query OK, 0 rows affected (0.01 sec)MySQL [test]> INSERT INTO t VALUES (0), (1), (2);Query OK, 3 rows affected (0.01 sec) Records: 3 Duplicates: 0 Warnings: 0MySQL [test]> SHOW CREATE TABLE t;+-------+---------------------------------------------------------------------------------------------------------------+| Table | Create Table |+-------+---------------------------------------------------------------------------------------------------------------+| t | CREATE TABLE `t` ( `a` int DEFAULT NULL, COLUMNSTORE KEY `csi` (`a`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 |+-------+---------------------------------------------------------------------------------------------------------------+MySQL [test]> SHOW INDEX FROM t;+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+-------------+---------+---------------+---------+------------+| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | Expression |+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+-------------+---------+---------------+---------+------------+| t | 1 | csi | 1 | a | NULL | 1 | NULL | NULL | YES | COLUMNSTORE | | | YES | NULL |+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+-------------+---------+---------------+---------+------------+1 row in set (0.00 sec)
SELECT a FROM t FORCE INDEX (csi);EXPLAIN FORMAT=TREE SELECT a FROM t FORCE INDEX (csi);
MySQL [test]> SELECT a FROM t FORCE INDEX (csi);+------+| a |+------+| 0 || 1 || 2 |+------+3 rows in set (0.00 sec)MySQL [test]> EXPLAIN FORMAT=TREE SELECT a FROM t FORCE INDEX (csi);+---------------------------------------------------------------+| EXPLAIN |+---------------------------------------------------------------+| -> COLUMNSTORE Index scan on t using csi (cost=1.30 rows=3) |+---------------------------------------------------------------+1 row in set (0.00 sec)
SELECT a FROM t IGNORE INDEX (csi);EXPLAIN FORMAT=TREE SELECT a FROM t IGNORE INDEX (csi);
MySQL [test]> SELECT a FROM t IGNORE INDEX (csi);+------+| a |+------+| 0 || 1 || 2 |+------+3 rows in set (0.00 sec)MySQL [test]> EXPLAIN FORMAT=TREE SELECT a FROM t IGNORE INDEX (csi);+-----------------------------------------+| EXPLAIN |+-----------------------------------------+| -> Table scan on t (cost=0.55 rows=3) |+-----------------------------------------+1 row in set (0.00 sec)
本页内容是否解决了您的问题?