Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.apache.doris.nereids;

import org.apache.doris.analysis.StatementBase;
import org.apache.doris.catalog.Column;
import org.apache.doris.catalog.TableIf;
import org.apache.doris.catalog.constraint.TableIdentifier;
import org.apache.doris.common.Id;
Expand All @@ -32,6 +31,7 @@
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.Placeholder;
import org.apache.doris.nereids.trees.expressions.Slot;
import org.apache.doris.nereids.trees.expressions.SlotReference;
import org.apache.doris.nereids.trees.expressions.StatementScopeIdGenerator;
import org.apache.doris.nereids.trees.plans.ObjectId;
import org.apache.doris.nereids.trees.plans.PlaceholderId;
Expand Down Expand Up @@ -135,7 +135,7 @@ public class StatementContext implements Closeable {
private final Map<Slot, Relation> slotToRelation = Maps.newHashMap();

// the columns in Plan.getExpressions(), such as columns in join condition or filter condition, group by expression
private final Set<Column> keyColumns = Sets.newHashSet();
private final Set<SlotReference> keySlots = Sets.newHashSet();
private BitSet disableRules;

// table locks
Expand Down Expand Up @@ -516,12 +516,12 @@ public String toString() {
}
}

public void addKeyColumn(Column column) {
keyColumns.add(column);
public void addKeySlot(SlotReference slot) {
keySlots.add(slot);
}

public boolean isKeyColumn(Column column) {
return keyColumns.contains(column);
public boolean isKeySlot(SlotReference slot) {
return keySlots.contains(slot);
}

/** Get table id with lazy */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public Plan rewriteRoot(Plan plan, JobContext jobContext) {
if (stmtContext != null) {
for (Slot key : keys) {
if (key instanceof SlotReference) {
((SlotReference) key).getColumn().ifPresent(stmtContext::addKeyColumn);
stmtContext.addKeySlot((SlotReference) key);
}
}
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ public interface OlapScan {

long getSelectedIndexId();

/**
* if this is mv, return selectedIndexId, o.w -1
* @return -1 or selectedIndexId
*/
long getSelectedIndexIdForMV();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only for sync mv? if true, rename to ForSyncMv

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for both


List<Long> getSelectedPartitionIds();

List<Long> getSelectedTabletIds();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ public long getSelectedIndexId() {
return logicalOlapScan.getSelectedIndexId();
}

@Override
public long getSelectedIndexIdForMV() {
return logicalOlapScan.getSelectedIndexIdForMV();
}

@Override
public List<Long> getSelectedPartitionIds() {
return logicalOlapScan.getSelectedPartitionIds();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,14 @@ public long getSelectedIndexId() {
return selectedIndexId;
}

@Override
public long getSelectedIndexIdForMV() {
if (getTable().getBaseIndexId() != selectedIndexId) {
return selectedIndexId;
}
return -1;
}

public boolean isIndexSelected() {
return indexSelected;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ public long getSelectedIndexId() {
return physicalOlapScan.getSelectedIndexId();
}

@Override
public long getSelectedIndexIdForMV() {
return physicalOlapScan.getSelectedIndexIdForMV();
}

@Override
public List<Long> getSelectedPartitionIds() {
return physicalOlapScan.getSelectedPartitionIds();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ public long getSelectedIndexId() {
return selectedIndexId;
}

@Override
public long getSelectedIndexIdForMV() {
if (getTable().getBaseIndexId() != selectedIndexId) {
return selectedIndexId;
}
return -1;
}

@Override
public List<Long> getSelectedTabletIds() {
return selectedTabletIds;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class StatisticsBuilder {

private double rowCount;
private int widthInJoinCluster;
private int widthInJoinCluster = 1;
private final Map<Expression, ColumnStatistic> expressionToColumnStats;

public StatisticsBuilder() {
Expand Down Expand Up @@ -60,6 +61,10 @@ public StatisticsBuilder putColumnStatistics(Expression expression, ColumnStatis
return this;
}

public Set<Map.Entry<Expression, ColumnStatistic>> getExpressionColumnStatsEntries() {
return expressionToColumnStats.entrySet();
Comment on lines +64 to +65
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Directly returning a map is more general.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to guarantee that every entry is add by API StatististicBuilder.put(expr, columnStats). If the map is exposed, the guarantee may be broken.

}

public Statistics build() {
return new Statistics(rowCount, widthInJoinCluster, expressionToColumnStats);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ suite("partition_col_stats") {
"""
//run this sql to make stats be cached
sql "select * from pt where k1<3;"
sleep(10)
sleep(10000)
explain{
sql "physical plan select * from pt where k1<3;"
contains("stats=4")
Expand Down