hqx871 commented on a change in pull request #2363:
URL: https://github.com/apache/calcite/pull/2363#discussion_r591577136



##########
File path: core/src/main/java/org/apache/calcite/rel/core/Sort.java
##########
@@ -124,11 +126,24 @@ public abstract Sort copy(RelTraitSet traitSet, RelNode 
newInput,
 
   @Override public @Nullable RelOptCost computeSelfCost(RelOptPlanner planner,
       RelMetadataQuery mq) {
+    double rowCount = mq.getRowCount(this);
+    if (collation.getFieldCollations().isEmpty()) {
+      return planner.getCostFactory().makeCost(rowCount, 0, 0);
+    }
+    final double inCount = mq.getRowCount(input);
     // Higher cost if rows are wider discourages pushing a project through a
     // sort.
-    final double rowCount = mq.getRowCount(this);
     final double bytesPerRow = getRowType().getFieldCount() * 4;

Review comment:
       I use log2 to replace logE, this obviously increase the cpu cost. and 
the test JdbcTest.testAlmostBushy failed.
   ```
   /** Just short of bushy. */
     @Test void testAlmostBushy() {
       CalciteAssert.that()
           .with(CalciteAssert.Config.FOODMART_CLONE)
           .query("select *\n"
               + "from \"sales_fact_1997\" as s\n"
               + "join \"customer\" as c\n"
               + "  on s.\"customer_id\" = c.\"customer_id\"\n"
               + "join \"product\" as p\n"
               + "  on s.\"product_id\" = p.\"product_id\"\n"
               + "where c.\"city\" = 'San Francisco'\n"
               + "and p.\"brand_name\" = 'Washington'")
           .explainMatches("including all attributes ",
               CalciteAssert.checkMaskedResultContains(""
                   + "EnumerableMergeJoin(condition=[=($0, $38)], 
joinType=[inner]): rowcount = 7.050660528307499E8, cumulative cost = 
{7.656040129282498E8 rows, 5.0023949296644424E10 cpu, 0.0 io}\n"
                   + "  EnumerableSort(sort0=[$0], dir0=[ASC]): rowcount = 
2.0087351932499997E7, cumulative cost = {4.044858016499999E7 rows, 
5.0023896255644424E10 cpu, 0.0 io}\n"
                   + "    EnumerableMergeJoin(condition=[=($2, $8)], 
joinType=[inner]): rowcount = 2.0087351932499997E7, cumulative cost = 
{2.0361228232499994E7 rows, 3.232400376004586E7 cpu, 0.0 io}\n"
                   + "      EnumerableSort(sort0=[$2], dir0=[ASC]): rowcount = 
86837.0, cumulative cost = {173674.0 rows, 3.168658076004586E7 cpu, 0.0 io}\n"
                   + "        EnumerableTableScan(table=[[foodmart2, 
sales_fact_1997]]): rowcount = 86837.0, cumulative cost = {86837.0 rows, 
86838.0 cpu, 0.0 io}\n"
                   + "      EnumerableCalc(expr#0..28=[{inputs}], expr#29=['San 
Francisco':VARCHAR(30)], expr#30=[=($t9, $t29)], proj#0..28=[{exprs}], 
$condition=[$t30]): rowcount = 1542.1499999999999, cumulative cost = {11823.15 
rows, 637423.0 cpu, 0.0 io}\n"
                   + "        EnumerableTableScan(table=[[foodmart2, 
customer]]): rowcount = 10281.0, cumulative cost = {10281.0 rows, 10282.0 cpu, 
0.0 io}\n"
                   + "  EnumerableCalc(expr#0..14=[{inputs}], 
expr#15=['Washington':VARCHAR(60)], expr#16=[=($t2, $t15)], 
proj#0..14=[{exprs}], $condition=[$t16]): rowcount = 234.0, cumulative cost = 
{1794.0 rows, 53041.0 cpu, 0.0 io}\n"
                   + "    EnumerableTableScan(table=[[foodmart2, product]]): 
rowcount = 1560.0, cumulative cost = {1560.0 rows, 1561.0 cpu, 0.0 io}\n"));
     }
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to