Skip to content

[Feature](execution) support adjuct filter order by cost - #60079

Merged
BiteTheDDDDt merged 1 commit into
apache:masterfrom
BiteTheDDDDt:dev_0120_3
Feb 12, 2026
Merged

[Feature](execution) support adjuct filter order by cost#60079
BiteTheDDDDt merged 1 commit into
apache:masterfrom
BiteTheDDDDt:dev_0120_3

Conversation

@BiteTheDDDDt

@BiteTheDDDDtBiteTheDDDDt commented Jan 20, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

tpch external 187s -> 180s
tpcds external 380s -> 370s

This pull request introduces a mechanism to estimate and utilize the execution cost of conjunct (predicate) expressions, enabling the system to dynamically reorder conjuncts for improved query performance when the new session variable enable_adjust_conjunct_order_by_cost is enabled. The changes span the addition of cost estimation methods to expression classes, integration of cost-based sorting in several operator initialization and runtime paths, and the introduction of the new session variable in both backend and frontend.

Key changes include:

Predicate Execution Cost Estimation

  • Added a virtual execute_cost() method to the base expression class VExpr and implemented or overridden it in various expression types (VLiteral, VSlotRef, VColumnRef, VCompoundPred, VectorizedFnCall, VRuntimeFilterWrapper, and function classes like FunctionComparison), providing a mechanism to estimate the computational cost of evaluating each predicate. ([[1]](https://github.com/apache/doris/pull/60079/files#diff-4150da5bf9ad89014e38f3a83e742a52468701b366ca4e4c6b09068c7dac283aR279-R286), [[2]](https://github.com/apache/doris/pull/60079/files#diff-17d34fd4d8b4a91c6eb1e3238715ce5e1c58b4968faea7d88ed22cfe0e348a91R59-R60), [[3]](https://github.com/apache/doris/pull/60079/files#diff-7eee9b0f155e5dd8d9d3a10dd72f7fb395cc0f65ff7f5de9ff5166599281d33fR75-R76), [[4]](https://github.com/apache/doris/pull/60079/files#diff-32461b08211d014e6636fd1cba54dc37cfb4916c13b47ac8ad36cb989a0b2031R92-R93), Fd3c42dfL347R347, [[5]](https://github.com/apache/doris/pull/60079/files#diff-01445f9862bc32606a103e5801fca9bd284f7dc2b9e1a6b7f28ec385d2ef2f24R67), [[6]](https://github.com/apache/doris/pull/60079/files#diff-dca2c0f573793d20c2dba5fe846bbadd82080fdea00051785cf0ea1ca41578bfR643-R655), [[7]](https://github.com/apache/doris/pull/60079/files#diff-93a2e196a10e91c528edefa02f02abb5b6ee621a3e1cbcc2d6a5ca7075a6061dR173-R174), [[8]](https://github.com/apache/doris/pull/60079/files#diff-f698d8639284042c1bb81cee0ae26a702114342abd4fa3bdfee4a51f62744f28R275-R276), [[9]](https://github.com/apache/doris/pull/60079/files#diff-f7878a776d3726dd835f26223f373f4d2e54f5080fa239868438adbe8bb911ffR67-R68), [[10]](https://github.com/apache/doris/pull/60079/files#diff-08b2eb65f6fe3da674c54840194c031f1309e06587938f5d31b04f2f9f4e9c68L204-R206), [[11]](https://github.com/apache/doris/pull/60079/files#diff-c0aab1f4c7a9ee63428155fea5d63afda8b47794f881392f71a47a619b334761R476-R484))

Cost-Based Predicate Reordering

  • Integrated cost-based sorting of conjuncts (using std::ranges::sort and execute_cost()) in several operator and scan initialization and runtime methods, so that when enable_adjust_conjunct_order_by_cost is true, predicates are evaluated in increasing order of estimated cost. This affects scan operators, aggregation operators, and Parquet group readers. ([[1]](https://github.com/apache/doris/pull/60079/files#diff-8922a03a948ba6a44dda51be21f535e0f5b8725b37b2f10facc90f2476b82aebL202-L214), [[2]](https://github.com/apache/doris/pull/60079/files#diff-ac38473f151ccd99db4ed80dfbfa176f4f957ae2f5335ce8fbb4f5dbb0e932e9L80-R87), [[3]](https://github.com/apache/doris/pull/60079/files#diff-ac38473f151ccd99db4ed80dfbfa176f4f957ae2f5335ce8fbb4f5dbb0e932e9R194-R199), [[4]](https://github.com/apache/doris/pull/60079/files#diff-d09145594c823444cca71879eb6515950211b548d7cbef65f0caf5c1d88f296fR191-R196))

Session Variable and Query Option

  • Introduced the session variable enable_adjust_conjunct_order_by_cost (default true) to control whether cost-based predicate reordering is enabled, and ensured it is forwarded and included in query options for both backend and frontend. ([[1]](https://github.com/apache/doris/pull/60079/files#diff-efeb89760ec70cdad5ae9c6169e213b9efa84fccb6ede73f626bf6583bd82333R128-R132), [[2]](https://github.com/apache/doris/pull/60079/files#diff-b8d4d6b7e84c9f48322536f241d11f98401524e08aba36b0c92be9589f43a4a3R3090-R3092), [[3]](https://github.com/apache/doris/pull/60079/files#diff-b8d4d6b7e84c9f48322536f241d11f98401524e08aba36b0c92be9589f43a4a3R5065))

Code Cleanup and Refactoring

  • Removed legacy handling of vconjunct in aggregation and streaming aggregation operators, simplifying conjunct management and aligning with the new cost-based mechanism. ([[1]](https://github.com/apache/doris/pull/60079/files#diff-df21df88282293d1bbe3223e0d95dcc5afc01da571e3a7c1d9dc9377a758d5daL737-R737), [[2]](https://github.com/apache/doris/pull/60079/files#diff-5f2882c1f711fc0954459c6b98a1dcde9b688bb5634be71ce6f585332d8b6497L828), [[3]](https://github.com/apache/doris/pull/60079/files#diff-81893b8013f0ade85a4aca0bcf807655fc08a57e7a6cc8531278cdc5330fae9eL265))
  • Minor improvements such as renaming profile info strings for clarity (e.g., "RemainedDownPredicates" to "RemainedPredicates"). ([be/src/pipeline/exec/scan_operator.cppL315-R327](https://github.com/apache/doris/pull/60079/files#diff-ac38473f151ccd99db4ed80dfbfa176f4f957ae2f5335ce8fbb4f5dbb0e932e9L315-R327))

These changes collectively enable more efficient predicate evaluation, which can reduce query execution time, especially for complex queries with multiple predicates of varying computational cost.

Check List (For Author)

  • Test

    • Regression test
    • Unit Test
    • Manual test (add detailed scripts or steps below)
    • No need to test or manual test. Explain why:
      • This is a refactor/code format and no logic has been changed.
      • Previous test can cover this change.
      • No code files have been changed.
      • Other reason
  • Behavior changed:

    • No.
    • Yes.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

CopilotAI review requested due to automatic review settings January 20, 2026 14:05
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@BiteTheDDDDt

Copy link
Copy Markdown
ContributorAuthor

run buildall

1 similar comment
@BiteTheDDDDt

Copy link
Copy Markdown
ContributorAuthor

run buildall

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a cost-based mechanism to reorder Parquet filter conjuncts, controlled by a new session/thrift query option, and adds plumbing to estimate expression/function execution cost in the vectorized engine.

Changes:

  • Added enable_adjust_conjunct_order_by_cost to TQueryOptions and exposed it as a session variable forwarded to BE.
  • Introduced execute_cost() hooks across vectorized expressions/contexts and function interfaces.
  • Sorted Parquet row group _filter_conjuncts by estimated execution cost when the option is enabled.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
FileDescription
gensrc/thrift/PaloInternalService.thriftAdds new thrift query option field to control cost-based conjunct ordering.
fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.javaAdds session variable and forwards it into TQueryOptions during serialization.
be/src/vec/functions/function.hIntroduces function-level execute_cost() API.
be/src/vec/functions/functions_comparison.hAssigns a low cost to comparison functions via execute_cost().
be/src/vec/exprs/vexpr.hAdds expression-level recursive execute_cost() default implementation.
be/src/vec/exprs/vexpr_context.hExposes execute_cost() on VExprContext and adjusts root() accessor.
be/src/vec/exprs/vexpr_context.cppImplements VExprContext::execute_cost().
be/src/vec/exprs/vectorized_fn_call.hDeclares cost override for vectorized function call expressions.
be/src/vec/exprs/vectorized_fn_call.cppImplements function-call cost estimation.
be/src/vec/exprs/vruntimefilter_wrapper.hForwards execute_cost() to wrapped runtime filter expression.
be/src/vec/exec/format/parquet/vparquet_group_reader.cppSorts Parquet filter conjuncts by cost when enabled.
Comments suppressed due to low confidence (1)

fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java:5073

  • In toThrift(), this field is set twice: first via the direct setter, then again via reflection. If the goal is compatibility with older generated thrift classes, the direct call defeats that (it won’t compile when the setter is missing). Please either keep only the direct setter (and drop reflection) or keep only the reflective set (and remove the direct call) to match the intended compatibility behavior.
 tResult.setEnableAdjustConjunctOrderByCost(enableAdjustConjunctOrderByCost);
// Set Iceberg write target file size
tResult.setIcebergWriteTargetFileSizeBytes(icebergWriteTargetFileSizeBytes);
return tResult;
}
public JSONObject toJson() throws IOException {

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +191 to +192
if (_state->query_options().enable_adjust_conjunct_order_by_cost) {
std::ranges::sort(_filter_conjuncts,

CopilotAIJan 20, 2026

Copy link

Choose a reason for hiding this comment

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

Minor style: please keep spacing consistent with the rest of the file (if ().

Copilot uses AI. Check for mistakes.
public boolean enablePhraseQuerySequentialOpt = true;

@VariableMgr.VarAttr(name = "enable_adjust_conjunct_order_by_cost", needForward = true)
public boolean enableAdjustConjunctOrderByCost = true;

CopilotAIJan 20, 2026

Copy link

Choose a reason for hiding this comment

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

This session variable defaults to true, meaning predicate reordering by cost will be enabled by default. Since this can change evaluation order (and potentially error/short-circuit behavior), consider defaulting it to false (similar to other cost-based reordering toggles like enableJoinReorderBasedCost).

Suggested change
publicbooleanenableAdjustConjunctOrderByCost = true;
publicbooleanenableAdjustConjunctOrderByCost = false;

Copilot uses AI. Check for mistakes.
Comment on lines +173 to +174
virtual double execute_cost() const { return 1.0; }

CopilotAIJan 20, 2026

Copy link

Choose a reason for hiding this comment

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

Adding execute_cost() to IFunctionBase is fine, but note that most functions appear to be wrapped by DefaultFunction (be/src/vec/functions/function.h:436+). Since DefaultFunction doesn’t override/forward execute_cost(), any per-function overrides (e.g. in IFunction implementations) won’t be observed via FunctionBasePtr. Consider forwarding execute_cost() in DefaultFunction (or otherwise ensuring the wrapper preserves the underlying function’s cost).

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

Comment threadbe/src/vec/exprs/vectorized_fn_call.cpp Outdated
@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 100.00% (2/2) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 100.00% (2/2) 🎉
Increment coverage report
Complete coverage report

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadbe/src/vec/exprs/vexpr_context.cpp
Comment threadbe/src/vec/exprs/vcompound_pred.h Outdated
Comment threadbe/src/pipeline/exec/operator.cpp
@BiteTheDDDDt

Copy link
Copy Markdown
ContributorAuthor

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 100.00% (2/2) 🎉
Increment coverage report
Complete coverage report

@BiteTheDDDDt

Copy link
Copy Markdown
ContributorAuthor

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

Cloud UT Coverage Report

Increment line coverage 🎉

Increment coverage report
Complete coverage report

CategoryCoverage
Function Coverage79.31% (1786/2252)
Line Coverage64.74% (31802/49120)
Region Coverage65.46% (15845/24207)
Branch Coverage56.06% (8424/15028)

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 100.00% (2/2) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 13.70% (10/73) 🎉

Increment coverage report
Complete coverage report

CategoryCoverage
Function Coverage52.43% (19112/36454)
Line Coverage35.80% (177399/495542)
Region Coverage32.29% (137146/424785)
Branch Coverage33.20% (59330/178711)

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 91.78% (67/73) 🎉

Increment coverage report
Complete coverage report

CategoryCoverage
Function Coverage71.48% (25542/35733)
Line Coverage54.05% (267539/494990)
Region Coverage51.59% (221472/429292)
Branch Coverage53.03% (95177/179476)

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 100.00% (2/2) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 91.78% (67/73) 🎉

Increment coverage report
Complete coverage report

CategoryCoverage
Function Coverage71.49% (25545/35733)
Line Coverage54.06% (267592/494990)
Region Coverage51.63% (221656/429292)
Branch Coverage53.04% (95199/179476)

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 100.00% (2/2) 🎉
Increment coverage report
Complete coverage report

@BiteTheDDDDtBiteTheDDDDt changed the title Dev 0120 3[Feature](execution) support adjuct filter order by costJan 22, 2026
@BiteTheDDDDt

Copy link
Copy Markdown
ContributorAuthor

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 100.00% (2/2) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 15.15% (10/66) 🎉

Increment coverage report
Complete coverage report

CategoryCoverage
Function Coverage52.71% (19253/36527)
Line Coverage36.11% (179374/496701)
Region Coverage32.58% (138841/426147)
Branch Coverage33.51% (60072/179281)

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 87.69% (57/65) 🎉

Increment coverage report
Complete coverage report

CategoryCoverage
Function Coverage71.52% (25606/35804)
Line Coverage54.16% (268699/496163)
Region Coverage51.89% (223459/430655)
Branch Coverage53.19% (95764/180051)

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 100.00% (2/2) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 87.69% (57/65) 🎉

Increment coverage report
Complete coverage report

CategoryCoverage
Function Coverage71.52% (25606/35804)
Line Coverage54.15% (268692/496163)
Region Coverage51.88% (223412/430655)
Branch Coverage53.18% (95752/180051)

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 100.00% (2/2) 🎉
Increment coverage report
Complete coverage report

HappenLee
HappenLee previously approved these changes Jan 30, 2026

@HappenLeeHappenLee left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@github-actionsgithub-actionsBot added the approved Indicates a PR has been approved by one committer. label Jan 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR approved by at least one committer and no changes requested.

@github-actions

Copy link
Copy Markdown
Contributor

PR approved by anyone and no changes requested.

thrift: add enable_adjust_conjunct_order_by_cost to TQueryOptions
fe: add session variable enable_adjust_conjunct_order_by_cost
fe: forward enable_adjust_conjunct_order_by_cost via toThrift if supported
update
update
format
update
Update be/src/vec/exprs/vexpr_context.cpp
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Update be/src/vec/exprs/vcompound_pred.h
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Update be/src/vec/exprs/vectorized_fn_call.cpp
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
update
update
@github-actionsgithub-actionsBot removed the approved Indicates a PR has been approved by one committer. label Feb 11, 2026
@BiteTheDDDDt

Copy link
Copy Markdown
ContributorAuthor

run buildall

@github-actionsgithub-actionsBot added the approved Indicates a PR has been approved by one committer. label Feb 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR approved by at least one committer and no changes requested.

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 87.88% (58/66) 🎉

Increment coverage report
Complete coverage report

CategoryCoverage
Function Coverage71.76% (25959/36176)
Line Coverage54.38% (271564/499375)
Region Coverage51.64% (224956/435642)
Branch Coverage53.24% (96890/181995)

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 100.00% (2/2) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 87.88% (58/66) 🎉

Increment coverage report
Complete coverage report

CategoryCoverage
Function Coverage71.76% (25959/36176)
Line Coverage54.38% (271564/499375)
Region Coverage51.64% (224956/435642)
Branch Coverage53.24% (96890/181995)

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 100.00% (2/2) 🎉
Increment coverage report
Complete coverage report

@BiteTheDDDDt
BiteTheDDDDt merged commit e66fe27 into apache:masterFeb 12, 2026
31 of 33 checks passed
BiteTheDDDDt added a commit to BiteTheDDDDt/incubator-doris that referenced this pull request Mar 19, 2026
tpch external 187s -> 180s
tpcds external 380s -> 370s
This pull request introduces a mechanism to estimate and utilize the
execution cost of conjunct (predicate) expressions, enabling the system
to dynamically reorder conjuncts for improved query performance when the
new session variable `enable_adjust_conjunct_order_by_cost` is enabled.
The changes span the addition of cost estimation methods to expression
classes, integration of cost-based sorting in several operator
initialization and runtime paths, and the introduction of the new
session variable in both backend and frontend.
BiteTheDDDDt added a commit to BiteTheDDDDt/incubator-doris that referenced this pull request Mar 19, 2026
tpch external 187s -> 180s
tpcds external 380s -> 370s
This pull request introduces a mechanism to estimate and utilize the
execution cost of conjunct (predicate) expressions, enabling the system
to dynamically reorder conjuncts for improved query performance when the
new session variable `enable_adjust_conjunct_order_by_cost` is enabled.
The changes span the addition of cost estimation methods to expression
classes, integration of cost-based sorting in several operator
initialization and runtime paths, and the introduction of the new
session variable in both backend and frontend.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approvedIndicates a PR has been approved by one committer.dev/4.1.0-mergedreviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@BiteTheDDDDt@hello-stephen@HappenLee@Mryange@zclllyybb@yiguolei