Skip to content

Commit 579dc36

Browse files
feat: add max-prefixes-count session property
Introduce a new session property `max-prefixes-count` to tune prefixes. Co-authored-by: Prashant Sharma <[email protected]>
1 parent 6a51bc1 commit 579dc36

File tree

7 files changed

+72
-16
lines changed

7 files changed

+72
-16
lines changed

presto-docs/src/main/sphinx/admin/properties-session.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,17 @@ Maximum object size in bytes that can be considered serializable in a function c
135135

136136
The corresponding configuration property is :ref:`admin/properties:\`\`max-serializable-object-size\`\``.
137137

138+
``max_prefixes_count``
139+
^^^^^^^^^^^^^^^^^^^^^^
140+
141+
* **Type:** ``integer``
142+
* **Minimum value:** ``1``
143+
* **Default value:** ``100``
144+
145+
Maximum number of prefixes that will be used when performing a ``SHOW QUERY``.
146+
147+
The corresponding configuration property is :ref:`admin/properties:\`\`max-prefixes-count\`\``.
148+
138149
Spilling Properties
139150
-------------------
140151

presto-docs/src/main/sphinx/admin/properties.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,18 @@ The corresponding session property is :ref:`admin/properties-session:\`\`offset_
157157

158158
Maximum object size in bytes that can be considered serializable in a function call by the coordinator.
159159

160-
The corresponding session property is :ref:`admin/properties-session:\`\`max_serializable_object_size\`\``.
160+
The corresponding session property is :ref:`admin/properties-session:\`\`max_serializable_object_size\`\``.
161+
162+
``max-prefixes-count``
163+
^^^^^^^^^^^^^^^^^^^^^^
164+
165+
* **Type:** ``integer``
166+
* **Minimum value:** ``1``
167+
* **Default value:** ``100``
168+
169+
Maximum number of prefixes that will be used when performing a ``SHOW QUERY``.
170+
171+
The corresponding session property is :ref:`admin/properties-session:\`\`max_prefixes_count\`\``.
161172

162173
Memory Management Properties
163174
----------------------------

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989

