tkalkirill commented on code in PR #13389:
URL: https://github.com/apache/ignite/pull/13389#discussion_r3860566786
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/metadata/IgniteMdRowCount.java:
##########
@@ -17,42 +17,58 @@
package org.apache.ignite.internal.processors.query.calcite.metadata;
+import java.util.BitSet;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import org.apache.calcite.plan.RelOptTable;
+import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.core.Intersect;
import org.apache.calcite.rel.core.Join;
import org.apache.calcite.rel.core.JoinInfo;
import org.apache.calcite.rel.core.JoinRelType;
import org.apache.calcite.rel.core.Minus;
import org.apache.calcite.rel.core.Sort;
+import org.apache.calcite.rel.metadata.BuiltInMetadata;
import org.apache.calcite.rel.metadata.ReflectiveRelMetadataProvider;
+import org.apache.calcite.rel.metadata.RelColumnOrigin;
import org.apache.calcite.rel.metadata.RelMdRowCount;
import org.apache.calcite.rel.metadata.RelMdUtil;
import org.apache.calcite.rel.metadata.RelMetadataProvider;
import org.apache.calcite.rel.metadata.RelMetadataQuery;
import org.apache.calcite.rex.RexNode;
-import org.apache.calcite.util.BuiltInMethod;
import org.apache.calcite.util.ImmutableBitSet;
import org.apache.calcite.util.ImmutableIntList;
import org.apache.calcite.util.Util;
+import org.apache.calcite.util.mapping.IntPair;
import org.apache.ignite.internal.processors.query.calcite.rel.IgniteAggregate;
import org.apache.ignite.internal.processors.query.calcite.rel.IgniteLimit;
import
org.apache.ignite.internal.processors.query.calcite.rel.IgniteSortedIndexSpool;
import
org.apache.ignite.internal.processors.query.calcite.rel.IgniteTableModify;
+import org.apache.ignite.internal.processors.query.calcite.schema.IgniteTable;
+import org.apache.ignite.internal.util.GridLeanMap;
import org.apache.ignite.internal.util.typedef.F;
import org.jetbrains.annotations.Nullable;
import static org.apache.calcite.util.NumberUtil.multiply;
+
/** */
@SuppressWarnings("unused") // actually all methods are used by runtime
generated classes
public class IgniteMdRowCount extends RelMdRowCount {
+ /** */
+ private static final double NON_EQUI_COEFF = 0.7;
+
+ /** */
+ public static final double EQUI_COEFF = 0.8;
+
/** */
public static final RelMetadataProvider SOURCE =
- ReflectiveRelMetadataProvider.reflectiveSource(
- BuiltInMethod.ROW_COUNT.method, new IgniteMdRowCount());
+ ReflectiveRelMetadataProvider.reflectiveSource(new IgniteMdRowCount(),
BuiltInMetadata.RowCount.Handler.class);
/** {@inheritDoc} */
@Override public Double getRowCount(Join rel, RelMetadataQuery mq) {
- return rel.estimateRowCount(mq);
+ return joinRowCount(mq, rel);
Review Comment:
Before this change, `getRowCount(Join, mq)` called
`rel.estimateRowCount(mq)`. Due to virtual dispatch, an
`IgniteCorrelatedNestedLoopJoin` invoked its specialized `estimateRowCount()`
override.
`CorrelatedNestedLoopJoinRule` pushes the join condition into an external
filter on the right input, while the resulting CNL still keeps the same join
condition. Therefore, the right input row count already includes the condition
selectivity. The generic `joinRowCount()` applies the join-condition
selectivity again.
`IgniteCorrelatedNestedLoopJoin.estimateRowCount()` explicitly compensates
for this by dividing the generic estimate by `mq.getSelectivity(this,
getCondition())`.
Calling `joinRowCount(mq, rel)` directly bypasses that override and
reintroduces the double application. This is relevant to this change because
the previous dispatch preserved the specialized behavior, while the new
dispatch does not.
Could we add a specific metadata overload for
`IgniteCorrelatedNestedLoopJoin`, delegating to `rel.estimateRowCount(mq)`, and
cover it with a regression test?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]