Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void executeWithCalcite(
CalcitePlanContext.create(
buildFrameworkConfig(), getQuerySizeLimit(), queryType);
RelNode relNode = analyze(plan, context);
RelNode optimized = optimize(relNode);
RelNode optimized = optimize(relNode, context, false);
RelNode calcitePlan = convertToCalcitePlan(optimized);
executionEngine.execute(calcitePlan, context, listener);
return null;
Expand Down Expand Up @@ -133,7 +133,7 @@ public void explainWithCalcite(
CalcitePlanContext.create(
buildFrameworkConfig(), getQuerySizeLimit(), queryType);
RelNode relNode = analyze(plan, context);
RelNode optimized = optimize(relNode);
RelNode optimized = optimize(relNode, context, true);
RelNode calcitePlan = convertToCalcitePlan(optimized);
executionEngine.explain(calcitePlan, format, context, listener);
return null;
Expand Down Expand Up @@ -250,8 +250,14 @@ public PhysicalPlan plan(LogicalPlan plan) {
return planner.plan(plan);
}

public RelNode optimize(RelNode plan) {
return planner.customOptimize(plan);
/**
* Try to optimize the plan by appending a limit operator for QUERY_SIZE_LIMIT Don't add for
* `EXPLAIN` to avoid changing its output plan.
*/
public RelNode optimize(RelNode plan, CalcitePlanContext context, boolean isExplain) {
if (isExplain) return plan;
context.relBuilder.limit(0, context.querySizeLimit);
Copy link
Member

Choose a reason for hiding this comment

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

can you add a case in ExplainIT?

Copy link
Collaborator Author

@qianheng-aws qianheng-aws Jul 30, 2025

Choose a reason for hiding this comment

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

It won't change the output plan of explain.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Add an IT to verify querySizeLimit pushdown.
Q, should we revert code of #3880?

Copy link
Member

Choose a reason for hiding this comment

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

We can reuse LogicalSystemLimit in explain. The physical plan is no diff. Then we can verify the querySizeLimit pushdown in explain IT.

Copy link
Collaborator Author

@qianheng-aws qianheng-aws Jul 31, 2025

Choose a reason for hiding this comment

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

  • Discussed with @LantaoJin offline, I will add a new LogicalSystemLimit operator to represent the limit operator added by our system. It will be used in many other places as well where we need to add a limitation. So it will contain a field of Type to distinguish them.

  • I will manually revert few lines related, although they are compatible. That Push down QUERY_SIZE_LIMIT #3880 also contains a bug fix related to limit push down.

return context.relBuilder.peek();
}

private boolean isCalciteFallbackAllowed() {
Expand Down
Loading