9090
public final class SystemSessionProperties
9191
{
92+
public static final String MAX_PREFIXES_COUNT = "max_prefixes_count";
9293
public static final String OPTIMIZE_HASH_GENERATION = "optimize_hash_generation";
9394
public static final String JOIN_DISTRIBUTION_TYPE = "join_distribution_type";
9495
public static final String JOIN_MAX_BROADCAST_TABLE_SIZE = "join_max_broadcast_table_size";
@@ -396,6 +397,11 @@ public SystemSessionProperties(
396397
HistoryBasedOptimizationConfig historyBasedOptimizationConfig)
397398
{
398399
sessionProperties = ImmutableList.of(
400+
integerProperty(
401+
MAX_PREFIXES_COUNT,
402+
"Max prefixes count, tune for show queries performance improvement",
403+
featuresConfig.getMaxPrefixesCount(),
404+
false),
399405
stringProperty(
400406
EXECUTION_POLICY,
401407
"Policy used for scheduling query tasks",
@@ -2003,6 +2009,11 @@ public SystemSessionProperties(
20032009
false));
20042010
}
20052011

2012+
public static int getMaxPrefixesCount(Session session)
2013+
{
2014+
return session.getSystemProperty(MAX_PREFIXES_COUNT, Integer.class);
2015+
}
2016+
20062017
public static boolean isSpoolingOutputBufferEnabled(Session session)
20072018
{
20082019
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;
@@ -141,7 +142,6 @@ public class InformationSchemaMetadata
141142
private static final InformationSchemaColumnHandle CATALOG_COLUMN_HANDLE = new InformationSchemaColumnHandle("table_catalog");
142143
private static final InformationSchemaColumnHandle SCHEMA_COLUMN_HANDLE = new InformationSchemaColumnHandle("table_schema");
143144
private static final InformationSchemaColumnHandle TABLE_NAME_COLUMN_HANDLE = new InformationSchemaColumnHandle("table_name");
144-
private static final int MAX_PREFIXES_COUNT = 100;
145145

146146
private final String catalogName;
147147
private final Metadata metadata;
@@ -234,19 +234,21 @@ public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSess
234234
}
235235

236236
@Override
237-
public ConnectorTableLayoutResult getTableLayoutForConstraint(ConnectorSession session, ConnectorTableHandle table, Constraint<ColumnHandle> constraint, Optional<Set<ColumnHandle>> desiredColumns)
237+
public ConnectorTableLayoutResult getTableLayoutForConstraint(ConnectorSession connectorSession, ConnectorTableHandle table, Constraint<ColumnHandle> constraint, Optional<Set<ColumnHandle>> desiredColumns)
238238
{
239239
InformationSchemaTableHandle handle = checkTableHandle(table);
240+
Session session = ((FullConnectorSession) connectorSession).getSession();
241+
int maxPrefixesCount = getMaxPrefixesCount(session);
240242

241-
Set<QualifiedTablePrefix> prefixes = calculatePrefixesWithSchemaName(session, constraint.getSummary(), constraint.predicate());
243+
Set<QualifiedTablePrefix> prefixes = calculatePrefixesWithSchemaName(connectorSession, constraint.getSummary(), constraint.predicate());
242244
if (isTablesEnumeratingTable(handle.getSchemaTableName())) {
243-
Set<QualifiedTablePrefix> tablePrefixes = calculatePrefixesWithTableName(session, prefixes, constraint.getSummary(), constraint.predicate());
245+
Set<QualifiedTablePrefix> tablePrefixes = calculatePrefixesWithTableName(connectorSession, prefixes, constraint.getSummary(), constraint.predicate());
244246
// in case of high number of prefixes it is better to populate all data and then filter
245-
if (tablePrefixes.size() <= MAX_PREFIXES_COUNT) {
247+
if (tablePrefixes.size() <= maxPrefixesCount) {
246248
prefixes = tablePrefixes;
247249
}
248250
}
249-
if (prefixes.size() > MAX_PREFIXES_COUNT) {
251+
if (prefixes.size() > maxPrefixesCount) {
250252
// in case of high number of prefixes it is better to populate all data and then filter
251253
prefixes = ImmutableSet.of(new QualifiedTablePrefix(catalogName));
252254
}

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
@@ -102,6 +102,7 @@ public class FeaturesConfig
102102
private boolean cteFilterAndProjectionPushdownEnabled = true;
103103
private int cteHeuristicReplicationThreshold = 4;
104104
private int maxReorderedJoins = 9;
105+
private int maxPrefixesCount = 100;
105106
private boolean useHistoryBasedPlanStatistics;
106107
private boolean trackHistoryBasedPlanStatistics;
107108
private boolean trackHistoryStatsFromFailedQuery = true;
@@ -477,6 +478,20 @@ public enum LeftJoinArrayContainsToInnerJoinStrategy
477478
ALWAYS_ENABLED
478479
}
479480

481+
@Min(1)
482+
@Config("max-prefixes-count")
483+
@ConfigDescription("Max prefixes count, tune for show queries performance improvement")
484+
public FeaturesConfig setMaxPrefixesCount(Integer maxPrefixesCount)
485+
{
486+
this.maxPrefixesCount = maxPrefixesCount;
487+
return this;
488+
}
489+
490+
public int getMaxPrefixesCount()
491+
{
492+
return maxPrefixesCount;
493+
}
494+
480495
public double getCpuCostWeight()
481496
{
482497
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)
@@ -279,6 +280,7 @@ public void testDefaults()
279280
public void testExplicitPropertyMappings()
280281
{
281282
Map<String, String> properties = new ImmutableMap.Builder<String, String>()
283+
.put("max-prefixes-count", "1")
282284
.put("cpu-cost-weight", "0.4")
283285
.put("memory-cost-weight", "0.3")
284286
.put("network-cost-weight", "0.2")
@@ -495,6 +497,7 @@ public void testExplicitPropertyMappings()
495497
.build();
496498

497499
FeaturesConfig expected = new FeaturesConfig()
500+
.setMaxPrefixesCount(1)
498501
.setCpuCostWeight(0.4)
499502
.setMemoryCostWeight(0.3)
500503
.setNetworkCostWeight(0.2)

0 commit comments

Comments
 (0)