Skip to content
Open
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 @@ -578,7 +578,6 @@ public static NormalizationResult normalizeQuery(@Nonnull final PlanContext cont
() -> normalizeAst(
context.getSchemaTemplate(), parseTreeInfo,
PreparedParams.copyOf(context.getPreparedStatementParameters()),
context.getUserVersion(),
context.getPlannerConfiguration(),
isCaseSensitive,
currentPlanHashMode,
Expand All @@ -591,7 +590,6 @@ public static NormalizationResult normalizeQuery(@Nonnull final PlanContext cont
public static NormalizationResult normalizeAst(@Nonnull final SchemaTemplate schemaTemplate,
@Nonnull final ParseTreeInfoImpl parseTreeInfo,
@Nonnull final PreparedParams preparedStatementParameters,
int userVersion,
@Nonnull final PlannerConfiguration plannerConfiguration,
boolean caseSensitive,
@Nonnull final PlanHashable.PlanHashMode currentPlanHashMode,
Expand Down Expand Up @@ -621,7 +619,6 @@ public static NormalizationResult normalizeAst(@Nonnull final SchemaTemplate sch
final var functionAstResult = normalizeAst(schemaTemplate,
QueryParser.parse(recordLayerRoutine.getDescription()),
recordLayerRoutine.getPreparedParams(),
userVersion,
plannerConfiguration,
caseSensitive,
currentPlanHashMode,
Expand All @@ -633,7 +630,7 @@ public static NormalizationResult normalizeAst(@Nonnull final SchemaTemplate sch
recordLayerSchemaTemplate.getName(),
QueryCacheKey.of(astNormalizer.getCanonicalSqlString(), getQuerySpecificPlannerConfig(plannerConfiguration, astNormalizer.getQueryOptions()),
recordLayerSchemaTemplate.getTransactionBoundMetadataAsString(),
recordLayerSchemaTemplate.getVersion(), userVersion),
recordLayerSchemaTemplate.getVersion()),
astNormalizer.getQueryExecutionParameters(),
parseTreeInfo.getRootContext(),
astNormalizer.getQueryCachingFlags(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ public final class PlanContext {
@Nonnull
private final SchemaTemplate schemaTemplate;

private final int userVersion;

private final boolean isCaseSensitive;

/**
Expand All @@ -77,7 +75,6 @@ public final class PlanContext {
* @param dbUri The URI of the database.
* @param ddlQueryFactory The DDL factory.
* @param preparedStatementParameters A list of prepared statement parameters.
* @param userVersion The user version bound to the opened record store.
* @param isCaseSensitive {@code True} if SQL identifiers should be treated as case-sensitive, otherwise
* {@code false}.
**/
Expand All @@ -89,7 +86,6 @@ private PlanContext(@Nonnull RecordMetaData metaData,
@Nonnull DdlQueryFactory ddlQueryFactory,
@Nonnull URI dbUri,
@Nonnull PreparedParams preparedStatementParameters,
final int userVersion,
boolean isCaseSensitive) {
this.metaData = metaData;
this.metricCollector = metricCollector;
Expand All @@ -99,7 +95,6 @@ private PlanContext(@Nonnull RecordMetaData metaData,
this.ddlQueryFactory = ddlQueryFactory;
this.dbUri = dbUri;
this.preparedStatementParameters = preparedStatementParameters;
this.userVersion = userVersion;
this.isCaseSensitive = isCaseSensitive;
}

Expand Down Expand Up @@ -153,10 +148,6 @@ public SchemaTemplate getSchemaTemplate() {
return schemaTemplate;
}

public int getUserVersion() {
return userVersion;
}

@Nonnull
public static Builder builder() {
return new Builder();
Expand All @@ -170,8 +161,6 @@ public static final class Builder {

private PlannerConfiguration plannerConfiguration;

private int userVersion;

private SchemaTemplate schemaTemplate;

private MetadataOperationsFactory metadataOperationsFactory;
Expand Down Expand Up @@ -213,13 +202,6 @@ public Builder withPlannerConfiguration(@Nonnull PlannerConfiguration plannerCon
return this;
}

@Nonnull
@VisibleForTesting
public Builder withUserVersion(int userVersion) {
this.userVersion = userVersion;
return this;
}

@Nonnull
private Builder isCaseSensitive(boolean isCaseSensitive) {
this.isCaseSensitive = isCaseSensitive;
Expand Down Expand Up @@ -271,7 +253,6 @@ public Builder fromRecordStore(@Nonnull FDBRecordStoreBase<?> recordStore, @Nonn
PlannerConfiguration.of(getReadableIndexes(recordStore.getRecordMetaData(), recordStore.getRecordStoreState()), options);
return withPlannerConfiguration(plannerConfig)
.withMetadata(recordStore.getRecordMetaData())
.withUserVersion(recordStore.getRecordStoreState().getStoreHeader().getUserVersion())
.isCaseSensitive(options.getOption(Options.Name.CASE_SENSITIVE_IDENTIFIERS));
}

Expand All @@ -298,7 +279,7 @@ private void verify() throws RelationalException {
public PlanContext build() throws RelationalException {
verify();
return new PlanContext(metaData, metricCollector, schemaTemplate, plannerConfiguration, metadataOperationsFactory,
ddlQueryFactory, dbUri, preparedStatementParameters, userVersion, isCaseSensitive);
ddlQueryFactory, dbUri, preparedStatementParameters, isCaseSensitive);
}

@Nonnull
Expand All @@ -316,7 +297,6 @@ public static Builder unapply(@Nonnull PlanContext planContext) {
.withSchemaTemplate(planContext.schemaTemplate)
.withDdlQueryFactory(planContext.ddlQueryFactory)
.withPlannerConfiguration(planContext.plannerConfiguration)
.withUserVersion(planContext.userVersion)
.withPreparedParameters(planContext.preparedStatementParameters)
.isCaseSensitive(planContext.isCaseSensitive);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* <ul>
* <li>The schema template name to which the query is bound. It is necessary to use it so we can segregate
* the otherwise identical plans but coming from different schemas (see Example 1 below)</li>
* <li>The schema template version, user version, and a bit-set of all readable indexes</li>
* <li>The schema template version and a bit-set of all readable indexes</li>
* <li>The canonical query string where all literals are removed and white spaces are normalised (see example 2)</li>
* <li>The hash of the query, see {@link AstNormalizer} for more information on how is this generated.</li>
* </ul>
Expand Down Expand Up @@ -110,25 +110,21 @@ public final class QueryCacheKey {

private final int schemaTemplateVersion;

private final int userVersion;

private final int memoizedHashCode;

private QueryCacheKey(@Nonnull final String canonicalQueryString,
@Nonnull final PlannerConfiguration plannerConfiguration,
@Nonnull final String auxiliaryMetadata,
int schemaTemplateVersion,
int userVersion) {
int schemaTemplateVersion) {
this.canonicalQueryString = canonicalQueryString;
this.schemaTemplateVersion = schemaTemplateVersion;
this.userVersion = userVersion;
this.auxiliaryMetadata = auxiliaryMetadata;
this.plannerConfiguration = plannerConfiguration;

// Memoize the hash code. Because this object is used as a key in a hash map, it is important that
// hashCode() be quick. Note that this includes information about the query (canonicalQueryString is like the query hash),
// the schema template version, and the schema (like the set of readable indexes)
this.memoizedHashCode = Objects.hash(canonicalQueryString, schemaTemplateVersion, plannerConfiguration, userVersion, auxiliaryMetadata);
this.memoizedHashCode = Objects.hash(canonicalQueryString, schemaTemplateVersion, plannerConfiguration, auxiliaryMetadata);
}

@Override
Expand All @@ -141,7 +137,6 @@ public boolean equals(Object other) {
}
final var that = (QueryCacheKey) other;
return schemaTemplateVersion == that.schemaTemplateVersion &&
userVersion == that.userVersion &&
Objects.equals(canonicalQueryString, that.canonicalQueryString) &&
Objects.equals(auxiliaryMetadata, that.auxiliaryMetadata) &&
Objects.equals(plannerConfiguration, that.plannerConfiguration);
Expand All @@ -166,10 +161,6 @@ public PlannerConfiguration getPlannerConfiguration() {
return plannerConfiguration;
}

public int getUserVersion() {
return userVersion;
}

@Nonnull
public String getAuxiliaryMetadata() {
return auxiliaryMetadata;
Expand All @@ -184,9 +175,7 @@ public String toString() {
public static QueryCacheKey of(@Nonnull final String query,
@Nonnull final PlannerConfiguration plannerConfiguration,
@Nonnull final String auxiliaryMetadata,
int schemaTemplateVersion,
int userVersion) {
return new QueryCacheKey(query, plannerConfiguration, auxiliaryMetadata, schemaTemplateVersion,
userVersion);
int schemaTemplateVersion) {
return new QueryCacheKey(query, plannerConfiguration, auxiliaryMetadata, schemaTemplateVersion);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ static PlanContext createVanillaPlanContext(@Nonnull final EmbeddedRelationalCon
.withMetadata(RecordMetaData.build(md))
.withMetricsCollector(Assert.notNullUnchecked(connection.getMetricCollector()))
.withPlannerConfiguration(PlannerConfiguration.ofAllAvailableIndexes())
.withUserVersion(0)
.withDbUri(URI.create(databaseUri))
.withDdlQueryFactory(NoOpQueryFactory.INSTANCE)
.withConstantActionFactory(NoOpMetadataOperationsFactory.INSTANCE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ public boolean execute(String sql) throws SQLException {
.withMetadata(relationalConn.getSchemaTemplate().unwrap(RecordLayerSchemaTemplate.class).toRecordMetadata())
.withSchemaTemplate(relationalConn.getSchemaTemplate())
.withPlannerConfiguration(PlannerConfiguration.ofAllAvailableIndexes())
.withUserVersion(0)
.build();

final var planGenerator = PlanGenerator.create(Optional.empty(), ctx, ctx.getMetaData(), new RecordStoreState(null, Map.of()), IndexMaintainerFactoryRegistryImpl.instance(), Options.NONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,6 @@ public PlanGenerator getPlanGenerator() throws RelationalException, SQLException
.withMetadata(getRecordMetaData())
.withSchemaTemplate(getSchemaTemplate("testSchema", 42))
.withPlannerConfiguration(PlannerConfiguration.ofAllAvailableIndexes())
.withUserVersion(0)
.build();
return PlanGenerator.create(Optional.empty(), ctx, ctx.getMetaData(), new RecordStoreState(null, Map.of()),
IndexMaintainerFactoryRegistryImpl.instance(), Options.builder().withOption(Options.Name.CASE_SENSITIVE_IDENTIFIERS, true).build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ private static void validate(@Nonnull final List<String> queries,
final var query = queries.get(i);
final var expectedParameters = expectedParametersList.get(i);
final var hashResults = AstNormalizer.normalizeAst(schemaTemplates.get(i), QueryParser.parse(query),
PreparedParams.copyOf(preparedParameters), 0, plannerConfiguration, false, PlanHashable.PlanHashMode.VC0, query);
PreparedParams.copyOf(preparedParameters), plannerConfiguration, false, PlanHashable.PlanHashMode.VC0, query);
Assertions.assertThat(hashResults.getQueryCacheKey().getCanonicalQueryString()).isEqualTo(expectedCanonicalRepresentation);
Assertions.assertThat(hashResults.getQueryCacheKey().getAuxiliaryMetadata()).isEqualTo(auxiliaryMetadata);
final var execParams = hashResults.getQueryExecutionContext();
Expand Down Expand Up @@ -310,7 +310,7 @@ private static void validate(@Nonnull final List<String> queries,
private static void shouldFail(@Nonnull final String query, @Nonnull final String errorMessage) {
try {
AstNormalizer.normalizeAst(fakeSchemaTemplate, QueryParser.parse(query),
PreparedParams.empty(), 0, plannerConfiguration, false, PlanHashable.PlanHashMode.VC0, query);
PreparedParams.empty(), plannerConfiguration, false, PlanHashable.PlanHashMode.VC0, query);
Assertions.fail(String.format(Locale.ROOT, "expected %s to fail with %s, but it succeeded!", query, errorMessage));
} catch (RelationalException | UncheckedRelationalException e) {
Assertions.assertThat(e.getMessage()).contains(errorMessage);
Expand All @@ -334,9 +334,9 @@ private static void validateNotSameHash(@Nonnull final String query1,
@Nonnull PreparedParams preparedParams2) throws RelationalException {

final var result1 = AstNormalizer.normalizeAst(fakeSchemaTemplate, QueryParser.parse(query1),
PreparedParams.copyOf(preparedParams1), 0, plannerConfiguration, false, PlanHashable.PlanHashMode.VC0, query1);
PreparedParams.copyOf(preparedParams1), plannerConfiguration, false, PlanHashable.PlanHashMode.VC0, query1);
final var result2 = AstNormalizer.normalizeAst(fakeSchemaTemplate, QueryParser.parse(query2),
PreparedParams.copyOf(preparedParams2), 0, plannerConfiguration, false, PlanHashable.PlanHashMode.VC0, query2);
PreparedParams.copyOf(preparedParams2), plannerConfiguration, false, PlanHashable.PlanHashMode.VC0, query2);
Assertions.assertThat(result1.getQueryCacheKey().hashCode()).isNotEqualTo(result2.getQueryCacheKey().hashCode());
}

Expand All @@ -349,9 +349,9 @@ private static void validateNotEqual(@Nonnull final String query1,
@Nonnull final String query2,
@Nonnull PreparedParams preparedParams) throws RelationalException {
final var result1 = AstNormalizer.normalizeAst(fakeSchemaTemplate, QueryParser.parse(query1),
PreparedParams.copyOf(preparedParams), 0, plannerConfiguration, false, PlanHashable.PlanHashMode.VC0, query1);
PreparedParams.copyOf(preparedParams), plannerConfiguration, false, PlanHashable.PlanHashMode.VC0, query1);
final var result2 = AstNormalizer.normalizeAst(fakeSchemaTemplate, QueryParser.parse(query2),
PreparedParams.copyOf(preparedParams), 0, plannerConfiguration, false, PlanHashable.PlanHashMode.VC0, query2);
PreparedParams.copyOf(preparedParams), plannerConfiguration, false, PlanHashable.PlanHashMode.VC0, query2);
Assertions.assertThat(result1.getQueryCacheKey()).isNotEqualTo(result2.getQueryCacheKey());
}

Expand All @@ -361,9 +361,9 @@ private static void validateNotEqual(@Nonnull final String query1,
@Nonnull final RecordLayerSchemaTemplate schemaTemplate2,
@Nonnull PreparedParams preparedParams) throws RelationalException {
final var result1 = AstNormalizer.normalizeAst(schemaTemplate1, QueryParser.parse(query1),
PreparedParams.copyOf(preparedParams), 0, plannerConfiguration, false, PlanHashable.PlanHashMode.VC0, query1);
PreparedParams.copyOf(preparedParams), plannerConfiguration, false, PlanHashable.PlanHashMode.VC0, query1);
final var result2 = AstNormalizer.normalizeAst(schemaTemplate2, QueryParser.parse(query2),
PreparedParams.copyOf(preparedParams), 0, plannerConfiguration, false, PlanHashable.PlanHashMode.VC0, query2);
PreparedParams.copyOf(preparedParams), plannerConfiguration, false, PlanHashable.PlanHashMode.VC0, query2);
Assertions.assertThat(result1.getQueryCacheKey()).isNotEqualTo(result2.getQueryCacheKey());
}

Expand Down Expand Up @@ -395,7 +395,7 @@ private static RecordLayerSchemaTemplate schemaTemplateWithFunction(@Nonnull fin
final String canonicalFunctionDdl;
if (isTemporary) {
final var normalizer = AstNormalizer.normalizeAst(schemaTemplate, QueryParser.parse(functionDdl), PreparedParams.empty(),
0, plannerConfiguration, false, PlanHashable.PlanHashMode.VC0, functionDdl);
plannerConfiguration, false, PlanHashable.PlanHashMode.VC0, functionDdl);
canonicalFunctionDdl = normalizer.getQueryCacheKey().getCanonicalQueryString();
} else {
canonicalFunctionDdl = functionDdl;
Expand Down Expand Up @@ -1449,7 +1449,7 @@ void windowFunctionOptionsAreNotStripped() throws Exception {
private String normalizeQuery(@Nonnull final String functionDdl) throws RelationalException {
final var normalizer = AstNormalizer.normalizeAst(fakeSchemaTemplate,
QueryParser.parse(functionDdl), PreparedParams.empty(),
0, plannerConfiguration, false, PlanHashable.PlanHashMode.VC0, functionDdl);
plannerConfiguration, false, PlanHashable.PlanHashMode.VC0, functionDdl);
return normalizer.getQueryCacheKey().getCanonicalQueryString();
}

Expand All @@ -1467,8 +1467,8 @@ void explainAndNonExplainProduceSameCanonicalQueryString() throws RelationalExce
final var selPT = QueryParser.parse(selQ);
final var expPT = QueryParser.parse(expQ);

final var selRes = AstNormalizer.normalizeAst(fakeSchemaTemplate, selPT, PreparedParams.empty(), 0, plannerConfiguration, false, PlanHashable.PlanHashMode.VC0, selQ);
final var expRes = AstNormalizer.normalizeAst(fakeSchemaTemplate, expPT, PreparedParams.empty(), 0, plannerConfiguration, false, PlanHashable.PlanHashMode.VC0, expQ);
final var selRes = AstNormalizer.normalizeAst(fakeSchemaTemplate, selPT, PreparedParams.empty(), plannerConfiguration, false, PlanHashable.PlanHashMode.VC0, selQ);
final var expRes = AstNormalizer.normalizeAst(fakeSchemaTemplate, expPT, PreparedParams.empty(), plannerConfiguration, false, PlanHashable.PlanHashMode.VC0, expQ);

// compare NormalizationResult
Assertions.assertThat(expRes.getQueryCacheKey().getCanonicalQueryString())
Expand Down Expand Up @@ -1496,7 +1496,7 @@ void visitFullDescribeStatementThrows() throws ReflectiveOperationException {

@Test
void queryCacheKeyToString() {
final var key = QueryCacheKey.of("select ? from testTable", plannerConfiguration, "someAuxiliaryMetadata", 3, 7);
final var key = QueryCacheKey.of("select ? from testTable", plannerConfiguration, "someAuxiliaryMetadata", 3);
final var expected = "(3 || someAuxiliaryMetadata)||select ? from testTable||" + key.hashCode();
Assertions.assertThat(key).hasToString(expected);
}
Expand Down
Loading