sql: replace BLOB as column type with SCALAR
BLOB column type is represented by SCALAR field type in terms of NoSQL. We attempted at emulating BLOB behaviour, but such efforts turn out to be not decent enough. For this reason, we've decided to abandon these attempts and fairly replace it with SCALAR column type. SCALAR column type acts in the same way as it does in NoSQL: it is aggregator-type for INTEGER, NUMBER and STRING types. So, column declared with this type can contain values of these three (available in SQL) types. It is worth mentioning that CAST operator in this case does nothing. Still, we consider BLOB values as entries encoded in msgpack with MP_BIN format. To make this happen, values to be operated should be represented in BLOB form x'...' (e.g. x'000000'). What is more, there are two built-in functions returning BLOBs: randomblob() and zeroblob(). On the other hand, columns with STRING NoSQL type don't accept BLOB values. Closes #4019 Closes #4023 @TarantoolBot document Title: SQL types changes There are couple of recently introduced changes connected with SQL types. Firstly, we've removed support of DATE/TIME types from parser due to confusing behaviour of these types: they were mapped to NUMBER NoSQL type and have nothing in common with generally accepted DATE/TIME types (like in other DBs). In addition, all built-in functions related to these types (julianday(), date(), time(), datetime(), current_time(), current_date() etc) are disabled until we reimplement TIME-like types as a native NoSQL ones (see #3694 issue). Secondly, we've removed CHAR type (i.e. alias to VARCHAR and TEXT). The reason is that according to ANSI SQL CHAR(len) must accept only strings featuring length exactly equal to given in type definition. Obviously, now we don't provide such checks. Types VARCHAR and TEXT are still legal. For the same reason, we've removed NUMERIC and DECIMAL types, which were aliases to NUMBER NoSQL type. REAL, FLOAT and DOUBLE are still exist as aliases. Finally, we've renamed BLOB column type to SCALAR. We've decided that all our attempts to emulate BLOB behaviour using SCALAR NoSQL type don't seem decent enough, i.e. without native NoSQL type BLOB there always will be inconsistency, especially taking into account possible NoSQL-SQL interactions. In SQL SCALAR type works exactly in the same way as in NoSQL: it can store values of INTEGER, FLOAT and TEXT SQL types at the same time. Also, with this change behaviour of CAST operator has been slightly corrected: now cast to SCALAR doesn't affect type of value at all. Couple of examples: CREATE TABLE t1 (a SCALAR PRIMARY KEY); INSERT INTO t1 VALUES ('1'); SELECT * FROM t1 WHERE a = 1; -- [] Result is empty set since column "a" contains string literal value '1', not integer value 1. CAST(123 AS SCALAR); -- Returns 123 (integer) CAST('abc' AS SCALAR); -- Returns 'abc' (string) Note that in NoSQL values of BLOB type defined as ones decoded in msgpack with MP_BIN format. In SQL there are still a few ways to force this format: declaring literal in "BLOB" format (x'...') or using one of two built-in functions (randomblob() and zeroblob()). TEXT and VARCHAR SQL types don't accept BLOB values: CREATE TABLE t (a TEXT PRIMARAY KEY); INSERT INTO t VALUES (randomblob(5)); --- - error: 'Tuple field 1 type does not match one required: expected string' ... BLOB itself is going to be reimplemented in scope of #3650.
Showing
- extra/mkkeywordhash.c 2 additions, 1 deletionextra/mkkeywordhash.c
- src/box/sql/parse.y 1 addition, 1 deletionsrc/box/sql/parse.y
- src/box/sql/vdbe.c 0 additions, 2 deletionssrc/box/sql/vdbe.c
- src/box/sql/vdbemem.c 1 addition, 13 deletionssrc/box/sql/vdbemem.c
- test/sql-tap/analyze9.test.lua 1 addition, 1 deletiontest/sql-tap/analyze9.test.lua
- test/sql-tap/blob.test.lua 2 additions, 2 deletionstest/sql-tap/blob.test.lua
- test/sql-tap/boundary1.test.lua 1 addition, 1 deletiontest/sql-tap/boundary1.test.lua
- test/sql-tap/boundary3.test.lua 1 addition, 1 deletiontest/sql-tap/boundary3.test.lua
- test/sql-tap/cast.test.lua 15 additions, 15 deletionstest/sql-tap/cast.test.lua
- test/sql-tap/default.test.lua 1 addition, 1 deletiontest/sql-tap/default.test.lua
- test/sql-tap/delete4.test.lua 1 addition, 1 deletiontest/sql-tap/delete4.test.lua
- test/sql-tap/distinct.test.lua 3 additions, 8 deletionstest/sql-tap/distinct.test.lua
- test/sql-tap/e_expr.test.lua 6 additions, 8 deletionstest/sql-tap/e_expr.test.lua
- test/sql-tap/in3.test.lua 4 additions, 5 deletionstest/sql-tap/in3.test.lua
- test/sql-tap/index4.test.lua 2 additions, 2 deletionstest/sql-tap/index4.test.lua
- test/sql-tap/keyword1.test.lua 2 additions, 1 deletiontest/sql-tap/keyword1.test.lua
- test/sql-tap/substr.test.lua 1 addition, 1 deletiontest/sql-tap/substr.test.lua
- test/sql-tap/table.test.lua 8 additions, 8 deletionstest/sql-tap/table.test.lua
- test/sql-tap/tkt1443.test.lua 1 addition, 1 deletiontest/sql-tap/tkt1443.test.lua
- test/sql-tap/tkt1449.test.lua 7 additions, 7 deletionstest/sql-tap/tkt1449.test.lua
Loading
Please register or sign in to comment