-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Temporary tables #2962
Temporary tables #2962
Conversation
- rework continuation semantics and add few continuation tests.
- new implementation of RecursiveUnorderedUnionCursor, incomplete, requires testing. - new implementation of RecordQueryRecursiveUnorderedUnionPlan, incomplete, requires testing. - new implementation of DoubleBufferCursor, requires more testing.
@@ -44,17 +44,18 @@ public class Bindings { | |||
/** | |||
* Bindings slots used internally by plan operators. | |||
*/ | |||
public enum Internal { | |||
public enum BindingType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that Internal
is too short for what is now a fairly wide variety of special bindings. But BindingType
suggests to me that all bindings would be of one of these types, when these are still just the special ones and normally named parameters aren't one of these types. Also, the serialized enum is PBindingKind
. It seems that perhaps a longer consistent name is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only bindings that do not have an Internal
are named bindings coming from the heuristic planner. I think everything in the cascades planner actually has a corresponding Internal
(mostly CORRELATION
or CONSTANT
so far).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the newly added enum value TABLE_QUEUE
effectively reverting the change, but I renamed Internal
to BindingKind
(not BindingType
) to align with the corresponding PB definition in record_query_plan.proto
:
enum PBindingKind { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although one might prefer to build a ConstantObjectValue
and/or CONSTANT
binding, from some higher level query data structure, it works today to call CascadesPlanner
with a RecordQuery
containing a ParameterComparison
and run that plan with an EvaluationContext
with a Bindings
with a corresponding named parameter. In other words, an external binding kind. These untyped / neutral bindings are not specific to the heuristic planner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reverted the name back to how it was before. It looks like introducing an External
binding could cause wider code changes that are outside the scope of this PR. Let's discuss this as a follow up item.
@SuppressWarnings("unchecked") | ||
@Nonnull | ||
public RecordCursor<QueryResult> getReadCursor(@Nullable byte[] continuation) { | ||
return new ListCursor<>((List<QueryResult>)getReadBuffer(), continuation); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this exhausts, it does not work to have one part of the plan filling and another part emptying. One must, I think, do all the add
s and then getReadCursor
to process the queue. Does that mean that the table queue itself ought to have a mode for which direction it is currently handling and callers must set that explicitly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is intended to be used such that there are no interleaving reads and writes, to address that, the consumer must make sure that these accesses are synchronised correctly e.g. by means of read-write lock, otherwise it would might break any expected continuation semantics imposed by the consumer.
03e4c8d
to
ff3e1ce
Compare
- Massive renaming, now we have `TempTableScanExpression`, `TempTableInsertExpression`, respective `TempTableInsertPlan`, and `TempTableScanPlan`, PB names are also consistent with that. - Moved `PEnumLightValue`, `PUUID`, `PFDBRecordVersion`, `PComparableObject`, `PQueryResult`, and `PTempTable` to `record_metadata.proto` since these are runtime objects. Removed the name from `TempTable`. Use `Value` to “refer” to a `TempTable` in the `EvaluationContext` instead of a plain `CorrelationIdentifier`, in all `TempTableScanExpression`, `TempTableInsertExpression`, respective `TempTableInsertPlan`, and `TempTableScanPlan`. Made the expressions’ constructors private and added two factory methods that enable the customer to create an expression using a constant binding, or a correlated binding. - Fixed the `translateCorrelations` implementations in `UpdateExpression`, `InsertExpression`, and `DeleteExpression`. Now it rebuilds the expression using the correct translated inner.
...er-core/src/main/java/com/apple/foundationdb/record/query/plan/PlanStringRepresentation.java
Outdated
Show resolved
Hide resolved
...d-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/TableQueue.java
Outdated
Show resolved
Hide resolved
...n/java/com/apple/foundationdb/record/query/plan/cascades/expressions/TqInsertExpression.java
Outdated
Show resolved
Hide resolved
...ain/java/com/apple/foundationdb/record/query/plan/cascades/expressions/TqScanExpression.java
Outdated
Show resolved
Hide resolved
...va/com/apple/foundationdb/record/query/plan/cascades/properties/DistinctRecordsProperty.java
Show resolved
Hide resolved
...r-core/src/main/java/com/apple/foundationdb/record/query/plan/plans/TempTableInsertPlan.java
Outdated
Show resolved
Hide resolved
...r-core/src/main/java/com/apple/foundationdb/record/query/plan/plans/TempTableInsertPlan.java
Outdated
Show resolved
Hide resolved
...com/apple/foundationdb/record/query/plan/cascades/expressions/TempTableInsertExpression.java
Outdated
Show resolved
Hide resolved
...com/apple/foundationdb/record/query/plan/cascades/expressions/TempTableInsertExpression.java
Outdated
Show resolved
Hide resolved
...com/apple/foundationdb/record/query/plan/cascades/expressions/TempTableInsertExpression.java
Outdated
Show resolved
Hide resolved
fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/EvaluationContext.java
Outdated
Show resolved
Hide resolved
...rd-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/TempTable.java
Show resolved
Hide resolved
...foundationdb/record/query/plan/cascades/matching/structure/RelationalExpressionMatchers.java
Outdated
Show resolved
Hide resolved
...va/com/apple/foundationdb/record/query/plan/cascades/properties/DistinctRecordsProperty.java
Show resolved
Hide resolved
...main/java/com/apple/foundationdb/record/query/plan/cascades/properties/OrderingProperty.java
Outdated
Show resolved
Hide resolved
...r-core/src/main/java/com/apple/foundationdb/record/query/plan/plans/TempTableInsertPlan.java
Outdated
Show resolved
Hide resolved
...r-core/src/main/java/com/apple/foundationdb/record/query/plan/plans/TempTableInsertPlan.java
Outdated
Show resolved
Hide resolved
...yer-core/src/main/java/com/apple/foundationdb/record/query/plan/plans/TempTableScanPlan.java
Outdated
Show resolved
Hide resolved
...main/java/com/apple/foundationdb/record/query/plan/cascades/properties/OrderingProperty.java
Outdated
Show resolved
Hide resolved
Result of fdb-record-layer-pr on Linux CentOS 7
|
This introduces temporary tables planning and execution. A temporary table is an in-memory buffer that holds a list of
QueryResult
objects.They offer means for storing temporary computation results, and can be leveraged to serve as SQL temporary tables in the future. The following APIs are introduced:
TempTable
, this wraps aQueue
ofQueryResult
objects, it is mutable, and in its current version, not thread-safe.a.
TableValuedCorrelationScanExpression
enables scanning from a table-valued correlation, such as aTempTable
.b.
TempTableInsertExpression
enables inserting into aTempTable
.TableValuedCorrelationScanPlan
andTempTableInsertPlan
.Few tests are added to illustrate the planning capabilities and execution correctness over temporary tables.
Few extra details:
QueryResult
.TempTable
can currently serialize its state, i.e. the underlying queue elements.Few examples:
Inserting into a temp table:
the logical plan looks like this:
while the physical plan looks like this:
Selecting from a temp table: the following is a logical plan representing a join between two named temp tables:
and the physical NLJ implementation of the join:
This solves #2961