提交 036fea4a authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Add tests for simple one-column index sorting

上级 a92ab735
......@@ -3,6 +3,269 @@
-- Initial Developer: H2 Group
--
-- Test all possible order modes
CREATE TABLE TEST(A INT);
> ok
INSERT INTO TEST VALUES (NULL), (0), (1);
> update count: 3
-- default
SELECT A FROM TEST ORDER BY A;
> A
> ----
> null
> 0
> 1
> rows (ordered): 3
CREATE INDEX A_IDX ON TEST(A);
SELECT A FROM TEST ORDER BY A;
> A
> ----
> null
> 0
> 1
> rows (ordered): 3
EXPLAIN SELECT A FROM TEST ORDER BY A;
>> SELECT A FROM PUBLIC.TEST /* PUBLIC.A_IDX */ ORDER BY 1 /* index sorted */
DROP INDEX A_IDX;
> ok
-- ASC
SELECT A FROM TEST ORDER BY A ASC;
> A
> ----
> null
> 0
> 1
> rows (ordered): 3
CREATE INDEX A_IDX ON TEST(A ASC);
SELECT A FROM TEST ORDER BY A ASC;
> A
> ----
> null
> 0
> 1
> rows (ordered): 3
EXPLAIN SELECT A FROM TEST ORDER BY A ASC;
>> SELECT A FROM PUBLIC.TEST /* PUBLIC.A_IDX */ ORDER BY 1 /* index sorted */
DROP INDEX A_IDX;
> ok
-- ASC NULLS FIRST
SELECT A FROM TEST ORDER BY A ASC NULLS FIRST;
> A
> ----
> null
> 0
> 1
> rows (ordered): 3
CREATE INDEX A_IDX ON TEST(A ASC NULLS FIRST);
SELECT A FROM TEST ORDER BY A ASC NULLS FIRST;
> A
> ----
> null
> 0
> 1
> rows (ordered): 3
EXPLAIN SELECT A FROM TEST ORDER BY A ASC NULLS FIRST;
>> SELECT A FROM PUBLIC.TEST /* PUBLIC.A_IDX */ ORDER BY 1 NULLS FIRST /* index sorted */
DROP INDEX A_IDX;
> ok
-- ASC NULLS LAST
SELECT A FROM TEST ORDER BY A ASC NULLS LAST;
> A
> ----
> 0
> 1
> null
> rows (ordered): 3
CREATE INDEX A_IDX ON TEST(A ASC NULLS LAST);
SELECT A FROM TEST ORDER BY A ASC NULLS LAST;
> A
> ----
> 0
> 1
> null
> rows (ordered): 3
EXPLAIN SELECT A FROM TEST ORDER BY A ASC NULLS LAST;
>> SELECT A FROM PUBLIC.TEST /* PUBLIC.A_IDX */ ORDER BY 1 NULLS LAST /* index sorted */
DROP INDEX A_IDX;
> ok
-- DESC
SELECT A FROM TEST ORDER BY A DESC;
> A
> ----
> 1
> 0
> null
> rows (ordered): 3
CREATE INDEX A_IDX ON TEST(A DESC);
SELECT A FROM TEST ORDER BY A DESC;
> A
> ----
> 1
> 0
> null
> rows (ordered): 3
EXPLAIN SELECT A FROM TEST ORDER BY A DESC;
>> SELECT A FROM PUBLIC.TEST /* PUBLIC.A_IDX */ ORDER BY 1 DESC /* index sorted */
DROP INDEX A_IDX;
> ok
-- DESC NULLS FIRST
SELECT A FROM TEST ORDER BY A DESC NULLS FIRST;
> A
> ----
> null
> 1
> 0
> rows (ordered): 3
CREATE INDEX A_IDX ON TEST(A DESC NULLS FIRST);
SELECT A FROM TEST ORDER BY A DESC NULLS FIRST;
> A
> ----
> null
> 1
> 0
> rows (ordered): 3
EXPLAIN SELECT A FROM TEST ORDER BY A DESC NULLS FIRST;
>> SELECT A FROM PUBLIC.TEST /* PUBLIC.A_IDX */ ORDER BY 1 DESC NULLS FIRST /* index sorted */
DROP INDEX A_IDX;
> ok
-- DESC NULLS LAST
SELECT A FROM TEST ORDER BY A DESC NULLS LAST;
> A
> ----
> 1
> 0
> null
> rows (ordered): 3
CREATE INDEX A_IDX ON TEST(A DESC NULLS LAST);
SELECT A FROM TEST ORDER BY A DESC NULLS LAST;
> A
> ----
> 1
> 0
> null
> rows (ordered): 3
EXPLAIN SELECT A FROM TEST ORDER BY A DESC NULLS LAST;
>> SELECT A FROM PUBLIC.TEST /* PUBLIC.A_IDX */ ORDER BY 1 DESC NULLS LAST /* index sorted */
DROP INDEX A_IDX;
> ok
-- Index selection
CREATE INDEX A_IDX_ASC ON TEST(A ASC);
> ok
CREATE INDEX A_IDX_ASC_NL ON TEST(A ASC NULLS LAST);
> ok
CREATE INDEX A_IDX_DESC ON TEST(A DESC);
> ok
CREATE INDEX A_IDX_DESC_NF ON TEST(A DESC NULLS FIRST);
> ok
EXPLAIN SELECT A FROM TEST ORDER BY A;
>> SELECT A FROM PUBLIC.TEST /* PUBLIC.A_IDX_ASC */ ORDER BY 1 /* index sorted */
EXPLAIN SELECT A FROM TEST ORDER BY A ASC;
>> SELECT A FROM PUBLIC.TEST /* PUBLIC.A_IDX_ASC */ ORDER BY 1 /* index sorted */
EXPLAIN SELECT A FROM TEST ORDER BY A NULLS FIRST;
>> SELECT A FROM PUBLIC.TEST /* PUBLIC.A_IDX_ASC */ ORDER BY 1 NULLS FIRST /* index sorted */
EXPLAIN SELECT A FROM TEST ORDER BY A NULLS LAST;
>> SELECT A FROM PUBLIC.TEST /* PUBLIC.A_IDX_ASC_NL */ ORDER BY 1 NULLS LAST /* index sorted */
EXPLAIN SELECT A FROM TEST ORDER BY A DESC;
>> SELECT A FROM PUBLIC.TEST /* PUBLIC.A_IDX_DESC */ ORDER BY 1 DESC /* index sorted */
EXPLAIN SELECT A FROM TEST ORDER BY A DESC NULLS FIRST;
>> SELECT A FROM PUBLIC.TEST /* PUBLIC.A_IDX_DESC_NF */ ORDER BY 1 DESC NULLS FIRST /* index sorted */
EXPLAIN SELECT A FROM TEST ORDER BY A DESC NULLS LAST;
>> SELECT A FROM PUBLIC.TEST /* PUBLIC.A_IDX_DESC */ ORDER BY 1 DESC NULLS LAST /* index sorted */
DROP INDEX A_IDX_ASC;
> ok
DROP INDEX A_IDX_DESC;
> ok
CREATE INDEX A_IDX_ASC_NF ON TEST(A ASC NULLS FIRST);
> ok
CREATE INDEX A_IDX_DESC_NL ON TEST(A DESC NULLS LAST);
> ok
EXPLAIN SELECT A FROM TEST ORDER BY A;
>> SELECT A FROM PUBLIC.TEST /* PUBLIC.A_IDX_ASC_NF */ ORDER BY 1 /* index sorted */
EXPLAIN SELECT A FROM TEST ORDER BY A ASC;
>> SELECT A FROM PUBLIC.TEST /* PUBLIC.A_IDX_ASC_NF */ ORDER BY 1 /* index sorted */
EXPLAIN SELECT A FROM TEST ORDER BY A NULLS FIRST;
>> SELECT A FROM PUBLIC.TEST /* PUBLIC.A_IDX_ASC_NF */ ORDER BY 1 NULLS FIRST /* index sorted */
EXPLAIN SELECT A FROM TEST ORDER BY A NULLS LAST;
>> SELECT A FROM PUBLIC.TEST /* PUBLIC.A_IDX_ASC_NL */ ORDER BY 1 NULLS LAST /* index sorted */
EXPLAIN SELECT A FROM TEST ORDER BY A DESC;
>> SELECT A FROM PUBLIC.TEST /* PUBLIC.A_IDX_DESC_NL */ ORDER BY 1 DESC /* index sorted */
EXPLAIN SELECT A FROM TEST ORDER BY A DESC NULLS FIRST;
>> SELECT A FROM PUBLIC.TEST /* PUBLIC.A_IDX_DESC_NF */ ORDER BY 1 DESC NULLS FIRST /* index sorted */
EXPLAIN SELECT A FROM TEST ORDER BY A DESC NULLS LAST;
>> SELECT A FROM PUBLIC.TEST /* PUBLIC.A_IDX_DESC_NL */ ORDER BY 1 DESC NULLS LAST /* index sorted */
DROP TABLE TEST;
> ok
-- Other tests
create table test(a int, b int);
> ok
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论