Search in sources :

Example 36 with ExecuteProperties

use of com.apple.foundationdb.record.ExecuteProperties in project fdb-record-layer by FoundationDB.

the class RecordQuerySortPlan method executePlan.

@Nonnull
@Override
public <M extends Message> RecordCursor<QueryResult> executePlan(@Nonnull FDBRecordStoreBase<M> store, @Nonnull EvaluationContext context, @Nullable byte[] continuation, @Nonnull ExecuteProperties executeProperties) {
    // Since we are sorting, we need to feed through everything from the inner plan,
    // even just to get the top few.
    final ExecuteProperties executeInner = executeProperties.clearSkipAndLimit();
    final Function<byte[], RecordCursor<FDBQueriedRecord<M>>> innerCursor = innerContinuation -> getChild().executePlan(store, context, innerContinuation, executeInner).map(result -> result.<M>getQueriedRecord(0));
    final int skip = executeProperties.getSkip();
    final int limit = executeProperties.getReturnedRowLimitOrMax();
    final int maxRecordsToRead = limit == Integer.MAX_VALUE ? limit : skip + limit;
    final RecordQuerySortAdapter<M> adapter = key.getAdapter(store, maxRecordsToRead);
    final FDBStoreTimer timer = store.getTimer();
    final RecordCursor<FDBQueriedRecord<M>> sorted;
    if (adapter.isMemoryOnly()) {
        sorted = MemorySortCursor.create(adapter, innerCursor, timer, continuation).skipThenLimit(skip, limit);
    } else {
        sorted = FileSortCursor.create(adapter, innerCursor, timer, continuation, skip, limit);
    }
    return sorted.map(QueryResult::of);
}
Also used : Iterables(com.google.common.collect.Iterables) QueryResult(com.apple.foundationdb.record.query.plan.plans.QueryResult) StoreTimer(com.apple.foundationdb.record.provider.common.StoreTimer) Quantifier(com.apple.foundationdb.record.query.plan.temp.Quantifier) GroupExpressionRef(com.apple.foundationdb.record.query.plan.temp.GroupExpressionRef) RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) Function(java.util.function.Function) PlanHashable(com.apple.foundationdb.record.PlanHashable) RecordQueryPlanWithChild(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlanWithChild) ExecuteProperties(com.apple.foundationdb.record.ExecuteProperties) FileSortCursor(com.apple.foundationdb.record.sorting.FileSortCursor) ImmutableList(com.google.common.collect.ImmutableList) AliasMap(com.apple.foundationdb.record.query.plan.temp.AliasMap) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) FDBRecordStoreBase(com.apple.foundationdb.record.provider.foundationdb.FDBRecordStoreBase) ImmutableSet(com.google.common.collect.ImmutableSet) MemorySortCursor(com.apple.foundationdb.record.sorting.MemorySortCursor) FDBStoreTimer(com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer) Set(java.util.Set) QueriedValue(com.apple.foundationdb.record.query.predicates.QueriedValue) RelationalExpression(com.apple.foundationdb.record.query.plan.temp.RelationalExpression) Objects(java.util.Objects) Value(com.apple.foundationdb.record.query.predicates.Value) List(java.util.List) CorrelationIdentifier(com.apple.foundationdb.record.query.plan.temp.CorrelationIdentifier) EvaluationContext(com.apple.foundationdb.record.EvaluationContext) ObjectPlanHash(com.apple.foundationdb.record.ObjectPlanHash) FDBQueriedRecord(com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord) Message(com.google.protobuf.Message) RecordCursor(com.apple.foundationdb.record.RecordCursor) API(com.apple.foundationdb.annotation.API) PlannerGraph(com.apple.foundationdb.record.query.plan.temp.explain.PlannerGraph) NodeInfo(com.apple.foundationdb.record.query.plan.temp.explain.NodeInfo) AvailableFields(com.apple.foundationdb.record.query.plan.AvailableFields) ExecuteProperties(com.apple.foundationdb.record.ExecuteProperties) QueryResult(com.apple.foundationdb.record.query.plan.plans.QueryResult) RecordCursor(com.apple.foundationdb.record.RecordCursor) FDBQueriedRecord(com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord) FDBStoreTimer(com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer) Nonnull(javax.annotation.Nonnull)

