Skip to content

Commit 5e0f8e6

Browse files
max prefixes count
Co-authored-by: Prashant Sharma <[email protected]>
1 parent 7f27481 commit 5e0f8e6

File tree

5 files changed

+46
-15
lines changed

5 files changed

+46
-15
lines changed

presto-main-base/src/main/java/com/facebook/presto/SystemSessionProperties.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787

8888
public final class SystemSessionProperties
8989
{
90+
public static final String MAX_PREFIXES_COUNT = "max_prefixes_count";
9091
public static final String OPTIMIZE_HASH_GENERATION = "optimize_hash_generation";
9192
public static final String JOIN_DISTRIBUTION_TYPE = "join_distribution_type";
9293
public static final String JOIN_MAX_BROADCAST_TABLE_SIZE = "join_max_broadcast_table_size";
@@ -389,6 +390,11 @@ public SystemSessionProperties(
389390
HistoryBasedOptimizationConfig historyBasedOptimizationConfig)
390391
{
391392
sessionProperties = ImmutableList.of(
393+
integerProperty(
394+
MAX_PREFIXES_COUNT,
395+
"Max prefixes count, tune for show queries performance improvement",
396+
featuresConfig.getMaxPrefixesCount(),
397+
false),
392398
stringProperty(
393399
EXECUTION_POLICY,
394400
"Policy used for scheduling query tasks",
@@ -1956,6 +1962,8 @@ public SystemSessionProperties(
19561962
false));
19571963
}
19581964

1965+
public static int getMaxPrefixesCount(Session session) { return session.getSystemProperty(MAX_PREFIXES_COUNT, Integer.class); }
1966+
19591967
public static boolean isSpoolingOutputBufferEnabled(Session session)
19601968
{
19611969
return session.getSystemProperty(SPOOLING_OUTPUT_BUFFER_ENABLED, Boolean.class);

presto-main-base/src/main/java/com/facebook/presto/connector/informationSchema/InformationSchemaMetadata.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import java.util.function.Predicate;
5050
import java.util.stream.Stream;
5151

52+
import static com.facebook.presto.SystemSessionProperties.getMaxPrefixesCount;
5253
import static com.facebook.presto.common.type.BigintType.BIGINT;
5354
import static com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType;
5455
import static com.facebook.presto.metadata.MetadataUtil.SchemaMetadataBuilder.schemaMetadataBuilder;
@@ -138,7 +139,6 @@ public class InformationSchemaMetadata
138139
private static final InformationSchemaColumnHandle CATALOG_COLUMN_HANDLE = new InformationSchemaColumnHandle("table_catalog");
139140
private static final InformationSchemaColumnHandle SCHEMA_COLUMN_HANDLE = new InformationSchemaColumnHandle("table_schema");
140141
private static final InformationSchemaColumnHandle TABLE_NAME_COLUMN_HANDLE = new InformationSchemaColumnHandle("table_name");
141-
private static final int MAX_PREFIXES_COUNT = 100;
142142

143143
private final String catalogName;
144144
private final Metadata metadata;
@@ -231,19 +231,21 @@ public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSess
231231
}
232232

233233
@Override
234-
public ConnectorTableLayoutResult getTableLayoutForConstraint(ConnectorSession session, ConnectorTableHandle table, Constraint<ColumnHandle> constraint, Optional<Set<ColumnHandle>> desiredColumns)
234+
public ConnectorTableLayoutResult getTableLayoutForConstraint(ConnectorSession connectorSession, ConnectorTableHandle table, Constraint<ColumnHandle> constraint, Optional<Set<ColumnHandle>> desiredColumns)
235235
{
236236
InformationSchemaTableHandle handle = checkTableHandle(table);
237+
Session session = ((FullConnectorSession) connectorSession).getSession();
238+
int maxPrefixesCount = getMaxPrefixesCount(session);
237239

238-
Set<QualifiedTablePrefix> prefixes = calculatePrefixesWithSchemaName(session, constraint.getSummary(), constraint.predicate());
240+
Set<QualifiedTablePrefix> prefixes = calculatePrefixesWithSchemaName(connectorSession, constraint.getSummary(), constraint.predicate());
239241
if (isTablesEnumeratingTable(handle.getSchemaTableName())) {
240-
Set<QualifiedTablePrefix> tablePrefixes = calculatePrefixesWithTableName(session, prefixes, constraint.getSummary(), constraint.predicate());
242+
Set<QualifiedTablePrefix> tablePrefixes = calculatePrefixesWithTableName(connectorSession, prefixes, constraint.getSummary(), constraint.predicate());
241243
// in case of high number of prefixes it is better to populate all data and then filter
242-
if (tablePrefixes.size() <= MAX_PREFIXES_COUNT) {
244+
if (tablePrefixes.size() <= maxPrefixesCount) {
243245
prefixes = tablePrefixes;
244246
}
245247
}
246-
if (prefixes.size() > MAX_PREFIXES_COUNT) {
248+
if (prefixes.size() > maxPrefixesCount) {
247249
// in case of high number of prefixes it is better to populate all data and then filter
248250
prefixes = ImmutableSet.of(new QualifiedTablePrefix(catalogName));
249251
}

presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/FeaturesConfig.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public class FeaturesConfig
9797
private boolean cteFilterAndProjectionPushdownEnabled = true;
9898
private int cteHeuristicReplicationThreshold = 4;
9999
private int maxReorderedJoins = 9;
100+
private int maxPrefixesCount = 100;
100101
private boolean useHistoryBasedPlanStatistics;
101102
private boolean trackHistoryBasedPlanStatistics;
102103
private boolean trackHistoryStatsFromFailedQuery = true;
@@ -459,6 +460,20 @@ public enum LeftJoinArrayContainsToInnerJoinStrategy
459460
ALWAYS_ENABLED
460461
}
461462

463+
@Min(1)
464+
@Config("max-prefixes-count")
465+
@ConfigDescription("Max prefixes count, tune for show queries performance improvement")
466+
public FeaturesConfig setMaxPrefixesCount(Integer maxPrefixesCount)
467+
{
468+
this.maxPrefixesCount = maxPrefixesCount;
469+
return this;
470+
}
471+
472+
public int getMaxPrefixesCount()
473+
{
474+
return maxPrefixesCount;
475+
}
476+
462477
public double getCpuCostWeight()
463478
{
464479
return cpuCostWeight;

presto-main-base/src/test/java/com/facebook/presto/metadata/TestInformationSchemaMetadata.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
import java.util.Optional;
4646

47+
import static com.facebook.presto.SystemSessionProperties.MAX_PREFIXES_COUNT;
4748
import static com.facebook.presto.common.type.VarcharType.VARCHAR;
4849
import static com.facebook.presto.metadata.MetadataManager.createTestMetadataManager;
4950
import static com.facebook.presto.spi.ConnectorId.createInformationSchemaConnectorId;
@@ -59,6 +60,7 @@ public class TestInformationSchemaMetadata
5960

6061
private final TransactionManager transactionManager;
6162
private final Metadata metadata;
63+
private static final String TEST_CATALOG = "test_catalog";
6264

6365
public TestInformationSchemaMetadata()
6466
{
@@ -102,9 +104,9 @@ public void testInformationSchemaPredicatePushdown()
102104
domains.put(new InformationSchemaColumnHandle("table_name"), Domain.singleValue(VARCHAR, Slices.utf8Slice("test_view")));
103105
Constraint<ColumnHandle> constraint = new Constraint<>(TupleDomain.withColumnDomains(domains.build()));
104106

105-
InformationSchemaMetadata informationSchemaMetadata = new InformationSchemaMetadata("test_catalog", metadata);
107+
InformationSchemaMetadata informationSchemaMetadata = new InformationSchemaMetadata(TEST_CATALOG, metadata);
106108
ConnectorTableLayoutResult layoutResult = informationSchemaMetadata.getTableLayoutForConstraint(
107-
createNewSession(transactionId),
109+
createNewSession(transactionId, 101),
108110
new InformationSchemaTableHandle("test_catalog", "information_schema", "views"),
109111
constraint,
110112
Optional.empty());
@@ -128,7 +130,7 @@ public void testInformationSchemaPredicatePushdownWithConstraintPredicate()
128130
NullableValue table = bindings.get(new InformationSchemaColumnHandle("table_name"));
129131
boolean isValid = true;
130132
if (catalog != null) {
131-
isValid = ((Slice) catalog.getValue()).toStringUtf8().equals("test_catalog");
133+
isValid = ((Slice) catalog.getValue()).toStringUtf8().equals(TEST_CATALOG);
132134
}
133135
if (schema != null) {
134136
isValid &= ((Slice) schema.getValue()).toStringUtf8().equals("test_schema");
@@ -139,25 +141,26 @@ public void testInformationSchemaPredicatePushdownWithConstraintPredicate()
139141
return isValid;
140142
});
141143

142-
InformationSchemaMetadata informationSchemaMetadata = new InformationSchemaMetadata("test_catalog", metadata);
144+
InformationSchemaMetadata informationSchemaMetadata = new InformationSchemaMetadata(TEST_CATALOG, metadata);
143145
ConnectorTableLayoutResult layoutResult = informationSchemaMetadata.getTableLayoutForConstraint(
144-
createNewSession(transactionId),
145-
new InformationSchemaTableHandle("test_catalog", "information_schema", "views"),
146+
createNewSession(transactionId, 10),
147+
new InformationSchemaTableHandle(TEST_CATALOG, "information_schema", "views"),
146148
constraint,
147149
Optional.empty());
148150

149151
ConnectorTableLayoutHandle handle = layoutResult.getTableLayout().getHandle();
150152
assertTrue(handle instanceof InformationSchemaTableLayoutHandle);
151153
InformationSchemaTableLayoutHandle tableHandle = (InformationSchemaTableLayoutHandle) handle;
152-
assertEquals(tableHandle.getPrefixes(), ImmutableSet.of(new QualifiedTablePrefix("test_catalog", "test_schema", "test_view")));
154+
assertEquals(tableHandle.getPrefixes(), ImmutableSet.of(new QualifiedTablePrefix(TEST_CATALOG, "test_schema", "test_view")));
153155
}
154156

155-
private ConnectorSession createNewSession(TransactionId transactionId)
157+
private ConnectorSession createNewSession(TransactionId transactionId, int maxPrefixesCount)
156158
{
157159
return testSessionBuilder()
158-
.setCatalog("test_catalog")
160+
.setCatalog(TEST_CATALOG)
159161
.setSchema("information_schema")
160162
.setTransactionId(transactionId)
163+
.setSystemProperty(MAX_PREFIXES_COUNT, String.valueOf(maxPrefixesCount))
161164
.build()
162165
.toConnectorSession();
163166
}

presto-main-base/src/test/java/com/facebook/presto/sql/analyzer/TestFeaturesConfig.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public class TestFeaturesConfig
5959
public void testDefaults()
6060
{
6161
assertRecordedDefaults(ConfigAssertions.recordDefaults(FeaturesConfig.class)
62+
.setMaxPrefixesCount(100)
6263
.setCpuCostWeight(75)
6364
.setMemoryCostWeight(10)
6465
.setNetworkCostWeight(15)
@@ -273,6 +274,7 @@ public void testDefaults()
273274
public void testExplicitPropertyMappings()
274275
{
275276
Map<String, String> properties = new ImmutableMap.Builder<String, String>()
277+
.put("max-prefixes-count", "1")
276278
.put("cpu-cost-weight", "0.4")
277279
.put("memory-cost-weight", "0.3")
278280
.put("network-cost-weight", "0.2")
@@ -483,6 +485,7 @@ public void testExplicitPropertyMappings()
483485
.build();
484486

485487
FeaturesConfig expected = new FeaturesConfig()
488+
.setMaxPrefixesCount(1)
486489
.setCpuCostWeight(0.4)
487490
.setMemoryCostWeight(0.3)
488491
.setNetworkCostWeight(0.2)

0 commit comments

Comments
 (0)