zstan commented on code in PR #6543:
URL: https://github.com/apache/ignite-3/pull/6543#discussion_r2322137449


##########
modules/sql-engine/src/test/resources/tpcds/plan/q5.plan:
##########
@@ -1,205 +1,148 @@
 Sort
     collation: [CHANNEL ASC, ID ASC]
     fetch: 100
-    est: (rows=100)

Review Comment:
   thanks, done



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/metadata/IgniteMdRowCount.java:
##########
@@ -231,37 +237,91 @@ public double getRowCount(IgniteLimit rel, 
RelMetadataQuery mq) {
             return RelMdUtil.getJoinRowCount(mq, rel, rel.getCondition());
         }
 
-        double postFiltrationAdjustment = joinContexts.size() == 1 && 
joinInfo.isEqui() ? 1.0
+        double postFiltrationAdjustment = 1.0;
+
+        switch (rel.getJoinType()) {
+            case INNER:
+            case SEMI:
                 // Extra join keys as well as non-equi conditions serves as 
post-filtration,
                 // therefore we need to adjust final result with a little 
factor.
-                : 0.7;
+                postFiltrationAdjustment = joinContexts.size() == 1 && 
joinInfo.isEqui() ? 1.0 : NON_EQUI_COEFF;
+
+                break;
+            default:
+                break;
+        }
 
-        double baseRowCount;
-        Double percentageAdjustment;
+        double baseRowCount = 0.0;
+        Double percentageAdjustment = null;
         if (context.joinType() == JoiningRelationType.PK_ON_PK) {
-            // Assume we have two fact tables SALES and RETURNS sharing the 
same primary key. Every item
-            // can be sold, but only items which were sold can be returned 
back, therefore
-            // size(SALES) > size(RETURNS). When joining SALES on RETURNS by 
primary key, the estimated
-            // result size will be the same as the size of the smallest table 
(RETURNS in this case),
-            // adjusted by the percentage of rows of the biggest table (SALES 
in this case; percentage
-            // adjustment is required to account for predicates pushed down to 
the table, e.g. we are
-            // interested in returns of items with certain category)
-            if (leftRowCount > rightRowCount) {
-                baseRowCount = rightRowCount;
-                percentageAdjustment = 
mq.getPercentageOriginalRows(rel.getLeft());
-            } else {
+            if (rel.getJoinType() == JoinRelType.INNER || rel.getJoinType() == 
JoinRelType.SEMI) {
+                // Assume we have two fact tables SALES and RETURNS sharing 
the same primary key. Every item
+                // can be sold, but only items which were sold can be returned 
back, therefore
+                // size(SALES) > size(RETURNS). When joining SALES on RETURNS 
by primary key, the estimated
+                // result size will be the same as the size of the smallest 
table (RETURNS in this case),
+                // adjusted by the percentage of rows of the biggest table 
(SALES in this case; percentage
+                // adjustment is required to account for predicates pushed 
down to the table, e.g. we are
+                // interested in returns of items with certain category)
+                if (leftRowCount > rightRowCount) {
+                    baseRowCount = rightRowCount;
+                    percentageAdjustment = 
mq.getPercentageOriginalRows(rel.getLeft());
+                } else {
+                    baseRowCount = leftRowCount;
+                    percentageAdjustment = 
mq.getPercentageOriginalRows(rel.getRight());
+                }
+            } else if (rel.getJoinType() == JoinRelType.LEFT) {
                 baseRowCount = leftRowCount;
-                percentageAdjustment = 
mq.getPercentageOriginalRows(rel.getRight());
+            } else if (rel.getJoinType() == JoinRelType.RIGHT) {
+                baseRowCount = rightRowCount;
+            } else if (rel.getJoinType() == JoinRelType.FULL) {
+                Double selectivity = mq.getSelectivity(rel, 
rel.getCondition());
+
+                // Fall-back to calcite's implementation.
+                if (selectivity == null) {
+                    return RelMdUtil.getJoinRowCount(mq, rel, 
rel.getCondition());
+                }
+
+                baseRowCount = rightRowCount + leftRowCount;
+                percentageAdjustment = 1.0 - selectivity;
             }
-        } else {
+        } else if (context.joinType() == JoiningRelationType.FK_ON_PK) {
             // For foreign key joins the base table is the one which is joined 
by non-primary key columns.
-            if (context.joinType() == JoiningRelationType.FK_ON_PK) {
+            if (rel.getJoinType() == JoinRelType.INNER || rel.getJoinType() == 
JoinRelType.SEMI) {
                 baseRowCount = leftRowCount;
                 percentageAdjustment = 
mq.getPercentageOriginalRows(rel.getRight());
-            } else {
-                assert context.joinType() == JoiningRelationType.PK_ON_FK : 
context.joinType();
+            } else if (rel.getJoinType() == JoinRelType.LEFT) {
+                baseRowCount = leftRowCount;
+            } else if (rel.getJoinType() == JoinRelType.RIGHT) {
+                baseRowCount = rightRowCount;

Review Comment:
   fixed



-- 
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.

To unsubscribe, e-mail: notifications-unsubscr...@ignite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to