Skip to content

Parquet filter pushdown#52951

Merged
al13n321 merged 2 commits intomasterfrom
hyper
Aug 21, 2023
Merged

Parquet filter pushdown#52951
al13n321 merged 2 commits intomasterfrom
hyper

Conversation

@al13n321
Copy link
Copy Markdown
Member

@al13n321 al13n321 commented Aug 2, 2023

Changelog category (leave one):

  • Performance Improvement

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Parquet filter pushdown. I.e. when reading Parquet files, row groups (chunks of the file) are skipped based on the WHERE condition and the min/max values in each column. In particular, if the file is roughly sorted by some column, queries that filter by a short range of that column will be much faster.

Closes #23297

@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-performance Pull request with some performance improvements label Aug 2, 2023
@robot-ch-test-poll2
Copy link
Copy Markdown
Contributor

robot-ch-test-poll2 commented Aug 2, 2023

This is an automated comment for commit 72dc186 with description of existing statuses. It's updated for the latest CI running
The full report is available here
The overall status of the commit is 🔴 failure

Check nameDescriptionStatus
AST fuzzerRuns randomly generated queries to catch program errors. The build type is optionally given in parenthesis. If it fails, ask a maintainer for help🟢 success
CI runningA meta-check that indicates the running CI. Normally, it's in success or pending state. The failed status indicates some problems with the PR🟢 success
ClickHouse build checkBuilds ClickHouse in various configurations for use in further steps. You have to fix the builds that fail. Build logs often has enough information to fix the error, but you might have to reproduce the failure locally. The cmake options can be found in the build log, grepping for cmake. Use these options and follow the general build process🟢 success
Compatibility checkChecks that clickhouse binary runs on distributions with old libc versions. If it fails, ask a maintainer for help🟢 success
Docker image for serversThe check to build and optionally push the mentioned image to docker hub🟢 success
Fast testNormally this is the first check that is ran for a PR. It builds ClickHouse and runs most of stateless functional tests, omitting some. If it fails, further checks are not started until it is fixed. Look at the report to see which tests fail, then reproduce the failure locally as described here🟢 success
Flaky testsChecks if new added or modified tests are flaky by running them repeatedly, in parallel, with more randomization. Functional tests are run 100 times with address sanitizer, and additional randomization of thread scheduling. Integrational tests are run up to 10 times. If at least once a new test has failed, or was too long, this check will be red. We don't allow flaky tests, read the doc🟢 success
Install packagesChecks that the built packages are installable in a clear environment🟢 success
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests🟢 success
Mergeable CheckChecks if all other necessary checks are successful🟢 success
Performance ComparisonMeasure changes in query performance. The performance test report is described in detail here. In square brackets are the optional part/total tests🔴 failure
Push to DockerhubThe check for building and pushing the CI related docker images to docker hub🟢 success
SQLTestThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS🟢 success
SQLancerFuzzing tests that detect logical bugs with SQLancer tool🟢 success
SqllogicRun clickhouse on the sqllogic test set against sqlite and checks that all statements are passed🟢 success
Stateful testsRuns stateful functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc🟢 success
Stateless testsRuns stateless functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc🟢 success
Stress testRuns stateless functional tests concurrently from several clients to detect concurrency-related errors🟢 success
Style CheckRuns a set of checks to keep the code style clean. If some of tests failed, see the related log from the report🟢 success
Unit testsRuns the unit tests for different release types🟢 success
Upgrade checkRuns stress tests on server version from last release and then tries to upgrade it to the version from the PR. It checks if the new server can successfully startup without any errors, crashes or sanitizer asserts🔴 failure

@danthegoodman1
Copy link
Copy Markdown

I'd mark closes #23297

@al13n321 al13n321 marked this pull request as ready for review August 4, 2023 02:01
@liuneng1994
Copy link
Copy Markdown
Contributor

I found on my re-implemented parquet reader that filters need to be pushed down to column decoder, especially for dictionary-encoded string columns.

@zhanglistar
Copy link
Copy Markdown
Contributor

@al13n321 Clickhouse Arrow version lags two big versions of upstream, do you have plan to upgrade the version?

