From e1c649e90683a5b49648522d4c7e0ff1088f1efd Mon Sep 17 00:00:00 2001 From: Gian Merlino Date: Wed, 19 Sep 2018 15:54:13 -0700 Subject: [PATCH] Add metadata indexes to help with segment allocation. (#6348) Segment allocation queries can take a long time (10s of seconds) when you have a lot of segments. Adding these indexes helps greatly. --- .../druid/metadata/SQLMetadataConnector.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/org/apache/druid/metadata/SQLMetadataConnector.java b/server/src/main/java/org/apache/druid/metadata/SQLMetadataConnector.java index 8c8528142e5..688409e3cf9 100644 --- a/server/src/main/java/org/apache/druid/metadata/SQLMetadataConnector.java +++ b/server/src/main/java/org/apache/druid/metadata/SQLMetadataConnector.java @@ -23,11 +23,11 @@ import com.google.common.base.Predicate; import com.google.common.base.Supplier; import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; +import org.apache.commons.dbcp2.BasicDataSource; import org.apache.druid.java.util.common.ISE; import org.apache.druid.java.util.common.RetryUtils; import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.java.util.common.logger.Logger; -import org.apache.commons.dbcp2.BasicDataSource; import org.skife.jdbi.v2.Batch; import org.skife.jdbi.v2.DBI; import org.skife.jdbi.v2.Handle; @@ -215,6 +215,11 @@ public abstract class SQLMetadataConnector implements MetadataStorageConnector + " UNIQUE (sequence_name_prev_id_sha1)\n" + ")", tableName, getPayloadType(), getQuoteString() + ), + StringUtils.format( + "CREATE INDEX idx_%1$s_datasource_used_end ON %1$s(dataSource, used, %2$send%2$s)", + tableName, + getQuoteString() ) ) ); @@ -259,8 +264,15 @@ public abstract class SQLMetadataConnector implements MetadataStorageConnector + ")", tableName, getPayloadType(), getQuoteString() ), - StringUtils.format("CREATE INDEX idx_%1$s_datasource ON %1$s(dataSource)", tableName), - StringUtils.format("CREATE INDEX idx_%1$s_used ON %1$s(used)", tableName) + StringUtils.format( + "CREATE INDEX idx_%1$s_datasource_end ON %1$s(dataSource, %2$send%2$s)", + tableName, + getQuoteString() + ), + StringUtils.format( + "CREATE INDEX idx_%1$s_datasource_sequence ON %1$s(dataSource, sequence_name)", + tableName + ) ) ); }