sql: rework VIEW internals
This patch significantly reworks VIEW mechanisms. Firstly, names resolution for VIEW now occurs during its creation. In other words, we can't run following code, since name T1 doesn't exist at the moment of V1 creation: CREATE VIEW v1 AS SELECT * FROM t1; CREATE TABLE t1(id PRIMARY KEY); Now, table t1 must be created before view. As a result, no circularly defined views are allowed. Moreover, it means that space representing view is created with appropriate field names, types, collations etc. Also, introduced view reference counter for each space. It is incremented for each space participating in select statement. For instace: CREATE VIEW v1 AS SELECT * FROM (SELECT * FROM t1, t2); In this case, view reference counter is increased for spaces T1 and T2. Similarly, such counter is decremented for all dependent spaces when VIEW is dropped. To support such behavior, auxiliary on_commit triggers are added. However, it is still not enough, since before dropping space itself, we must drop secondary indexes, clear _sequence space etc. Such changes can't be rollbacked (due to the lack of transactional DDL), so before executing DROP routine, special opcode OP_CheckViewReferences checks view reference counter for space to be dropped. Finally, we don't hold struct Select in struct Table or anywhere else anymore. Instead, 'CREATE VIEW AS SELECT ...' string is stored in def->opts.sql. At compilation time of query on view (such as 'SELECT * FROM v1;') this string is parsed once and loaded into struct Select, which in turn is used as before. Fixed tests where view was created prior to referenced table. Closes #3429, #3368, #3300
Showing
- src/box/alter.cc 150 additions, 0 deletionssrc/box/alter.cc
- src/box/space_def.c 1 addition, 0 deletionssrc/box/space_def.c
- src/box/space_def.h 2 additions, 0 deletionssrc/box/space_def.h
- src/box/sql.h 52 additions, 0 deletionssrc/box/sql.h
- src/box/sql/build.c 72 additions, 212 deletionssrc/box/sql/build.c
- src/box/sql/delete.c 3 additions, 3 deletionssrc/box/sql/delete.c
- src/box/sql/expr.c 2 additions, 3 deletionssrc/box/sql/expr.c
- src/box/sql/fkey.c 2 additions, 2 deletionssrc/box/sql/fkey.c
- src/box/sql/insert.c 4 additions, 3 deletionssrc/box/sql/insert.c
- src/box/sql/parse.y 11 additions, 8 deletionssrc/box/sql/parse.y
- src/box/sql/pragma.c 4 additions, 2 deletionssrc/box/sql/pragma.c
- src/box/sql/select.c 94 additions, 16 deletionssrc/box/sql/select.c
- src/box/sql/sqliteInt.h 45 additions, 13 deletionssrc/box/sql/sqliteInt.h
- src/box/sql/tokenize.c 21 additions, 2 deletionssrc/box/sql/tokenize.c
- src/box/sql/trigger.c 4 additions, 4 deletionssrc/box/sql/trigger.c
- src/box/sql/update.c 2 additions, 1 deletionsrc/box/sql/update.c
- src/box/sql/vdbe.c 24 additions, 0 deletionssrc/box/sql/vdbe.c
- test/sql-tap/colname.test.lua 2 additions, 2 deletionstest/sql-tap/colname.test.lua
- test/sql-tap/drop_all.test.lua 2 additions, 2 deletionstest/sql-tap/drop_all.test.lua
- test/sql-tap/fkey2.test.lua 1 addition, 0 deletionstest/sql-tap/fkey2.test.lua
Loading
Please register or sign in to comment