sql: extend result set with span
Each column of result set features its name span (in full metadata mode). For instance: SELECT x + 1 AS add FROM ...; In this case real name (span) of resulting set column is "x + 1" meanwhile "add" is its alias. This patch extends metadata with member which corresponds to column's original expression. It is worth mentioning that in most cases span coincides with name, so to avoid overhead and sending the same string twice, we follow the rule that if span is encoded as MP_NIL then its value is the same as name. Also note that span is always presented in full metadata mode. Closes #4407 @TarantoolBot document Title: extended SQL metadata Before this patch metadata for SQL DQL contained only two fields: name and type of each column of result set. Now it may contain following properties: - collation (in case type of resulting set column is string and collation is different from default "none"); is encoded with IPROTO_FIELD_COLL (0x2) key in IPROTO_METADATA map; in msgpack is encoded as string and held with MP_STR type; - is_nullable (in case column of result set corresponds to space's field; for expressions like x+1 for the sake of simplicity nullability is omitted); is encoded with IPROTO_FIELD_IS_NULLABLE key (0x3) in IPROTO_METADATA; in msgpack is encoded as boolean and held with MP_BOOL type; note that absence of this field implies that nullability is unknown; - is_autoincrement (is set only for autoincrement column in result set); is encoded with IPROTO_FIELD_IS_AUNTOINCREMENT (0x4) key in IPROTO_METADATA; in msgpack is encoded as boolean and held with MP_BOOL type; - span (is always set in full metadata mode; it is an original expression forming result set column. For instance: SELECT a + 1 AS x; -- x is a name, meanwhile a + 1 is a span); is encoded with IPROTO_FIELD_SPAN (0x5) key in IPROTO_METADATA map; in msgpack is encoded as string and held with MP_STR type OR as NIL with MP_NIL type. The latter case indicates that span coincides with name. This simple optimization allows to avoid sending the same string twice. This extended metadata is send only when PRAGMA full_metadata is enabled. Otherwise, only basic (name and type) metadata is processed.
Showing
- src/box/execute.c 29 additions, 5 deletionssrc/box/execute.c
- src/box/iproto_constants.h 1 addition, 0 deletionssrc/box/iproto_constants.h
- src/box/lua/execute.c 10 additions, 1 deletionsrc/box/lua/execute.c
- src/box/lua/net_box.c 26 additions, 8 deletionssrc/box/lua/net_box.c
- src/box/sql/select.c 13 additions, 9 deletionssrc/box/sql/select.c
- src/box/sql/sqlInt.h 6 additions, 0 deletionssrc/box/sql/sqlInt.h
- src/box/sql/vdbe.h 3 additions, 0 deletionssrc/box/sql/vdbe.h
- src/box/sql/vdbeInt.h 6 additions, 0 deletionssrc/box/sql/vdbeInt.h
- src/box/sql/vdbeapi.c 15 additions, 0 deletionssrc/box/sql/vdbeapi.c
- src/box/sql/vdbeaux.c 19 additions, 0 deletionssrc/box/sql/vdbeaux.c
- test/sql/full_metadata.result 94 additions, 5 deletionstest/sql/full_metadata.result
- test/sql/full_metadata.test.lua 11 additions, 0 deletionstest/sql/full_metadata.test.lua
Loading
Please register or sign in to comment