sql: change collation compatibility rules
Before this patch our SQL implementation relied on strange rules when comparing strings with different collations: - if either operand has an explicit collating function assignment using the postfix COLLATE operator, then the explicit collating function is used for comparison, with precedence to the collating function of the left operand; - if either operand is a column, then the collating function of that column is used with precedence to the left operand. The main concern in this implementation is that collation of the left operand is forced over right one (even if both operands come with explicit COLLATE clause). This contradicts ANSI SQL and seems to be quite misleading, since if user simple swap LHS and RHS - result of query may change. Lets introduce restrictions concerning collations compatibilities. Collations of LHS and RHS are compatible (i.e. no "Illegal mix of collations" is thrown) if: - one of collations is mentioned alongside with explicit COLLATE clause, which forces this collation over another one. It is allowed to have the same forced collations; - both collations are derived from table columns and they are the same; - one collation is derived from table column and another one is not specified (i.e. COLL_NONE). The compound SELECT operators UNION, INTERSECT and EXCEPT perform implicit comparisons between values. Hence, all new rules stated above are applied to parts of compound SELECT. Otherwise, an error is raised. In other words, before current patch queries like below were allowed: SELECT 'abc' COLLATE binary UNION SELECT 'ABC' COLLATE "unicode_ci"; --- - - ['ABC'] - ['abc'] ... If we swap collations, we will get another result: SELECT 'ABC' COLLATE "unicode_ci" UNION SELECT 'abc' COLLATE BINARY --- - - ['abc'] ... Now such queries are illegal. Closes #3185
Showing
- src/box/errcode.h 1 addition, 0 deletionssrc/box/errcode.h
- src/box/sql/expr.c 54 additions, 17 deletionssrc/box/sql/expr.c
- src/box/sql/select.c 59 additions, 46 deletionssrc/box/sql/select.c
- src/box/sql/sqliteInt.h 27 additions, 2 deletionssrc/box/sql/sqliteInt.h
- src/box/sql/where.c 6 additions, 7 deletionssrc/box/sql/where.c
- src/box/sql/whereexpr.c 7 additions, 6 deletionssrc/box/sql/whereexpr.c
- test/box/misc.result 1 addition, 0 deletionstest/box/misc.result
- test/sql-tap/e_select1.test.lua 5 additions, 7 deletionstest/sql-tap/e_select1.test.lua
- test/sql-tap/in4.test.lua 1 addition, 1 deletiontest/sql-tap/in4.test.lua
- test/sql-tap/join.test.lua 1 addition, 1 deletiontest/sql-tap/join.test.lua
- test/sql-tap/tkt3493.test.lua 2 additions, 2 deletionstest/sql-tap/tkt3493.test.lua
- test/sql-tap/transitive1.test.lua 2 additions, 2 deletionstest/sql-tap/transitive1.test.lua
- test/sql-tap/with1.test.lua 1 addition, 1 deletiontest/sql-tap/with1.test.lua
- test/sql/collation.result 63 additions, 0 deletionstest/sql/collation.result
- test/sql/collation.test.lua 22 additions, 0 deletionstest/sql/collation.test.lua
Loading
Please register or sign in to comment