You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by "Zhen Chen (Jira)" <ji...@apache.org> on 2025/10/28 07:07:00 UTC

[jira] [Created] (CALCITE-7252) Implement ORDER BY Optimization Using Functional Dependencies at SQL-to-Rel Conversion Phase

Zhen Chen created CALCITE-7252:
----------------------------------

             Summary: Implement ORDER BY Optimization Using Functional Dependencies at SQL-to-Rel Conversion Phase
                 Key: CALCITE-7252
                 URL: https://issues.apache.org/jira/browse/CALCITE-7252
             Project: Calcite
          Issue Type: New Feature
            Reporter: Zhen Chen
            Assignee: Zhen Chen


This issue implements an optimization that removes redundant columns from ORDER BYclauses based on functional dependencies (FDs) during the SQL-to-Relational (SQL-to-Rel) conversion process. This approach was chosen because a rule-based implementation within the Volcano planner would face significant hurdles with trait satisfaction. Specifically, an optimized collation (e.g., [0]) cannot satisfy the original, broader collation requirement (e.g., [0, 1]) under the standard trait subsumption check, which would prevent the optimizer from selecting the more efficient plan, details see CALCITE-7234.

The implementation achieves the following results:
{code:java}
-- Original Query (FD: empno(primary key) → sal)
select empno, sal from emp order by empno, sal;
-- Optimized Logical Plan
LogicalSort(sort0=[$0], dir0=[ASC])   <-- Instead of sort0=[$0], sort1=[$1]
  LogicalProject(EMPNO=[$0], SAL=[$5])
    LogicalTableScan(table=[[CATALOG, SALES, EMP]]) {code}
Introduces a new optimizeOrderBy configuration parameter to enable the optimization. The default value is false.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)