From 7f7dd9ef3020f62861cd7951096f1cbcccc04f5b Mon Sep 17 00:00:00 2001 From: Ralph Gasser Date: Fri, 24 May 2024 20:26:14 +0200 Subject: [PATCH] Fixes an issue in selectivity calculation for IN operations. --- .../physical/sources/IndexScanPhysicalOperatorNode.kt | 2 +- .../statistics/selectivity/NaiveSelectivityCalculator.kt | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/cottontaildb-dbms/src/main/kotlin/org/vitrivr/cottontail/dbms/queries/operators/physical/sources/IndexScanPhysicalOperatorNode.kt b/cottontaildb-dbms/src/main/kotlin/org/vitrivr/cottontail/dbms/queries/operators/physical/sources/IndexScanPhysicalOperatorNode.kt index 1a3876a0b..72eb4c0ed 100644 --- a/cottontaildb-dbms/src/main/kotlin/org/vitrivr/cottontail/dbms/queries/operators/physical/sources/IndexScanPhysicalOperatorNode.kt +++ b/cottontaildb-dbms/src/main/kotlin/org/vitrivr/cottontail/dbms/queries/operators/physical/sources/IndexScanPhysicalOperatorNode.kt @@ -111,7 +111,7 @@ class IndexScanPhysicalOperatorNode(override val groupId: Int, /* Populate statistics. */ if (!this.statistics.containsKey(binding.physical) && entityProduces.contains(binding.physical)) { - this.statistics[binding.column] = entityTx.columnForName(binding.physical!!.name).newTx(this.index.context).statistics() as ValueStatistics + this.statistics[binding.physical] = entityTx.columnForName(binding.physical!!.name).newTx(this.index.context).statistics() as ValueStatistics } } else { require(indexProduces.contains(binding.column)) { diff --git a/cottontaildb-dbms/src/main/kotlin/org/vitrivr/cottontail/dbms/statistics/selectivity/NaiveSelectivityCalculator.kt b/cottontaildb-dbms/src/main/kotlin/org/vitrivr/cottontail/dbms/statistics/selectivity/NaiveSelectivityCalculator.kt index e58bb0281..ceaa5f8c6 100644 --- a/cottontaildb-dbms/src/main/kotlin/org/vitrivr/cottontail/dbms/statistics/selectivity/NaiveSelectivityCalculator.kt +++ b/cottontaildb-dbms/src/main/kotlin/org/vitrivr/cottontail/dbms/statistics/selectivity/NaiveSelectivityCalculator.kt @@ -73,9 +73,8 @@ object NaiveSelectivityCalculator { val right = predicate.operator.right return when { left is Binding.Literal && right is Binding.Literal -> if (left.getValue() == right.getValue()) Selectivity.ALL else Selectivity.NOTHING - left is Binding.Literal && right is Binding.Column -> statistics[right.physical]?.estimateSelectivity(predicate) ?: Selectivity.DEFAULT - left is Binding.Column && right is Binding.Literal -> statistics[left.physical]?.estimateSelectivity(predicate) ?: Selectivity.DEFAULT - left is Binding.Column && right is Binding.LiteralList -> statistics[left.physical]?.estimateSelectivity(predicate) ?: Selectivity.DEFAULT + left !is Binding.Column && right is Binding.Column -> statistics[right.physical]?.estimateSelectivity(predicate) ?: Selectivity.DEFAULT + left is Binding.Column && right !is Binding.Column -> statistics[left.physical]?.estimateSelectivity(predicate) ?: Selectivity.DEFAULT else -> Selectivity.DEFAULT } }