Make sure SQL user-defined types are preserved in RecordMetadata - #4490
Make sure SQL user-defined types are preserved in RecordMetadata#4490hazefully wants to merge 2 commits into
Conversation
6a11fef to
1d7996b
Compare
6e66a64 to
34c7475
Compare
| @Override | ||
| public Value getValue() { | ||
| return LiteralValue.ofScalar(getComparand()); | ||
| return new LiteralValue<>(getComparand()); |
There was a problem hiding this comment.
This is necessary because the old planner generates SimpleComparisons where the inner value is an enum and not a scalar value, which now throws when getDynamicTypes is called on an index plan.
89794d9 to
2515688
Compare
2515688 to
9f3000c
Compare
📊 Metrics Diff Analysis ReportSummary
ℹ️ About this analysisThis automated analysis compares query planner metrics between the base branch and this PR. It categorizes changes into:
The last category in particular may indicate planner regressions that should be investigated. New QueriesCount of new queries by file:
Plan and Metrics ChangedThese queries experienced both plan and metrics changes. This generally indicates that there was some planner change Total: 6 queries Statistical Summary (Plan and Metrics Changed)
There were no queries with significant regressions detected. Minor Changes (Plan and Metrics Changed)In addition, there were 6 queries with minor changes. Only Metrics ChangedThese queries experienced only metrics changes without any plan changes. If these metrics have substantially changed, Total: 1 query Statistical Summary (Only Metrics Changed)
Significant Regressions (Only Metrics Changed)There was 1 outlier detected. Outlier queries have a significant regression in at least one field. Statistically, this represents either an increase of more than two standard deviations above the mean or a large absolute increase (e.g., 100).
|
This PR enhances the serialisation and deserialisation of a
RecordLayerSchemaTemplateto/from aRecordMetaDataby making sure that all user-defined SQL types (structs or enums) are preserved in theRecordMetadataand are available in the schema template when it is deserialised from theRecordMetaData.Before this PR, only types which were used in a table were added, as a protobuf message type, to the
FileDescriptorof theRecordMetaData. This means that if a user-defined type is only used as arguments of user-defined functions, or not used at all, it would not be preserved in the serialisedFileDescriptor, making it not possible to use in temporary functions or the SQL query as an existing type. In addition, as explained in #4177 and #4317, defining compiled SQL functions or temporary macro functions with user-defined types as parameters didn't work as the deserialised schema template didn't maintain a way to access these user-defined types by name.This PR fixes both problems, by making sure that all
auxiliaryTypesin aRecordLayerSchemaTemplateare added to theFileDescriptorof theRecordMetaDatawhether they are used in a table or not. In addition, it adds a new generated message type calledAuxiliaryTypeUnionthe serialisedFileDescriptor, which similar to the existingRecordTypeUnionmessage type provides a way to access these user-defined types by name in the deserialisedRecordMetaDataandRecordLayerSchemaTemplatewithout having to store the protobuf descriptor of the user-defined types more than once. The new generated typeAuxiliaryTypeUnionhas a field for each user-defined SQL type with the name of the user-defined type and the protobuf message type of the user-defined SQL type. This new message type is only added toRecordMetaDatas serialised from aRecordLayerSchemaTemplate.This PR also includes the following minor fixes:
RecordQueryIndexPlanor aRecordQueryCoveringIndexPlanin a continuation, where the index plan has comparisons which involve dynamic type, a runtime error would occur as the dynamic types were not added correctly to the type repository used for executing the continuation.RoutineParser.java, when we parse SQL functions included in the metadata as raw SQL queries, we assert in the code that the parsed function is a compiled SQL function. There is no technical reason for this restriction, and relaxing this assertion allows us to attach user-defined macro functions as raw SQL queries in the metadata.Resolves #4177, #4317.