Merge pull request #50923 from ClickHouse/read-in-order-proj-bug

Do not apply projection if read-in-order was enabled.
This commit is contained in:
Nikolai Kochetov 2023-06-14 13:13:25 +02:00 committed by GitHub
commit 5163927b7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 57 additions and 0 deletions

View File

@ -38,6 +38,9 @@ bool canUseProjectionForReadingStep(ReadFromMergeTree * reading)
if (reading->isParallelReadingEnabled()) if (reading->isParallelReadingEnabled())
return false; return false;
if (reading->readsInOrder())
return false;
// Currently projection don't support deduplication when moving parts between shards. // Currently projection don't support deduplication when moving parts between shards.
if (reading->getContext()->getSettingsRef().allow_experimental_query_deduplication) if (reading->getContext()->getSettingsRef().allow_experimental_query_deduplication)
return false; return false;

View File

@ -1427,6 +1427,11 @@ bool ReadFromMergeTree::requestReadingInOrder(size_t prefix_size, int direction,
return true; return true;
} }
bool ReadFromMergeTree::readsInOrder() const
{
return reader_settings.read_in_order;
}
void ReadFromMergeTree::updatePrewhereInfo(const PrewhereInfoPtr & prewhere_info_value) void ReadFromMergeTree::updatePrewhereInfo(const PrewhereInfoPtr & prewhere_info_value)
{ {
query_info.prewhere_info = prewhere_info_value; query_info.prewhere_info = prewhere_info_value;

View File

@ -161,6 +161,7 @@ public:
/// Returns `false` if requested reading cannot be performed. /// Returns `false` if requested reading cannot be performed.
bool requestReadingInOrder(size_t prefix_size, int direction, size_t limit); bool requestReadingInOrder(size_t prefix_size, int direction, size_t limit);
bool readsInOrder() const;
void updatePrewhereInfo(const PrewhereInfoPtr & prewhere_info_value); void updatePrewhereInfo(const PrewhereInfoPtr & prewhere_info_value);

View File

@ -0,0 +1,4 @@
00000000-0000-0000-0000-000000000000 1643760000 0
00000000-0000-0000-0000-000000000000 1643760000 0
00000000-0000-0000-0000-000000000000 1643760000 0
00000000-0000-0000-0000-000000000000 1643760000 0

View File

@ -0,0 +1,44 @@
create table events (
`organisation_id` UUID,
`session_id` UUID,
`id` UUID DEFAULT generateUUIDv4(),
`timestamp` UInt64,
`payload` String,
`customer_id` UUID,
`call_id` String,
PROJECTION events_by_session_and_org
(
SELECT *
ORDER BY
organisation_id,
session_id,
timestamp
),
PROJECTION events_by_session
(
SELECT *
ORDER BY
session_id,
timestamp
),
PROJECTION events_by_session_and_customer
(
SELECT *
ORDER BY
customer_id,
session_id,
timestamp
),
PROJECTION events_by_call_id
(
SELECT *
ORDER BY
call_id,
timestamp
)) engine = MergeTree order by (organisation_id, session_id, timestamp) settings index_granularity = 3;
insert into events values (reinterpretAsUUID(0), reinterpretAsUUID(1), reinterpretAsUUID(0), toDateTime('2022-02-02', 'UTC'), toString(0), reinterpretAsUUID(0), toString(0)), (reinterpretAsUUID(0), reinterpretAsUUID(1), reinterpretAsUUID(0), toDateTime('2022-02-02', 'UTC'), toString(0), reinterpretAsUUID(0), toString(0)), (reinterpretAsUUID(1), reinterpretAsUUID(0), reinterpretAsUUID(0), toDateTime('2022-02-02', 'UTC'), toString(0), reinterpretAsUUID(0), toString(0)), (reinterpretAsUUID(1), reinterpretAsUUID(0), reinterpretAsUUID(0), toDateTime('2022-02-02', 'UTC'), toString(0), reinterpretAsUUID(0), toString(0)), (reinterpretAsUUID(3), reinterpretAsUUID(2), reinterpretAsUUID(0), toDateTime('2022-02-02', 'UTC'), toString(0), reinterpretAsUUID(0), toString(0)), (reinterpretAsUUID(3), reinterpretAsUUID(2), reinterpretAsUUID(0), toDateTime('2022-02-02', 'UTC'), toString(0), reinterpretAsUUID(0), toString(0));
insert into events values (reinterpretAsUUID(0), reinterpretAsUUID(1), reinterpretAsUUID(0), toDateTime('2022-02-02', 'UTC'), toString(0), reinterpretAsUUID(0), toString(0)), (reinterpretAsUUID(0), reinterpretAsUUID(1), reinterpretAsUUID(0), toDateTime('2022-02-02', 'UTC'), toString(0), reinterpretAsUUID(0), toString(0)), (reinterpretAsUUID(1), reinterpretAsUUID(0), reinterpretAsUUID(0), toDateTime('2022-02-02', 'UTC'), toString(0), reinterpretAsUUID(0), toString(0)), (reinterpretAsUUID(1), reinterpretAsUUID(0), reinterpretAsUUID(0), toDateTime('2022-02-02', 'UTC'), toString(0), reinterpretAsUUID(0), toString(0)), (reinterpretAsUUID(3), reinterpretAsUUID(2), reinterpretAsUUID(0), toDateTime('2022-02-02', 'UTC'), toString(0), reinterpretAsUUID(0), toString(0)), (reinterpretAsUUID(3), reinterpretAsUUID(2), reinterpretAsUUID(0), toDateTime('2022-02-02', 'UTC'), toString(0), reinterpretAsUUID(0), toString(0));
set read_in_order_two_level_merge_threshold=1;
SELECT id, timestamp, payload FROM events WHERE (organisation_id = reinterpretAsUUID(1)) AND (session_id = reinterpretAsUUID(0)) ORDER BY timestamp, payload, id ASC;