Skip to content

Respect max_block_size for array join to avoid possible OOM#54664

Merged
robot-ch-test-poll4 merged 3 commits intoClickHouse:masterfrom
bigo-sg:arrow_join_max_block_size
Sep 23, 2023
Merged

Respect max_block_size for array join to avoid possible OOM#54664
robot-ch-test-poll4 merged 3 commits intoClickHouse:masterfrom
bigo-sg:arrow_join_max_block_size

Conversation

@taiyang-li
Copy link
Copy Markdown
Contributor

@taiyang-li taiyang-li commented Sep 15, 2023

Changelog category (leave one):

  • Improvement

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

Respect max_block_size for array join to avoid possible OOM. Close #54290

@robot-ch-test-poll1 robot-ch-test-poll1 added pr-improvement Pull request with some product improvements pr-status-⏳ labels Sep 15, 2023
@robot-ch-test-poll1
Copy link
Copy Markdown
Contributor

robot-ch-test-poll1 commented Sep 15, 2023

This is an automated comment for commit d59db55 with description of existing statuses. It's updated for the latest CI running

✅ Click here to open a full report in a separate page

Successful checks
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✅ success
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✅ success

@alexey-milovidov
Copy link
Copy Markdown
Member

Let's add a test.

@alexey-milovidov
Copy link
Copy Markdown
Member

Thank you! I wanted this feature for a very long time 🎉

@taiyang-li
Copy link
Copy Markdown
Contributor Author

taiyang-li commented Sep 18, 2023

Notice peak memory usage

 :) set max_block_size = 10;

SET max_block_size = 10

Query id: a82913e9-bd2d-41c4-99de-70f16f1d7f6b

Ok.

0 rows in set. Elapsed: 0.001 sec. 

 :) SELECT n % 10, count(1) from (SELECT range(0, number) as x FROM numbers(10000)) LEFT ARRAY JOIN x as n group by n % 10;

SELECT
    n % 10,
    count(1)
FROM
(
    SELECT range(0, number) AS x
    FROM numbers(10000)
)
LEFT ARRAY JOIN x AS n
GROUP BY n % 10

Query id: 72db26cd-1a66-46ad-9e53-4334cbf321ee

┌─modulo(n, 10)─┬─count()─┐
│             05004001 │
│             15003000 │
│             25002000 │
│             35001000 │
│             45000000 │
│             54999000 │
│             64998000 │
│             74997000 │
│             84996000 │
│             94995000 │
└───────────────┴─────────┘

10 rows in set. Elapsed: 0.372 sec. Processed 10.00 thousand rows, 80.00 KB (26.86 thousand rows/s., 214.86 KB/s.)
Peak memory usage: 8.61 MiB.

 :) set max_block_size = 100000;

SET max_block_size = 100000

Query id: b4081541-2fde-47ac-983d-980d45d9a850

Ok.

0 rows in set. Elapsed: 0.001 sec. 

 :) SELECT n % 10, count(1) from (SELECT range(0, number) as x FROM numbers(10000)) LEFT ARRAY JOIN x as n group by n % 10;

SELECT
    n % 10,
    count(1)
FROM
(
    SELECT range(0, number) AS x
    FROM numbers(10000)
)
LEFT ARRAY JOIN x AS n
GROUP BY n % 10

Query id: 6fdae9a2-680f-4b67-a170-4ac00934bb49

┌─modulo(n, 10)─┬─count()─┐
│             05004001 │
│             15003000 │
│             25002000 │
│             35001000 │
│             45000000 │
│             54999000 │
│             64998000 │
│             74997000 │
│             84996000 │
│             94995000 │
└───────────────┴─────────┘

10 rows in set. Elapsed: 0.689 sec. Processed 10.00 thousand rows, 80.00 KB (14.51 thousand rows/s., 116.05 KB/s.)
Peak memory usage: 898.64 MiB.

@taiyang-li taiyang-li force-pushed the arrow_join_max_block_size branch from 711f948 to 39ca44b Compare September 18, 2023 03:05
@taiyang-li
Copy link
Copy Markdown
Contributor Author

Let's add a test.

done

@taiyang-li
Copy link
Copy Markdown
Contributor Author

taiyang-li commented Sep 19, 2023

liuneng1994 pushed a commit to apache/gluten that referenced this pull request Sep 20, 2023
…apply max_block_size #3191

What changes were proposed in this pull request?
Notice that arrayJoin function and array join step are executing in different places. The former is in ExpressionActions::execute, and latter is in ArrayJoinAction::execute. max_block_size is currently only valid in array join step, so we must transform arrayJoin function to array join step to apply max_block_size.

Notice: This pr relies on ClickHouse/ClickHouse#54664, but it can be merge firstly.

(Fixes: #3143)
@@ -0,0 +1,13 @@
SET max_block_size = 8192;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test passed on 23.7

@@ -0,0 +1,16 @@
-- { echoOn }
set max_block_size = 10, enable_unaligned_array_join = true;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test also passed on 23.7

@alexey-milovidov
Copy link
Copy Markdown
Member

@nickitat I didn't find any difference after this feature, and the tests have passed on previous ClickHouse versions.

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

Labels

pr-improvement Pull request with some product improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Respect settings: max_block_size for arrayJoin function

10 participants