Repository navigation
Backport #113291 to 26.5: Fix for virtual row is not being applied in some cases - #114219
Conversation
|
Workflow [BackportPR], commit [050b8a6] Summary: ✅ |
|
@groeneai could you please apply the relevant fixes to this branch? I applied these changes to a single branch, and now we need to reapply them to other versions: Adapting the backport of "Fix for virtual row is not being applied in some cases" (upstream #113291)The automated cherry-pick applies the hunks whose context matches and silently drops the rest — no conflict markers, 0. Find the dropped hunksFor every file in the backport commit: git show <backport-commit> --stat # file list
git diff master -- <each source file> # anything from the PR missing here was dropped
1. Restore the
|
|
I cannot push to Two things first, because they change what steps 1-5 are needed for. Step 1 is already fully applied on this branch. Your section-0 check comes out clean for it: The current build break is not a dropped hunk, it is the shape of your own step-2 hunk. All 7 builds fail with 18 errors, one signature:
Two corrections to the procedure for these branches:
For step 5 I took the delete-the-case option rather than forward-porting, because #110121 is labelled Patch against 265-adaptation.patchdiff --git a/src/Functions/FunctionsConversion.h b/src/Functions/FunctionsConversion.h
index 9c1707c9cf9d387..d40f3cf5f54e393 100644
--- a/src/Functions/FunctionsConversion.h
+++ b/src/Functions/FunctionsConversion.h
@@ -3984,7 +3984,7 @@ struct ToStringMonotonicity
/// `DateTime` is formatted in the time zone of the type, and local time decreases when the clocks are
/// turned back, so the order is preserved only if the time zone never changes its offset.
- if (const auto * date_time_type = checkAndGetDataType<DataTypeDateTime>(type_ptr))
+ if (checkAndGetDataType<DataTypeDateTime>(type_ptr))
{
return not_monotonic;
}
diff --git a/src/Functions/tests/gtest_monotonic.cpp b/src/Functions/tests/gtest_monotonic.cpp
index 1cfc29c769081fa..6d2e8883a9d8122 100644
--- a/src/Functions/tests/gtest_monotonic.cpp
+++ b/src/Functions/tests/gtest_monotonic.cpp
@@ -81,29 +81,3 @@ TEST(Monotonicity, Coalesce)
{
testNullWrapperMonotonicity("coalesce", {std::make_shared<DataTypeUInt8>(), std::make_shared<DataTypeUInt8>()});
}
-
-TEST(Monotonicity, ToNullable)
-{
- /// `toNullable` only wraps the value, so it is strictly increasing on the whole range of any argument type.
- const DataTypes argument_types = {
- std::make_shared<DataTypeUInt8>(),
- std::make_shared<DataTypeString>(),
- makeNullable(std::make_shared<DataTypeString>()),
- std::make_shared<DataTypeLowCardinality>(std::make_shared<DataTypeString>()),
- };
-
- for (const auto & argument_type : argument_types)
- {
- SCOPED_TRACE(argument_type->getName());
-
- auto function_base = buildFunction("toNullable", {argument_type});
- ASSERT_TRUE(function_base->hasInformationAboutMonotonicity());
-
- const auto monotonicity = function_base->getMonotonicityForRange(*argument_type, Field{}, Field{});
-
- ASSERT_TRUE(monotonicity.is_monotonic);
- ASSERT_TRUE(monotonicity.is_positive);
- ASSERT_TRUE(monotonicity.is_always_monotonic);
- ASSERT_TRUE(monotonicity.is_strict);
- }
-}
diff --git a/tests/queries/0_stateless/04672_read_in_order_virtual_row_sort_prefix.sql b/tests/queries/0_stateless/04672_read_in_order_virtual_row_sort_prefix.sql
index 3ca17919507bee4..da290bc2e149ba5 100644
--- a/tests/queries/0_stateless/04672_read_in_order_virtual_row_sort_prefix.sql
+++ b/tests/queries/0_stateless/04672_read_in_order_virtual_row_sort_prefix.sql
@@ -18,50 +18,50 @@ INSERT INTO dict VALUES ('r1', 'l1'), ('r2', 'l2'), ('r3', 'l3');
INSERT INTO by_day VALUES ('2020-01-01', 1), ('2020-01-01', 2), ('2020-01-02', 1);
SET optimize_read_in_order = 1, read_in_order_use_virtual_row = 1;
-SET max_bytes_ratio_before_external_join = 0, max_bytes_before_external_join = 0, query_plan_read_in_order_through_join = 1, join_runtime_filter_min_probe_rows = 0;
+SET max_bytes_ratio_before_external_join = 0, max_bytes_before_external_join = 0, query_plan_read_in_order_through_join = 1;
SET query_plan_optimize_join_order_limit = 1, query_plan_optimize_join_order_randomize = 0, query_plan_join_swap_table = 0;
SELECT '--- single table: sorting key (name, code)';
SELECT '-- plain key';
SELECT extract(explain, '(?:Prefix sort description|Read type|Virtual row conversions).*') AS e
-FROM (EXPLAIN PLAN actions = 1, indexes = 0 SELECT * FROM ev ORDER BY name, code LIMIT 5) WHERE e != '';
+FROM (EXPLAIN PLAN actions = 1, indexes = 0, compact = 1, pretty = 1 SELECT * FROM ev ORDER BY name, code LIMIT 5) WHERE e != '';
SELECT '-- cast on the only column';
SELECT extract(explain, '(?:Prefix sort description|Read type|Virtual row conversions).*') AS e
-FROM (EXPLAIN PLAN actions = 1, indexes = 0 SELECT * FROM ev ORDER BY name::Nullable(String) LIMIT 5) WHERE e != '';
+FROM (EXPLAIN PLAN actions = 1, indexes = 0, compact = 1, pretty = 1 SELECT * FROM ev ORDER BY name::Nullable(String) LIMIT 5) WHERE e != '';
SELECT '-- cast on the first of two columns';
SELECT extract(explain, '(?:Prefix sort description|Read type|Virtual row conversions).*') AS e
-FROM (EXPLAIN PLAN actions = 1, indexes = 0 SELECT * FROM ev ORDER BY name::Nullable(String), code LIMIT 5) WHERE e != '';
+FROM (EXPLAIN PLAN actions = 1, indexes = 0, compact = 1, pretty = 1 SELECT * FROM ev ORDER BY name::Nullable(String), code LIMIT 5) WHERE e != '';
SELECT '-- cast on the last of two columns';
SELECT extract(explain, '(?:Prefix sort description|Read type|Virtual row conversions).*') AS e
-FROM (EXPLAIN PLAN actions = 1, indexes = 0 SELECT * FROM ev ORDER BY name, code::Nullable(String) LIMIT 5) WHERE e != '';
+FROM (EXPLAIN PLAN actions = 1, indexes = 0, compact = 1, pretty = 1 SELECT * FROM ev ORDER BY name, code::Nullable(String) LIMIT 5) WHERE e != '';
SELECT '-- toString on the first of two columns';
SELECT extract(explain, '(?:Prefix sort description|Read type|Virtual row conversions).*') AS e
-FROM (EXPLAIN PLAN actions = 1, indexes = 0 SELECT * FROM ev ORDER BY toString(name), code LIMIT 5) WHERE e != '';
+FROM (EXPLAIN PLAN actions = 1, indexes = 0, compact = 1, pretty = 1 SELECT * FROM ev ORDER BY toString(name), code LIMIT 5) WHERE e != '';
SELECT '-- non-key column last';
SELECT extract(explain, '(?:Prefix sort description|Read type|Virtual row conversions).*') AS e
-FROM (EXPLAIN PLAN actions = 1, indexes = 0 SELECT * FROM ev ORDER BY name, code, ref LIMIT 5) WHERE e != '';
+FROM (EXPLAIN PLAN actions = 1, indexes = 0, compact = 1, pretty = 1 SELECT * FROM ev ORDER BY name, code, ref LIMIT 5) WHERE e != '';
SELECT '--- non-strictly monotonic function: the prefix is cut after it';
SELECT extract(explain, '(?:Prefix sort description|Read type|Virtual row conversions).*') AS e
-FROM (EXPLAIN PLAN actions = 1, indexes = 0 SELECT * FROM by_day ORDER BY toStartOfMonth(d), num LIMIT 5) WHERE e != '';
+FROM (EXPLAIN PLAN actions = 1, indexes = 0, compact = 1, pretty = 1 SELECT * FROM by_day ORDER BY toStartOfMonth(d), num LIMIT 5) WHERE e != '';
SELECT '--- INNER JOIN: read-in-order needs the virtual row';
SELECT '-- cast on the first of two key columns';
SELECT extract(explain, '(?:Prefix sort description|Read type|Virtual row conversions).*') AS e
-FROM (EXPLAIN PLAN actions = 1, indexes = 0
+FROM (EXPLAIN PLAN actions = 1, indexes = 0, compact = 1, pretty = 1
SELECT ev.name, ev.code, dict.label FROM ev INNER JOIN dict ON ev.ref = dict.ref
ORDER BY ev.name::Nullable(String), ev.code LIMIT 5) WHERE e != '';
SELECT '-- right table column last';
SELECT extract(explain, '(?:Prefix sort description|Read type|Virtual row conversions).*') AS e
-FROM (EXPLAIN PLAN actions = 1, indexes = 0
+FROM (EXPLAIN PLAN actions = 1, indexes = 0, compact = 1, pretty = 1
SELECT ev.name, ev.code, dict.label FROM ev INNER JOIN dict ON ev.ref = dict.ref
ORDER BY ev.name, ev.code, dict.label LIMIT 5) WHERE e != '';
diff --git a/tests/queries/0_stateless/04695_to_string_monotonicity.reference b/tests/queries/0_stateless/04695_to_string_monotonicity.reference
index 6b482e0810e554d..4b818857bcd8709 100644
--- a/tests/queries/0_stateless/04695_to_string_monotonicity.reference
+++ b/tests/queries/0_stateless/04695_to_string_monotonicity.reference
@@ -15,8 +15,5 @@
2021-11-07 01:59:57
2021-11-07 01:59:58
2021-11-07 01:59:59
-12
-│ Prefix sort description: toString(x) ASC, y ASC
-│ Result sort description: toString(x) ASC, y ASC
│ Prefix sort description: toString(d) ASC, y ASC
│ Result sort description: toString(d) ASC, y ASC
diff --git a/tests/queries/0_stateless/04695_to_string_monotonicity.sql b/tests/queries/0_stateless/04695_to_string_monotonicity.sql
index 4d255e070adf058..1bf4d6c0f27ff81 100644
--- a/tests/queries/0_stateless/04695_to_string_monotonicity.sql
+++ b/tests/queries/0_stateless/04695_to_string_monotonicity.sql
@@ -20,21 +20,14 @@ SELECT toString(toDateTime(1636264799, 'America/New_York')), toString(toDateTime
SELECT count() FROM t_dst WHERE toString(x) >= '2021-11-07 01:59:00';
SELECT toString(x) FROM t_dst ORDER BY toString(x) SETTINGS optimize_read_in_order = 1;
-
-SELECT count() FROM t_utc WHERE toString(x) >= '2021-11-07 06:00:00';
-SELECT trimLeft(explain) FROM (
- EXPLAIN PLAN SELECT * FROM t_utc ORDER BY toString(x), y SETTINGS optimize_read_in_order = 1
-) WHERE explain LIKE '%sort description%';
-
DROP TABLE IF EXISTS t_date;
CREATE TABLE t_date (d Date, y UInt32) ENGINE = MergeTree ORDER BY (d, y);
INSERT INTO t_date SELECT toDate('2021-01-01') + intDiv(number, 4), number % 4 FROM numbers(20);
SELECT trimLeft(explain) FROM (
- EXPLAIN PLAN SELECT * FROM t_date ORDER BY toString(d), y SETTINGS optimize_read_in_order = 1
+ EXPLAIN PLAN actions = 1, compact = 1, pretty = 1 SELECT * FROM t_date ORDER BY toString(d), y SETTINGS optimize_read_in_order = 1
) WHERE explain LIKE '%sort description%';
DROP TABLE t_time;
DROP TABLE t_dst;
-DROP TABLE t_utc;
DROP TABLE t_date;Validated on stock release binaries, using 26.7.4.25 as the fix-present arm (positive control: 26.7's own
For the compile fix I reproduced both shapes with clang-21 under The same patch applies to #114220, with two differences in |
|
@groeneai can you create your branch on top of this in your fork, I'll cherry pick form there then |
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.
|
Pushed: Two commits on top of 1. Adapt the backport (
2. A/B on stock per-branch binaries, 26.7.4.25 as the fix-present arm: unpatched, Unrelated to this branch, but found while checking it and worth your judgement since it is your code: CREATE TABLE t_dst (x DateTime('America/New_York'), y UInt32) ENGINE = MergeTree ORDER BY (x, y);
INSERT INTO t_dst VALUES (toDateTime(1636261200,'America/New_York'), 7), (toDateTime(1636264800,'America/New_York'), 3);
SELECT y FROM t_dst WHERE toString(x) = '2021-11-07 01:00:00' ORDER BY y SETTINGS optimize_read_in_order = 1;Both rows format as |
Original pull-request #113291
This pull-request is a last step of an automated backporting.
Treat it as a standard pull-request: look at the checks and resolve conflicts.
Merge it only if you intend to backport changes to the target branch, otherwise just close it.
The PR source
The PR is created in the CI job
Version info
26.5.7.49