close
Skip to content

[Improve][Connector-Clickhouse] improve ck batch parallel read by using last batch row sorting value approach, instead of limit offset.#9801

Merged
corgy-w merged 4 commits into
apache:devfrom
JeremyXin:improve-ck-parallel-read
Sep 8, 2025
Merged

[Improve][Connector-Clickhouse] improve ck batch parallel read by using last batch row sorting value approach, instead of limit offset.#9801
corgy-w merged 4 commits into
apache:devfrom
JeremyXin:improve-ck-parallel-read

Conversation

@JeremyXin

@JeremyXin JeremyXin commented Aug 30, 2025

Copy link
Copy Markdown
Contributor

Purpose of this pull request

Improve ck batch parallel read by using last batch row sorting value approach, instead of limit offset.

When reading large amounts of data, using the limit offset method will first construct the complete result set and then skip the number of rows specified by the offset. The larger the value of OFFSET is, the higher the cost of the query will be. Therefore, for the optimization of batch reading, the maximum value of the sorting key of the last batch is recorded. This approach utilizes the WHERE condition to "skip" the previous data.

before:
ck-parallel-optimize-after

after:
ck-parallel-optimize-before

Does this PR introduce any user-facing change?

How was this patch tested?

Check list

JeremyXin and others added 2 commits August 30, 2025 17:44
} else {
return clickhouseSourceSplit.getParts().stream()
.map(ClickhouseValueReader.this::buildPartQuery)
.map(this::buildStreamPartQuery)

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.

why change this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually, I just want to separate the methods for building query sql in different modes. The buildBatchSqlQuery and buildBatchPartQuery methods are only used for sql query construction in batch mode. This way, there is no need to make additional logical judgments within the method regarding the generation of sql in the Stream scenario.

Comment on lines +347 to +350
Method buildKeysetWhereConditionMethod =
ClickhouseValueReader.class.getDeclaredMethod(
"buildKeysetWhereCondition", String.class, List.class);
buildKeysetWhereConditionMethod.setAccessible(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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

@Hisoka-X Hisoka-X left a comment

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.

Thanks @JeremyXin !

@corgy-w corgy-w merged commit 5e9990a into apache:dev Sep 8, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants