SQLite outer query is returning results not found in inner query

我是研究僧i 提交于 2019-12-05 15:26:28

I can verify that it happens with SQLite add-on for Firefox as well.

If it is any consolation, this form works:

SELECT DISTINCT "number" FROM (SELECT "letter", "number" FROM "test"
ORDER BY "letter", "number") AS "test" ORDER BY "letter" LIMIT 1;

I believe the SQLite spec ignores the LIMIT clause in inner queries and migrates it outside. Without the limit:

SELECT DISTINCT "number" FROM (SELECT "letter", "number" FROM "test"
ORDER BY "letter", "number") AS "test";

It returns

1
2
(2 rows)

Interesting to note that this also returns the correct results

SELECT number FROM (SELECT letter, number FROM test
ORDER BY letter, number LIMIT 1) AS test;

The two plans can be compared using EXPLAIN.
DESCRIBE is adding a lot of operations, in-lining and optimizing the inner query (incorrectly).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!