Skip to content
Merged
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 @@ -214,12 +214,6 @@ public enum Name {
*/
VALID_PLAN_HASH_MODES,

/**
* Boolean indicator if continuations generated for query responses may contain serialized compiled statements
* that can be used in EXECUTE CONTINUATION statements.
*/
CONTINUATIONS_CONTAIN_COMPILED_STATEMENTS,

/**
* Timeout for asynchronous operations in milliseconds, this is usually used to set an upperbound time limit for
* operations interacting with FDB.
Expand Down Expand Up @@ -294,7 +288,6 @@ public enum IndexFetchMethod {
builder.put(Name.EXECUTION_SCANNED_ROWS_LIMIT, Integer.MAX_VALUE);
builder.put(Name.DRY_RUN, false);
builder.put(Name.CASE_SENSITIVE_IDENTIFIERS, false);
builder.put(Name.CONTINUATIONS_CONTAIN_COMPILED_STATEMENTS, true);
builder.put(Name.ASYNC_OPERATIONS_TIMEOUT_MILLIS, 10_000L);
builder.put(Name.ENCRYPT_WHEN_SERIALIZING, false);
builder.put(Name.ENCRYPTION_KEY_PASSWORD, "");
Expand Down Expand Up @@ -551,7 +544,6 @@ private static Map<Name, List<OptionContract>> makeContracts() {
data.put(Name.CASE_SENSITIVE_IDENTIFIERS, List.of(TypeContract.booleanType()));
data.put(Name.CURRENT_PLAN_HASH_MODE, List.of(TypeContract.stringType()));
data.put(Name.VALID_PLAN_HASH_MODES, List.of(TypeContract.stringType()));
data.put(Name.CONTINUATIONS_CONTAIN_COMPILED_STATEMENTS, List.of(TypeContract.booleanType()));
data.put(Name.ASYNC_OPERATIONS_TIMEOUT_MILLIS, List.of(TypeContract.longType(), RangeContract.of(0L, Long.MAX_VALUE)));
data.put(Name.ENCRYPT_WHEN_SERIALIZING, List.of(TypeContract.booleanType()));
data.put(Name.ENCRYPTION_KEY_STORE, List.of(TypeContract.nullableStringType()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public static Options nonDefaultOptions() throws SQLException {
builder = builder.withOption(Options.Name.CASE_SENSITIVE_IDENTIFIERS, true);
builder = builder.withOption(Options.Name.CURRENT_PLAN_HASH_MODE, "m1");
builder = builder.withOption(Options.Name.VALID_PLAN_HASH_MODES, "m1,m2");
builder = builder.withOption(Options.Name.CONTINUATIONS_CONTAIN_COMPILED_STATEMENTS, false);
builder = builder.withOption(Options.Name.ASYNC_OPERATIONS_TIMEOUT_MILLIS, 5000L);
builder = builder.withOption(Options.Name.ENCRYPT_WHEN_SERIALIZING, true);
builder = builder.withOption(Options.Name.ENCRYPTION_KEY_STORE, "secrets.ks");
Expand Down
1 change: 0 additions & 1 deletion fdb-relational-core/src/main/antlr/RelationalParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,6 @@ queryOption
: NOCACHE
| LOG QUERY
| DRY RUN
| CONTINUATION CONTAINS COMPILED STATEMENT
;

// Transaction's Statements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,6 @@ public Object visitQueryOption(@Nonnull RelationalParser.QueryOptionContext ctx)
if (ctx.DRY() != null) {
queryOptions.withOption(Options.Name.DRY_RUN, true);
}
if (ctx.CONTINUATION() != null) {
queryOptions.withOption(Options.Name.CONTINUATIONS_CONTAIN_COMPILED_STATEMENTS, true);
}
return null;
} catch (SQLException e) {
throw ExceptionUtil.toRelationalException(e).toUncheckedWrappedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

import javax.annotation.Nonnull;
import java.util.Arrays;
import java.util.Objects;
import java.util.Set;

@API(API.Status.INTERNAL)
Expand All @@ -56,10 +55,6 @@ public static Set<PlanHashable.PlanHashMode> getValidPlanHashModes(@Nonnull fina
.collect(ImmutableSet.toImmutableSet());
}

public static boolean getContinuationsContainsCompiledStatements(@Nonnull final Options options) {
return Objects.requireNonNull(options.getOption(Options.Name.CONTINUATIONS_CONTAIN_COMPILED_STATEMENTS));
}

@Nonnull
public static IndexFetchMethod getIndexFetchMethod(@Nonnull final Options options) {
Options.IndexFetchMethod indexFetchMethod = options.getOption(Options.Name.INDEX_FETCH_METHOD);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,7 @@ protected <M extends Message> void validatePlanAgainstEnvironment(@Nonnull final
PlanValidator.validateHashes(parsedContinuation, executionContext.metricCollector,
recordQueryPlan, queryExecutionContext, currentPlanHashMode, validPlanHashModes);

final var options = executionContext.getOptions();
final var continuationsContainCompiledStatements = OptionsUtils.getContinuationsContainsCompiledStatements(options);
if (continuationsContainCompiledStatements && !parsedContinuation.atBeginning()) {
if (!parsedContinuation.atBeginning()) {
// if we are here it means that the current execution is from a regular planned plan, i.e. not
// an EXECUTE CONTINUATION statement but it uses a continuation that is not at the beginning.
// this can only happen if the query was started without the use of serialized plans, and we are now
Expand Down Expand Up @@ -411,21 +409,20 @@ private RelationalResultSet executePhysicalPlan(@Nonnull final RecordLayerSchema
final ResumableIterator<Row> iterator = RecordLayerIterator.create(cursor, messageFDBQueriedRecord -> new MessageTuple(messageFDBQueriedRecord.getMessage()));
return new RecordLayerResultSet(RelationalStructMetaData.of(dataType), iterator, connection,
(continuation, reason) -> enrichContinuation(continuation,
currentPlanHashMode, reason, OptionsUtils.getContinuationsContainsCompiledStatements(options)));
currentPlanHashMode, reason));
});
}

@Nonnull
private Continuation enrichContinuation(@Nonnull final Continuation continuation,
@Nonnull final PlanHashMode currentPlanHashMode,
@Nonnull final Continuation.Reason reason,
final boolean serializeCompiledStatement) throws RelationalException {
@Nonnull final Continuation.Reason reason) throws RelationalException {
final var continuationBuilder = ContinuationImpl.copyOf(continuation).asBuilder()
.withBindingHash(queryExecutionContext.getParameterHash())
.withPlanHash(planHashSupplier.get())
.withReason(reason);
// Do not send the serialized plan unless we can continue with this continuation.
if (serializeCompiledStatement && !continuation.atEnd()) {
if (!continuation.atEnd()) {
//
// Note that serialization and deserialization of the constituent elements have to done in the same order
// in order for the dictionary compression for type serialization to work properly. The order is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
package com.apple.foundationdb.relational.recordlayer;

import com.apple.foundationdb.relational.api.Continuation;
import com.apple.foundationdb.relational.api.Options;
import com.apple.foundationdb.relational.utils.ResultSetAssert;
import com.apple.foundationdb.relational.utils.SimpleDatabaseRule;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -54,7 +52,6 @@ public class JoinWithLimitTest {
@RegisterExtension
@Order(2)
public final RelationalConnectionRule connection = new RelationalConnectionRule(db::getConnectionUri)
.withOptions(Options.builder().withOption(Options.Name.CONTINUATIONS_CONTAIN_COMPILED_STATEMENTS, true).build())
.withSchema(db.getSchemaName());

@RegisterExtension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@
package com.apple.foundationdb.relational.recordlayer.query;

import com.apple.foundationdb.relational.api.Continuation;
import com.apple.foundationdb.relational.api.Options;
import com.apple.foundationdb.relational.api.RelationalConnection;
import com.apple.foundationdb.relational.api.RelationalPreparedStatement;
import com.apple.foundationdb.relational.api.RelationalResultSet;
import com.apple.foundationdb.relational.api.RelationalStatement;
import com.apple.foundationdb.relational.recordlayer.EmbeddedRelationalExtension;
import com.apple.foundationdb.relational.recordlayer.Utils;
import com.apple.foundationdb.relational.utils.Ddl;
import com.apple.foundationdb.relational.utils.ResultSetAssert;
import com.apple.foundationdb.relational.utils.RelationalStructAssert;

import com.apple.foundationdb.relational.utils.ResultSetAssert;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -117,47 +114,12 @@ void explainWithNoContinuationTest() throws Exception {
}
}

@Test
void explainWithContinuationNoSerializedPlanTest() throws Exception {
try (var ddl = Ddl.builder().database(URI.create("/TEST/QT")).relationalExtension(relationalExtension).schemaTemplate(schemaTemplate).build()) {
executeInsert(ddl);
Continuation continuation;
try (RelationalConnection conn = ddl.setSchemaAndGetConnection()) {
conn.setOption(Options.Name.CONTINUATIONS_CONTAIN_COMPILED_STATEMENTS, false);
try (RelationalPreparedStatement ps = conn.prepareStatement("SELECT * FROM RestaurantComplexRecord")) {
ps.setMaxRows(2);
continuation = consumeResultAndGetContinuation(ps, 2);
}
try (RelationalPreparedStatement ps = conn.prepareStatement("EXPLAIN SELECT * FROM RestaurantComplexRecord WITH CONTINUATION ?cont")) {
ps.setMaxRows(2);
ps.setObject("cont", continuation.serialize());
try (final RelationalResultSet resultSet = ps.executeQuery()) {
final var assertResult = ResultSetAssert.assertThat(resultSet);

assertResult.hasNextRow()
.hasColumn("PLAN", "ISCAN(RECORD_NAME_IDX <,>)")
.hasColumn("PLAN_HASH", -1635569052);
final var continuationInfo = resultSet.getStruct(5);
org.junit.jupiter.api.Assertions.assertNotNull(continuationInfo);
final var assertStruct = RelationalStructAssert.assertThat(continuationInfo);
assertStruct.hasValue("EXECUTION_STATE", new byte[]{0, 21, 1, 21, 11});
assertStruct.hasValue("VERSION", 1);
assertStruct.hasValue("PLAN_HASH_MODE", null);
assertStruct.hasValue("PLAN_HASH", -1635569052);
assertStruct.hasValue("SERIALIZED_PLAN_COMPLEXITY", null);
}
}
}
}
}

@Test
void explainWithContinuationSerializedPlanTest() throws Exception {
try (var ddl = Ddl.builder().database(URI.create("/TEST/QT")).relationalExtension(relationalExtension).schemaTemplate(schemaTemplate).build()) {
executeInsert(ddl);
Continuation continuation;
try (final var connection = ddl.setSchemaAndGetConnection()) {
connection.setOption(Options.Name.CONTINUATIONS_CONTAIN_COMPILED_STATEMENTS, true);
try (RelationalPreparedStatement ps = ddl.setSchemaAndGetConnection().prepareStatement("SELECT * FROM RestaurantComplexRecord")) {
ps.setMaxRows(2);
continuation = consumeResultAndGetContinuation(ps, 2);
Expand Down Expand Up @@ -190,7 +152,6 @@ void explainWithContinuationSerializedPlanWithDifferentQueryTest() throws Except
executeInsert(ddl);
Continuation continuation;
try (final var connection = ddl.setSchemaAndGetConnection()) {
connection.setOption(Options.Name.CONTINUATIONS_CONTAIN_COMPILED_STATEMENTS, true);
try (RelationalPreparedStatement ps = ddl.setSchemaAndGetConnection().prepareStatement("SELECT * FROM RestaurantComplexRecord")) {
ps.setMaxRows(2);
continuation = consumeResultAndGetContinuation(ps, 2);
Expand Down Expand Up @@ -223,7 +184,6 @@ void explainExecuteStatementTest() throws Exception {
executeInsert(ddl);
Continuation continuation;
try (final var connection = ddl.setSchemaAndGetConnection()) {
connection.setOption(Options.Name.CONTINUATIONS_CONTAIN_COMPILED_STATEMENTS, true);
try (RelationalPreparedStatement ps = ddl.setSchemaAndGetConnection().prepareStatement("SELECT * FROM RestaurantComplexRecord")) {
ps.setMaxRows(2);
continuation = consumeResultAndGetContinuation(ps, 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@
package com.apple.foundationdb.relational.recordlayer.query;

import com.apple.foundationdb.relational.api.Continuation;
import com.apple.foundationdb.relational.api.Options;
import com.apple.foundationdb.relational.api.exceptions.ContextualSQLException;
import com.apple.foundationdb.relational.recordlayer.EmbeddedRelationalExtension;
import com.apple.foundationdb.relational.recordlayer.RelationalConnectionRule;
import com.apple.foundationdb.relational.recordlayer.RelationalStatementRule;
import com.apple.foundationdb.relational.recordlayer.UniqueIndexTests;
import com.apple.foundationdb.relational.recordlayer.Utils;
import com.apple.foundationdb.relational.utils.SimpleDatabaseRule;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -40,7 +38,6 @@
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import java.sql.SQLException;
import java.util.stream.Stream;

public class ForceContinuationQueryTests {
Expand Down Expand Up @@ -75,14 +72,13 @@ public class ForceContinuationQueryTests {
@RegisterExtension
@Order(2)
public final RelationalConnectionRule connection = new RelationalConnectionRule(db::getConnectionUri)
.withOptions(Options.builder().withOption(Options.Name.CONTINUATIONS_CONTAIN_COMPILED_STATEMENTS, true).build())
.withSchema(db.getSchemaName());

@RegisterExtension
@Order(3)
public final RelationalStatementRule statement = new RelationalStatementRule(connection);

public ForceContinuationQueryTests() throws SQLException {
public ForceContinuationQueryTests() {
}

@BeforeAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ void groupByWithScanLimit() throws Exception {
try (var conn = ddl.setSchemaAndGetConnection()) {
Continuation continuation = null;
conn.setOption(Options.Name.EXECUTION_SCANNED_ROWS_LIMIT, 2);
conn.setOption(Options.Name.CONTINUATIONS_CONTAIN_COMPILED_STATEMENTS, true);
try (var statement = conn.createStatement()) {
insertT1Record(statement, 2, 1, 1, 20);
insertT1Record(statement, 3, 1, 2, 5);
Expand All @@ -82,7 +81,6 @@ void groupByWithScanLimit() throws Exception {
}
try (var preparedStatement = conn.prepareStatement("EXECUTE CONTINUATION ?param")) {
conn.setOption(Options.Name.EXECUTION_SCANNED_ROWS_LIMIT, 2);
conn.setOption(Options.Name.CONTINUATIONS_CONTAIN_COMPILED_STATEMENTS, true);
// scan pk = 5 and pk = 4 rows, hit SCAN_LIMIT_REACHED
preparedStatement.setBytes("param", continuation.serialize());
try (final RelationalResultSet resultSet = preparedStatement.executeQuery()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,11 @@ void preparedStatementWithExecuteContinuation() throws Exception {
executeInsert(ddl);
Continuation continuation;
try (final var connection = ddl.setSchemaAndGetConnection()) {
connection.setOption(Options.Name.CONTINUATIONS_CONTAIN_COMPILED_STATEMENTS, true);
try (var statement = connection.prepareStatement("SELECT * FROM RestaurantComplexRecord")) {
statement.setMaxRows(2);
continuation = assertResult(statement, 10L, 11L);
assertContinuation(continuation, false, false);
}
connection.setOption(Options.Name.CONTINUATIONS_CONTAIN_COMPILED_STATEMENTS, true);
try (var statement = connection.prepareStatement("EXECUTE CONTINUATION ?continuation")) {
statement.setMaxRows(2);
statement.setBytes("continuation", continuation.serialize());
Expand All @@ -120,35 +118,6 @@ void preparedStatementWithExecuteContinuation() throws Exception {
}
}

@Test
void preparedStatementWithExecuteContinuationWithOption() throws Exception {
try (var ddl = Ddl.builder().database(URI.create("/TEST/QT")).relationalExtension(relationalExtension).schemaTemplate(schemaTemplate).build()) {
executeInsert(ddl);
Continuation continuation;
try (final var connection = ddl.setSchemaAndGetConnection()) {
try (var statement =
connection.prepareStatement("SELECT * FROM RestaurantComplexRecord OPTIONS(CONTINUATION CONTAINS COMPILED STATEMENT)")) {
statement.setMaxRows(2);
continuation = assertResult(statement, 10L, 11L);
assertContinuation(continuation, false, false);
}

try (var statement =
connection.prepareStatement("EXECUTE CONTINUATION ?continuation OPTIONS(CONTINUATION CONTAINS COMPILED STATEMENT)")) {
statement.setMaxRows(2);
statement.setBytes("continuation", continuation.serialize());
continuation = assertResult(statement, 12L, 13L);
assertContinuation(continuation, false, false);

statement.setBytes("continuation", continuation.serialize());
continuation = assertResult(statement, 14L);
assertContinuation(continuation, false, true);
}

}
}
}

@Test
void preparedStatementWithLimit() throws Exception {
try (var ddl = Ddl.builder().database(URI.create("/TEST/QT")).relationalExtension(relationalExtension).schemaTemplate(schemaTemplate).build()) {
Expand Down
Loading
Loading