Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
xinyiZzz committed Oct 24, 2023
1 parent f9f5392 commit 1c1381b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,8 @@ public void computeSampleTabletIds() {
continue;
}

// It is assumed here that all tablets row count is uniformly distributed
// TODO Use `p.getBaseIndex().getTablet(n).getRowCount()` to get each tablet row count to compute sample.
long avgRowsPerTablet = Math.max(p.getBaseIndex().getRowCount() / ids.size(), 1);
long tabletCounts = Math.max(
avgRowsPerPartition / avgRowsPerTablet + (avgRowsPerPartition % avgRowsPerTablet != 0 ? 1 : 0), 1);
Expand Down Expand Up @@ -1026,19 +1028,28 @@ private void computeTabletInfo() throws UserException {
final Partition partition = olapTable.getPartition(partitionId);
final MaterializedIndex selectedTable = partition.getIndex(selectedIndexId);
final List<Tablet> tablets = Lists.newArrayList();
final Collection<Long> tabletIds = distributionPrune(selectedTable, partition.getDistributionInfo());
Collection<Long> tabletIds = distributionPrune(selectedTable, partition.getDistributionInfo());
LOG.debug("distribution prune tablets: {}", tabletIds);
if (tabletIds != null && sampleTabletIds.size() != 0) {
tabletIds.retainAll(sampleTabletIds);
if (sampleTabletIds.size() != 0) {
if (tabletIds != null) {
tabletIds.retainAll(sampleTabletIds);
} else {
tabletIds = sampleTabletIds;
}
LOG.debug("after sample tablets: {}", tabletIds);
}

List<Long> allTabletIds = selectedTable.getTabletIdsInOrder();
if (tabletIds != null) {
for (Long id : tabletIds) {
tablets.add(selectedTable.getTablet(id));
if (selectedTable.getTablet(id) != null) {
tablets.add(selectedTable.getTablet(id));
scanTabletIds.add(id);
} else {
// The tabletID specified in query does not exist in this partition, skip scan partition.
Preconditions.checkState(sampleTabletIds.size() != 0);
}
}
scanTabletIds.addAll(tabletIds);
} else {
tablets.addAll(selectedTable.getTablets());
scanTabletIds.addAll(allTabletIds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,29 @@ public static void setUp() throws Exception {
+ "\"in_memory\" = \"false\",\n"
+ "\"storage_format\" = \"V2\"\n"
+ ")";
String tbl3 = "CREATE TABLE db1.table3 (\n"
+ " `siteid` int(11) NULL DEFAULT \"10\" COMMENT \"\",\n"
+ " `citycode` smallint(6) NULL COMMENT \"\",\n"
+ " `username` varchar(32) NULL DEFAULT \"\" COMMENT \"\",\n"
+ " `pv` bigint(20) NULL DEFAULT \"0\" COMMENT \"\"\n"
+ ") ENGINE=OLAP\n"
+ "UNIQUE KEY(`siteid`, `citycode`, `username`)\n"
+ "COMMENT \"OLAP\"\n"
+ "DISTRIBUTED BY RANDOM BUCKETS 10\n"
+ "PROPERTIES (\n"
+ "\"replication_num\" = \"1\",\n"
+ "\"in_memory\" = \"false\",\n"
+ "\"storage_format\" = \"V2\"\n"
+ ")";
dorisAssert = new DorisAssert();
dorisAssert.withDatabase("db1").useDatabase("db1");
dorisAssert.withTable(createTblStmtStr)
.withTable(createBaseAllStmtStr)
.withTable(createPratitionTableStr)
.withTable(createDatePartitionTableStr)
.withTable(tbl1)
.withTable(tbl2);
.withTable(tbl2)
.withTable(tbl3);
}

@Test
Expand Down Expand Up @@ -822,7 +837,7 @@ public void testSelectOuterJoinSql() throws Exception {
}

@Test
public void testSelectTablet() throws Exception {
public void testHashBucketSelectTablet() throws Exception {
String sql1 = "SELECT * FROM db1.table1 TABLET(10031,10032,10033)";
OriginalPlanner planner = (OriginalPlanner) dorisAssert.query(sql1).internalExecuteOneAndGetPlan();
Set<Long> sampleTabletIds = ((OlapScanNode) planner.getScanNodes().get(0)).getSampleTabletIds();
Expand All @@ -831,6 +846,16 @@ public void testSelectTablet() throws Exception {
Assert.assertTrue(sampleTabletIds.contains(10033L));
}

@Test
public void testRandomBucketSelectTablet() throws Exception {
String sql1 = "SELECT * FROM db1.table3 TABLET(10031,10032,10033)";
OriginalPlanner planner = (OriginalPlanner) dorisAssert.query(sql1).internalExecuteOneAndGetPlan();
Set<Long> sampleTabletIds = ((OlapScanNode) planner.getScanNodes().get(0)).getSampleTabletIds();
Assert.assertTrue(sampleTabletIds.contains(10031L));
Assert.assertTrue(sampleTabletIds.contains(10032L));
Assert.assertTrue(sampleTabletIds.contains(10033L));
}

@Test
public void testSelectSampleTable() throws Exception {
Database db = Env.getCurrentInternalCatalog().getDbOrMetaException("default_cluster:db1");
Expand Down

0 comments on commit 1c1381b

Please sign in to comment.