Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add prewhere test #8486

Merged
merged 1 commit into from Dec 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions dbms/src/Storages/MergeTree/MergeTreeRangeReader.cpp
Expand Up @@ -316,7 +316,8 @@ void MergeTreeRangeReader::ReadResult::optimize()
/// Check if const 1 after shrink
if (countBytesInResultFilter(filter->getData()) + total_zero_rows_in_tails == total_rows_per_granule)
{
num_rows = total_rows_per_granule = total_rows_per_granule - total_zero_rows_in_tails;
total_rows_per_granule = total_rows_per_granule - total_zero_rows_in_tails;
num_rows = total_rows_per_granule;
setFilterConstTrue();
shrink(columns); /// shrink acts as filtering in such case
}
Expand All @@ -326,7 +327,8 @@ void MergeTreeRangeReader::ReadResult::optimize()
IColumn::Filter & new_data = new_filter->getData();

collapseZeroTails(filter->getData(), new_data);
num_rows = total_rows_per_granule = new_filter->size();
total_rows_per_granule = new_filter->size();
num_rows = total_rows_per_granule;
filter_original = filter;
filter_holder_original = std::move(filter_holder);
filter = new_filter.get();
Expand Down
2 changes: 2 additions & 0 deletions dbms/tests/queries/0_stateless/01055_prewhere_bugs.reference
@@ -0,0 +1,2 @@
43
1
14 changes: 14 additions & 0 deletions dbms/tests/queries/0_stateless/01055_prewhere_bugs.sql
@@ -0,0 +1,14 @@
DROP TABLE IF EXISTS test_prewhere_default_column;
DROP TABLE IF EXISTS test_prewhere_column_type;

CREATE TABLE test_prewhere_default_column (APIKey UInt8, SessionType UInt8) ENGINE = MergeTree() PARTITION BY APIKey ORDER BY tuple();
INSERT INTO test_prewhere_default_column VALUES( 42, 42 );
ALTER TABLE test_prewhere_default_column ADD COLUMN OperatingSystem UInt64 DEFAULT SessionType+1;

SELECT OperatingSystem FROM test_prewhere_default_column PREWHERE SessionType = 42;


CREATE TABLE test_prewhere_column_type (`a` LowCardinality(String), `x` Nullable(Int32)) ENGINE = MergeTree ORDER BY tuple();
INSERT INTO test_prewhere_column_type VALUES ('', 2);

SELECT a, y FROM test_prewhere_column_type prewhere (x = 2) AS y;