This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 5c159339d09 [fix](planner) Fix table sample not take effect if exist
conjunct #29814
5c159339d09 is described below
commit 5c159339d090f56192361d238b2c249451291e70
Author: Xinyi Zou <[email protected]>
AuthorDate: Thu Jan 11 04:30:58 2024 +0800
[fix](planner) Fix table sample not take effect if exist conjunct #29814
---
.../glue/translator/PhysicalPlanTranslator.java | 2 +-
.../org/apache/doris/planner/OlapScanNode.java | 23 +++++++++++++++++++---
.../org/apache/doris/analysis/SelectStmtTest.java | 5 +++++
3 files changed, 26 insertions(+), 4 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java
index 0de4b9497a9..713fcc1bdfe 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java
@@ -646,7 +646,7 @@ public class PhysicalPlanTranslator extends
DefaultPlanVisitor<PlanFragment, Pla
BaseTableRef tableRef = new BaseTableRef(ref, olapTable, tableName);
tupleDescriptor.setRef(tableRef);
olapScanNode.setSelectedPartitionIds(olapScan.getSelectedPartitionIds());
- olapScanNode.setSampleTabletIds(olapScan.getSelectedTabletIds()); //
TODO
+ olapScanNode.setSampleTabletIds(olapScan.getSelectedTabletIds());
if (olapScan.getTableSample().isPresent()) {
olapScanNode.setTableSample(new
TableSample(olapScan.getTableSample().get().isPercent,
olapScan.getTableSample().get().sampleValue,
olapScan.getTableSample().get().seek));
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java
b/fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java
index f812c3d0fde..e5381a2018f 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java
@@ -999,6 +999,7 @@ public class OlapScanNode extends ScanNode {
// 3. Sampling partition. If Seek is specified, the partition will be
the same for each sampling.
long hitRows = 0; // The number of rows hit by the tablet
+ Set<Long> hitTabletIds = Sets.newHashSet();
long partitionSeek = tableSample.getSeek() != -1
? tableSample.getSeek() : (long) (new
SecureRandom().nextDouble() * selectedPartitionList.size());
for (int i = 0; i < selectedPartitionList.size(); i++) {
@@ -1024,16 +1025,24 @@ public class OlapScanNode extends ScanNode {
? tableSample.getSeek() : (long) (new
SecureRandom().nextDouble() * tablets.size());
for (int j = 0; j < tablets.size(); j++) {
int seekTid = (int) ((j + tabletSeek) % tablets.size());
+ Tablet tablet = tablets.get(seekTid);
+ if (sampleTabletIds.size() != 0 &&
!sampleTabletIds.contains(tablet.getId())) {
+ // After PruneOlapScanTablet, sampleTabletIds.size() != 0,
+ // continue sampling only in sampleTabletIds.
+ // If it is percentage sample, the number of sampled rows
is a percentage of the
+ // total number of rows, and It is not related to
sampleTabletI after PruneOlapScanTablet.
+ continue;
+ }
long tabletRowCount;
if (!FeConstants.runningUnitTest) {
- tabletRowCount = tablets.get(seekTid).getRowCount(true);
+ tabletRowCount = tablet.getRowCount(true);
} else {
tabletRowCount = selectedTable.getRowCount() /
tablets.size();
}
if (tabletRowCount == 0) {
continue;
}
- sampleTabletIds.add(tablets.get(seekTid).getId());
+ hitTabletIds.add(tablet.getId());
sampleRows -= tabletRowCount;
hitRows += tabletRowCount;
if (sampleRows <= 0) {
@@ -1044,7 +1053,15 @@ public class OlapScanNode extends ScanNode {
break;
}
}
- LOG.debug("after computeSampleTabletIds, hitRows {}, selectedRows {}",
hitRows, selectedRows);
+ if (sampleTabletIds.size() != 0) {
+ sampleTabletIds.retainAll(hitTabletIds);
+ LOG.debug("after computeSampleTabletIds, hitRows {}, totalRows {},
selectedTablets {}, sampleRows {}",
+ hitRows, selectedRows, sampleTabletIds.size(),
totalSampleRows);
+ } else {
+ sampleTabletIds = hitTabletIds;
+ LOG.debug("after computeSampleTabletIds, hitRows {}, selectedRows
{}, sampleRows {}", hitRows, selectedRows,
+ totalSampleRows);
+ }
}
public boolean isFromPrepareStmt() {
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/analysis/SelectStmtTest.java
b/fe/fe-core/src/test/java/org/apache/doris/analysis/SelectStmtTest.java
index e2ecffaae56..331ee4eb060 100755
--- a/fe/fe-core/src/test/java/org/apache/doris/analysis/SelectStmtTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/SelectStmtTest.java
@@ -961,6 +961,11 @@ public class SelectStmtTest {
OriginalPlanner planner16 = (OriginalPlanner)
dorisAssert.query(sql16).internalExecuteOneAndGetPlan();
Set<Long> sampleTabletIds16 = ((OlapScanNode)
planner16.getScanNodes().get(0)).getSampleTabletIds();
Assert.assertEquals(1, sampleTabletIds16.size());
+
+ String sql17 = "SELECT * FROM db1.table1 TABLESAMPLE(15 PERCENT) where
siteid != 0";
+ OriginalPlanner planner17 = (OriginalPlanner)
dorisAssert.query(sql17).internalExecuteOneAndGetPlan();
+ Set<Long> sampleTabletIds17 = ((OlapScanNode)
planner17.getScanNodes().get(0)).getSampleTabletIds();
+ Assert.assertEquals(2, sampleTabletIds17.size());
FeConstants.runningUnitTest = false;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]