@al13n321
Copy link
Copy Markdown
Member Author

al13n321 commented Aug 4, 2023

I found on my re-implemented parquet reader that filters need to be pushed down to column decoder, especially for dictionary-encoded string columns.

I don't understand, can you elaborate?

This PR just looks at column chunk statistics in the FileMetaData struct, then just skips row groups. No deeper integration with the decoder seems necessary. Do you mean one of these?:

  • We could also filter out individual pages based on page statistics. But that seems really difficult and not worthwhile.
  • Don't expand dictionary-encoded columns into full columns, keep them in memory as dictionary-encoded (ColumnLowCardinality) throughout the pipeline as much as possible. Kind of like if LowCardinality wasn't a type but just an internal detail of column representation. That would be nice. Seems unrelated to this task.
  • We could do PREWHERE on row groups, just like on merge tree granules. I.e. first decode the columns needed for PREWHERE, then evaluate the PREWHERE expression, and if all rows are rejected don't read+decode the rest of the columns. Can also skip individual pages based on the filter mask.

Btw, how's the reimplementation going? I'm looking forward to it!

@liuneng1994
Copy link
Copy Markdown
Contributor

liuneng1994 commented Aug 4, 2023

I found on my re-implemented parquet reader that filters need to be pushed down to column decoder, especially for dictionary-encoded string columns.

I don't understand, can you elaborate?

This PR just looks at column chunk statistics in the FileMetaData struct, then just skips row groups. No deeper integration with the decoder seems necessary. Do you mean one of these?:

  • We could also filter out individual pages based on page statistics. But that seems really difficult and not worthwhile.
  • Don't expand dictionary-encoded columns into full columns, keep them in memory as dictionary-encoded (ColumnLowCardinality) throughout the pipeline as much as possible. Kind of like if LowCardinality wasn't a type but just an internal detail of column representation. That would be nice. Seems unrelated to this task.
  • We could do PREWHERE on row groups, just like on merge tree granules. I.e. first decode the columns needed for PREWHERE, then evaluate the PREWHERE expression, and if all rows are rejected don't read+decode the rest of the columns. Can also skip individual pages based on the filter mask.

Btw, how's the reimplementation going? I'm looking forward to it!

Just mentioning. It doesn't mean that this feature is bad.
The second point. Filters act on the encoded value, which is filtered and then decoded. I have implemented this method, but the performance is still not as good as the Velox Parquet reader, and it is still being investigated. The main gap here lies in the processing of the filter, and there is no gap in the performance of data decoding. There's an experimental PR here, and the code is ugly. https://github.com/oap-project/gluten/pull/1997/files

@Avogar Avogar self-assigned this Aug 4, 2023
@danthegoodman1
Copy link
Copy Markdown

We could do PREWHERE on row groups, just like on merge tree granules. I.e. first decode the columns needed for PREWHERE, then evaluate the PREWHERE expression, and if all rows are rejected don't read+decode the rest of the columns. Can also skip individual pages based on the filter mask.

IIUC then prewhere would not take effect on parquet pushdown, and would have to manually be implemented with nested subqueries in the current form of this PR?

@al13n321
Copy link
Copy Markdown
Member Author

al13n321 commented Aug 4, 2023

IIUC then prewhere would not take effect on parquet pushdown, and would have to manually be implemented with nested subqueries in the current form of this PR?

Yes.

@Avogar
Copy link
Copy Markdown
Member

Avogar commented Aug 17, 2023

Can we add a performance test? (in tests/performance)

@Avogar
Copy link
Copy Markdown
Member

Avogar commented Aug 18, 2023

Screenshot 2023-08-18 at 13 57 31

Nice!

@al13n321
Copy link
Copy Markdown
Member Author

Performance Comparison regressions seem spurious, except for this one:

SELECT WatchID FROM table_Parquet FORMAT Null

which now takes 3 ms instead of 2 ms. It's plausible that ~1ms is really how long the new filtering code takes (on a file with 133 columns and 1 row group), and I guess that's ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-performance Pull request with some performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parquet filter pushdown

6 participants