Repository navigation
Fix for virtual row is not being applied in some cases - #113291
Conversation
|
Workflow [PR], commit [c5410fd] Summary: ❌
AI ReviewSummaryThis PR does two related things: it allows Findings
Final Verdict
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 66/74 (89.19%) · Uncovered code |
|
@groeneai, please suggest someone suitable to review this PR and tag them with a review request. |
|
cc @KochetovNicolai @nihalzp, could you review this? @KochetovNicolai wrote the @nihalzp wrote the adjacent One thing worth a look during review: |
|
|
||
| SELECT '--- results stay correctly ordered'; | ||
|
|
||
| SELECT groupArray(t) = arraySort(x -> x, groupArray(t)) FROM ( |
There was a problem hiding this comment.
This only proves that the returned tuples are internally sorted. Because the two INSERTs never put the same (name, code) into different parts, it would still pass if the relaxed prefix-only virtual row returned a sorted but wrong top-N set when ref / dict.label breaks ties across parts.
Could we duplicate a prefix across the two parts and compare the optimized result against SETTINGS optimize_read_in_order = 0, read_in_order_use_virtual_row = 0, like the existing 04549_* regressions do?
Avogar
left a comment
There was a problem hiding this comment.
Looks good. The comment from the bot about toString(String) worth fixing I think.
| -- Monotonicity of `toString` for date and time types, see `ToStringMonotonicity`. | ||
|
|
||
| DROP TABLE IF EXISTS t_time; | ||
| CREATE TABLE t_time (x Time) ENGINE = MergeTree ORDER BY x; |
There was a problem hiding this comment.
This regression is supposed to cover Time64 too, but it only exercises Time. The new ToStringMonotonicity branch explicitly changes DataTypeTime64, and the changelog entry calls out Time64 incorrect results, so we need the same filter / ORDER BY toString(x) checks for a Time64 table here as well. Otherwise a Time64-only regression can slip through while this test still passes.
Backport #113291 to 26.7: Fix for virtual row is not being applied in some cases
Three things the automated cherry-pick left in a state that does not build or pass on 26.5. FunctionsConversion.h: the DateTime branch of ToStringMonotonicity binds a variable it never reads, which is -Wunused-but-set-variable and therefore an error under -Weverything -Werror. All 7 Build (*) jobs fail with this one signature, 18 times. Dropping the binding makes the block byte-identical to the same block on 26.6. 04695_to_string_monotonicity: the t_utc table was removed from the setup but two queries against it and its DROP were left behind, so the test aborts with UNKNOWN_TABLE. Its .reference still carried the three corresponding lines. 04672 and 04695: join_runtime_filter_min_probe_rows does not exist on 26.5, so the SET raises UNKNOWN_SETTING before any assertion runs. Only that one clause is removed; max_bytes_ratio_before_external_join does exist here, so the resulting SET line is byte-identical to the merged 26.7 backport, and 04029_join_convert_to_fixed_hash_table needs no change at all. explain_query_plan_default is also absent on 26.5, so instead of pinning it the EXPLAIN PLAN calls pass compact = 1, pretty = 1 explicitly, which keeps the expected output byte-identical to master.
The case asserts hasInformationAboutMonotonicity() on toNullable, but that monotonicity was not added by #113291. It came from #110121, which is labelled pr-performance and carries no backport label, so 26.5 does not have it and the assertion fails under asan_ubsan and tsan. Deleting the one case is the smaller change. Forward-porting the toNullable monotonicity to 26.5 instead is the alternative; that is a call for the release owner, so this is a separate commit and can be dropped on its own.
Resolved conflicts with #113291: keep this PR's covered-prefix comparison (`sort_prefix_limit`) and drop the strict `checkVirtualRowCoversSortDescription` debug check it supersedes; adopt master's `do_debug_checks` constexpr style and the `setVirtualRow` pk-block return both sides introduced.
Backport #113291 to 26.5: Fix for virtual row is not being applied in some cases
Backport #113291 to 26.6: Fix for virtual row is not being applied in some cases
…applied in some cases
…applied in some cases
Two stateless tests from ClickHouse#113291 cannot run on 26.6 as cherry-picked, so they fail before any assertion executes. 04672: join_runtime_filter_min_probe_rows does not exist on 26.6 (added by ClickHouse#104860, settings history 26.8), so the SET at line 21 aborts the test with UNKNOWN_SETTING. Dropping that one clause makes the line identical to the merged 26.7 backport. max_bytes_ratio_before_external_join does exist here, so it stays and 04029 needs no change. 04695: the t_utc block was removed from this branch but the trailing DROP TABLE t_utc and the three matching reference lines were left behind, so the test dies with UNKNOWN_TABLE. Both files: EXPLAIN PLAN defaults to actions=1, compact=1, pretty=1 only from 26.7 via explain_query_plan_default, which does not exist on 26.6, so the references written for master do not match. Pinning the three options explicitly restores the byte-exact output. All three are needed: compact and pretty without actions collapse the plan and hide the sort description rows. Verified with clickhouse local on stock 26.6.3.30 and on a master build. On 26.6 both tests now run to completion and every remaining difference is the defect ClickHouse#113291 fixes. On master the same files match the references byte for byte, so the pinning loses no coverage.
This is the only failing gtest on asan_ubsan and tsan. ClickHouse#113291 added the TEST, but the monotonicity it asserts lives in src/Functions/toNullable.cpp and came from ClickHouse#110121, which is labelled pr-performance and was not backported: hasInformationAboutMonotonicity is absent from toNullable.cpp on 26.6 and present on 26.7, which is why 26.7 went green. Separate commit so it can be dropped if ClickHouse#110121 is backported instead.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed wrong monotonicity metadata for
toStringandCAST(..., 'Nullable(String)')over aStringcolumn. As a result the read-in-order optimization was silently skipped and queries withORDER BY <sorting key columns> LIMIT nsorted the whole table instead of stopping early.Fixed the read-in-order with virtual row optimization being silently skipped for
ORDER BYover a prefix of the table's sorting keyFix incorrect results for queries with a filter or
ORDER BYontoStringof aTime,Time64, orDateTimecolumn whose time zone has daylight saving time. FunctiontoStringwas assumed to preserve the order of such columns, but it does not:Timeis formatted with a sign and a variable number of digits for hours ('99:00:00'is greater than'100:00:00'as a string), and local time goes backwards when the clocks are turned back. As a result the primary key index could exclude parts holding matching rows, andoptimize_read_in_ordercould return unsorted results.Version info
26.8.1.1127(included in26.8and later)26.7.4.19,26.6.3.37,26.5.7.49