Example 37 with ExecuteProperties

use of com.apple.foundationdb.record.ExecuteProperties in project fdb-record-layer by FoundationDB.

the class JoinedRecordPlan method execute.

@Override
@Nonnull
public <M extends Message> RecordCursor<FDBSyntheticRecord> execute(@Nonnull FDBRecordStore store, @Nonnull FDBStoredRecord<M> record, @Nullable byte[] continuation, @Nonnull ExecuteProperties executeProperties) {
    final EvaluationContext context = joinedTypes.get(0).bind(EvaluationContext.EMPTY, record);
    final RecordCursor<EvaluationContext> joinedContexts;
    if (queries.size() == 1) {
        joinedContexts = query(0, store, context, continuation, executeProperties);
    } else {
        final ExecuteProperties baseProperties = executeProperties.clearSkipAndLimit();
        joinedContexts = nest(0, store.getPipelineSize(PipelineOperation.SYNTHETIC_RECORD_JOIN), store, context, continuation, baseProperties).skipThenLimit(executeProperties.getSkip(), executeProperties.getReturnedRowLimit());
    }
    return joinedContexts.map(this::toSyntheticRecord);
}
Also used : ExecuteProperties(com.apple.foundationdb.record.ExecuteProperties) EvaluationContext(com.apple.foundationdb.record.EvaluationContext) Nonnull(javax.annotation.Nonnull)

Example 38 with ExecuteProperties

use of com.apple.foundationdb.record.ExecuteProperties in project fdb-record-layer by FoundationDB.

the class SyntheticRecordScanPlan method execute.

@Override
@Nonnull
public RecordCursor<FDBSyntheticRecord> execute(@Nonnull FDBRecordStore store, @Nullable byte[] continuation, @Nonnull ExecuteProperties executeProperties) {
    final ExecuteProperties baseProperties = executeProperties.clearSkipAndLimit();
    RecordCursor<FDBSyntheticRecord> cursor = RecordCursor.flatMapPipelined(outerContinuation -> store.executeQuery(recordPlan, outerContinuation, baseProperties), (queriedRecord, innerContinuation) -> syntheticRecordPlan.execute(store, queriedRecord.getStoredRecord(), innerContinuation, baseProperties), continuation, store.getPipelineSize(PipelineOperation.SYNTHETIC_RECORD_JOIN));
    if (needDistinct) {
        cursor = SyntheticRecordConcatPlan.addDistinct(cursor);
    }
    cursor = cursor.skipThenLimit(executeProperties.getSkip(), executeProperties.getReturnedRowLimit());
    return cursor;
}
Also used : ExecuteProperties(com.apple.foundationdb.record.ExecuteProperties) FDBSyntheticRecord(com.apple.foundationdb.record.provider.foundationdb.FDBSyntheticRecord) Nonnull(javax.annotation.Nonnull)

Aggregations

ExecuteProperties (com.apple.foundationdb.record.ExecuteProperties)38 Nonnull (javax.annotation.Nonnull)29 Message (com.google.protobuf.Message)23 RecordCursor (com.apple.foundationdb.record.RecordCursor)20 ScanProperties (com.apple.foundationdb.record.ScanProperties)18 List (java.util.List)17 Index (com.apple.foundationdb.record.metadata.Index)15 FDBQueriedRecord (com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord)15 FDBRecordContext (com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext)15 RecordQueryPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan)15 RecordCursorResult (com.apple.foundationdb.record.RecordCursorResult)14 Function (java.util.function.Function)14 Nullable (javax.annotation.Nullable)13 API (com.apple.foundationdb.annotation.API)12 EvaluationContext (com.apple.foundationdb.record.EvaluationContext)12 Tuple (com.apple.foundationdb.tuple.Tuple)12 IsolationLevel (com.apple.foundationdb.record.IsolationLevel)11 TupleRange (com.apple.foundationdb.record.TupleRange)11 ArrayList (java.util.ArrayList)11 Collections (java.util.Collections)10