Repository navigation
[Bug] Make table-model LIMIT 0 return zero rows - #18857
Open
JackieTien97 wants to merge 1 commit into
Open
JackieTien97 wants to merge 1 commit into
JackieTien97 wants to merge 1 commit into
Conversation
Replace zero limits with empty relations before limit pushdown and TopK planning. Preserve empty-input semantics for scalar subqueries, outer and ASOF joins, sorting, and set operations, and fix ValuesNode serialization. Add focused planner, operator, serialization, and SQL integration coverage. Verified both locales with full-reactor compilation and focused unit tests, plus table integration tests on one and three DataNodes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
In the table model, an explicit
LIMIT 0can be pushed into a scan and then eliminated because the scan also uses zero to mean "unlimited". As a result, queries such asSELECT * FROM t LIMIT 0can return rows.This PR makes an explicit
LIMIT 0return zero rows while preserving result column names and types, aligning its behavior with MySQL and PostgreSQL.Behavior change
SELECT * FROM t LIMIT 0SELECT count(*) FROM t LIMIT 0SELECT count(*) FROM (SELECT * FROM t LIMIT 0) q0SELECT (SELECT v FROM t LIMIT 0) AS valueNULLApplications that used
LIMIT 0to request an unlimited result should omitLIMITor useLIMIT ALL. Positive limits and offsets retain their existing behavior. This change is limited to the table model; tree-modelLIMITvalidation is unchanged.Implementation
ValuesNoderelations before scan pushdown, TopK planning, and subquery rewrites. Preserve output symbols and expose the values node's exact cardinality to existing optimizations.ValuesNodeserialization so the buffer and stream encodings agree, and deserialize the column count and row count using their encoded integer widths.Test coverage
The new
IoTDBLimitZeroITcovers scans and expressions; tag/field filters; zero, positive, and maximum offsets; sorting and TopK; global/grouped/distinct aggregation and HAVING; window functions, fill, and gap fill; nested limits; table views; UNION/INTERSECT/EXCEPT with DISTINCT/ALL semantics; inner, cross, outer, and ASOF joins; scalar, EXISTS, IN, and quantified subqueries, including correlated cases; inline/materialized CTEs; queries without FROM; information schema and SHOW DEVICES; JDBC column metadata; and INSERT ... SELECT.Controls also check omitted limits,
LIMIT ALL, positive limits, invalid columns/tables, negative limits, and multiple-row scalar subquery errors.Unit coverage includes zero-limit logical/distributed plans, existing limit/offset and set-operation optimizations, scalar-operator behavior for empty/single/multiple rows and empty batches, and values serialization through both output APIs and a read-only input buffer.
Validation
All checks passed with JDK 17:
IoTDBLimitZeroIT,TableSimpleIT, English, 1 ConfigNode + 1 DataNodeIoTDBLimitZeroIT,TableClusterIT+with-zh-locale, 1 ConfigNode + 3 DataNodesmvn test-compile -DskipTestsmvn test-compile -DskipTests -P with-zh-localeThe final Chinese cluster validation used a clean reactor
verifybuild with-pl integration-test -am -P TableClusterIT,with-integration-tests,with-zh-locale, selecting only the focused unit tests and-Dit.test=IoTDBLimitZeroIT. Formatting, Checkstyle, and license checks passed.This PR has:
Key changed/added classes
RemoveZeroLimit,LogicalOptimizeFactory,QueryCardinalityUtil,TransformSortToStreamSort,PushPredicateIntoTableScan,EnforceSingleRowOperator,TableOperatorGenerator,ValuesNode, andIoTDBLimitZeroIT.