ClickHouse/tests/queries/0_stateless/00836_indices_alter_replicated_zookeeper.sql

114 lines
3.2 KiB
MySQL
Raw Normal View History

2020-11-11 15:29:36 +00:00
DROP TABLE IF EXISTS minmax_idx;
DROP TABLE IF EXISTS minmax_idx_r;
DROP TABLE IF EXISTS minmax_idx2;
DROP TABLE IF EXISTS minmax_idx2_r;
2019-01-17 09:16:39 +00:00
2020-02-18 09:02:40 +00:00
SET replication_alter_partitions_sync = 2;
2019-02-12 17:54:52 +00:00
2020-11-11 15:29:36 +00:00
CREATE TABLE minmax_idx
2019-01-17 09:16:39 +00:00
(
u64 UInt64,
i32 Int32
2020-08-26 17:45:20 +00:00
) ENGINE = ReplicatedMergeTree('/clickhouse/tables/test_00836/indices_alter1', 'r1')
2019-01-17 09:16:39 +00:00
ORDER BY u64;
2020-11-11 15:29:36 +00:00
CREATE TABLE minmax_idx_r
2019-01-17 09:16:39 +00:00
(
u64 UInt64,
i32 Int32
2020-08-26 17:45:20 +00:00
) ENGINE = ReplicatedMergeTree('/clickhouse/tables/test_00836/indices_alter1', 'r2')
2019-01-17 09:16:39 +00:00
ORDER BY u64;
2020-11-11 15:29:36 +00:00
INSERT INTO minmax_idx VALUES (1, 2);
2019-01-17 09:16:39 +00:00
2020-11-11 15:29:36 +00:00
SYSTEM SYNC REPLICA minmax_idx_r;
2019-01-17 09:16:39 +00:00
2020-11-11 15:29:36 +00:00
ALTER TABLE minmax_idx ADD INDEX idx1 u64 * i32 TYPE minmax GRANULARITY 10;
ALTER TABLE minmax_idx_r ADD INDEX idx2 u64 + i32 TYPE minmax GRANULARITY 10;
ALTER TABLE minmax_idx ADD INDEX idx3 u64 - i32 TYPE minmax GRANULARITY 10 AFTER idx1;
2019-01-17 09:16:39 +00:00
2020-11-11 15:29:36 +00:00
SHOW CREATE TABLE minmax_idx;
SHOW CREATE TABLE minmax_idx_r;
2019-01-17 09:16:39 +00:00
2020-11-11 15:29:36 +00:00
SELECT * FROM minmax_idx WHERE u64 * i32 = 2 ORDER BY (u64, i32);
SELECT * FROM minmax_idx_r WHERE u64 * i32 = 2 ORDER BY (u64, i32);
2019-01-17 09:16:39 +00:00
2020-11-11 15:29:36 +00:00
INSERT INTO minmax_idx VALUES (1, 4);
INSERT INTO minmax_idx_r VALUES (3, 2);
INSERT INTO minmax_idx VALUES (1, 5);
INSERT INTO minmax_idx_r VALUES (65, 75);
INSERT INTO minmax_idx VALUES (19, 9);
2019-01-17 09:16:39 +00:00
2020-11-11 15:29:36 +00:00
SYSTEM SYNC REPLICA minmax_idx;
SYSTEM SYNC REPLICA minmax_idx_r;
2019-01-17 09:16:39 +00:00
2020-11-11 15:29:36 +00:00
SELECT * FROM minmax_idx WHERE u64 * i32 > 1 ORDER BY (u64, i32);
SELECT * FROM minmax_idx_r WHERE u64 * i32 > 1 ORDER BY (u64, i32);
2019-01-17 09:16:39 +00:00
2020-11-11 15:29:36 +00:00
ALTER TABLE minmax_idx DROP INDEX idx1;
2019-01-17 09:16:39 +00:00
2020-11-11 15:29:36 +00:00
SHOW CREATE TABLE minmax_idx;
SHOW CREATE TABLE minmax_idx_r;
2019-01-17 09:16:39 +00:00
2020-11-11 15:29:36 +00:00
SELECT * FROM minmax_idx WHERE u64 * i32 > 1 ORDER BY (u64, i32);
SELECT * FROM minmax_idx_r WHERE u64 * i32 > 1 ORDER BY (u64, i32);
2019-01-17 09:16:39 +00:00
2020-11-11 15:29:36 +00:00
ALTER TABLE minmax_idx DROP INDEX idx2;
ALTER TABLE minmax_idx_r DROP INDEX idx3;
2019-01-17 09:16:39 +00:00
2020-11-11 15:29:36 +00:00
SHOW CREATE TABLE minmax_idx;
SHOW CREATE TABLE minmax_idx_r;
2019-01-17 09:16:39 +00:00
2020-11-11 15:29:36 +00:00
ALTER TABLE minmax_idx ADD INDEX idx1 u64 * i32 TYPE minmax GRANULARITY 10;
2019-01-17 09:16:39 +00:00
2020-11-11 15:29:36 +00:00
SHOW CREATE TABLE minmax_idx;
SHOW CREATE TABLE minmax_idx_r;
2019-01-17 09:16:39 +00:00
2020-11-11 15:29:36 +00:00
SELECT * FROM minmax_idx WHERE u64 * i32 > 1 ORDER BY (u64, i32);
SELECT * FROM minmax_idx_r WHERE u64 * i32 > 1 ORDER BY (u64, i32);
2019-01-17 09:16:39 +00:00
2020-11-11 15:29:36 +00:00
CREATE TABLE minmax_idx2
2019-01-17 09:16:39 +00:00
(
u64 UInt64,
i32 Int32,
INDEX idx1 u64 + i32 TYPE minmax GRANULARITY 10,
INDEX idx2 u64 * i32 TYPE minmax GRANULARITY 10
2020-08-26 17:45:20 +00:00
) ENGINE = ReplicatedMergeTree('/clickhouse/tables/test_00836/indices_alter2', 'r1')
ORDER BY u64;
2019-01-17 09:16:39 +00:00
2020-11-11 15:29:36 +00:00
CREATE TABLE minmax_idx2_r
2019-01-17 09:16:39 +00:00
(
u64 UInt64,
i32 Int32,
INDEX idx1 u64 + i32 TYPE minmax GRANULARITY 10,
INDEX idx2 u64 * i32 TYPE minmax GRANULARITY 10
2020-08-26 17:45:20 +00:00
) ENGINE = ReplicatedMergeTree('/clickhouse/tables/test_00836/indices_alter2', 'r2')
ORDER BY u64;
2019-01-17 09:16:39 +00:00
2020-11-11 15:29:36 +00:00
SHOW CREATE TABLE minmax_idx2;
SHOW CREATE TABLE minmax_idx2_r;
2019-01-17 09:16:39 +00:00
2020-11-11 15:29:36 +00:00
INSERT INTO minmax_idx2 VALUES (1, 2);
INSERT INTO minmax_idx2_r VALUES (1, 3);
2019-01-17 09:16:39 +00:00
2020-11-11 15:29:36 +00:00
SYSTEM SYNC REPLICA minmax_idx2;
SYSTEM SYNC REPLICA minmax_idx2_r;
2019-01-17 09:16:39 +00:00
2020-11-11 15:29:36 +00:00
SELECT * FROM minmax_idx2 WHERE u64 * i32 >= 2 ORDER BY (u64, i32);
SELECT * FROM minmax_idx2_r WHERE u64 * i32 >= 2 ORDER BY (u64, i32);
2019-01-17 09:16:39 +00:00
2020-11-11 15:29:36 +00:00
ALTER TABLE minmax_idx2_r DROP INDEX idx1, DROP INDEX idx2;
2019-01-17 09:16:39 +00:00
2020-11-11 15:29:36 +00:00
SHOW CREATE TABLE minmax_idx2;
SHOW CREATE TABLE minmax_idx2_r;
2019-01-17 09:16:39 +00:00
2020-11-11 15:29:36 +00:00
SELECT * FROM minmax_idx2 WHERE u64 * i32 >= 2 ORDER BY (u64, i32);
SELECT * FROM minmax_idx2_r WHERE u64 * i32 >= 2 ORDER BY (u64, i32);
2019-01-17 09:16:39 +00:00
2020-11-11 15:29:36 +00:00
DROP TABLE minmax_idx;
DROP TABLE minmax_idx_r;
DROP TABLE minmax_idx2;
DROP TABLE minmax_idx2_r;