From 15d7b17c81712a399edb6c173333b2eeb818b5f4 Mon Sep 17 00:00:00 2001 From: Mingyu Chen Date: Tue, 28 Nov 2023 10:36:22 +0800 Subject: [PATCH] [opt](plan) only lock olap table when query plan #27639 (#27656) bp #27639 --- .../java/org/apache/doris/catalog/OlapTable.java | 13 ++++++++++++- .../main/java/org/apache/doris/catalog/TableIf.java | 9 +++++++++ .../org/apache/doris/nereids/CascadesContext.java | 3 +++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java index 21d9ee92f3d688..3ac83a3f3d3de9 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java @@ -2354,6 +2354,17 @@ public boolean isDistributionColumn(String columnName) { @Override public boolean isPartitionColumn(String columnName) { return getPartitionInfo().getPartitionColumns().stream() - .anyMatch(c -> c.getName().equalsIgnoreCase(columnName)); + .anyMatch(c -> c.getName().equalsIgnoreCase(columnName)); + } + + /** + * For olap table, we need to acquire read lock when plan. + * Because we need to make sure the partition's version remain unchanged when plan. + * + * @return + */ + @Override + public boolean needReadLockWhenPlan() { + return true; } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/TableIf.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/TableIf.java index 3539d17e269a53..3f53fa1bfaef07 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/TableIf.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/TableIf.java @@ -149,6 +149,15 @@ default int getBaseColumnIdxByName(String colName) { void write(DataOutput out) throws IOException; + /** + * return true if this kind of table need read lock when doing query plan. + * + * @return + */ + default boolean needReadLockWhenPlan() { + return false; + } + /** * Doris table type. */ diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/CascadesContext.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/CascadesContext.java index a81e9f008fab0e..39edea95d202ea 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/CascadesContext.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/CascadesContext.java @@ -521,6 +521,9 @@ public Lock(LogicalPlan plan, CascadesContext cascadesContext) { cascadesContext.extractTables(plan); } for (TableIf table : cascadesContext.tables.values()) { + if (!table.needReadLockWhenPlan()) { + continue; + } if (!table.tryReadLock(1, TimeUnit.MINUTES)) { close(); throw new RuntimeException(String.format("Failed to get read lock on table: %s", table.getName()));