From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 353C02637C for ; Thu, 14 Jun 2018 13:32:43 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id URpPWPS29wnt for ; Thu, 14 Jun 2018 13:32:43 -0400 (EDT) Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id C11E226378 for ; Thu, 14 Jun 2018 13:32:42 -0400 (EDT) From: Kirill Shcherbatov Subject: [tarantool-patches] [PATCH v3 08/10] sql: new _trigger space format with space_id Date: Thu, 14 Jun 2018 20:32:26 +0300 Message-Id: In-Reply-To: References: In-Reply-To: References: Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: v.shpilevoy@tarantool.org, Kirill Shcherbatov As we would like to lookup triggers by space_id in future on space deletion to delete associated _trigger tuples we need to introduce new field space_id as secondary key. Part of #3273. --- src/box/bootstrap.snap | Bin 1698 -> 1704 bytes src/box/lua/upgrade.lua | 4 +++ src/box/schema_def.h | 6 ++++ src/box/sql.c | 21 +++++++----- src/box/sql/sqliteInt.h | 2 ++ src/box/sql/trigger.c | 8 +++-- test/app-tap/tarantoolctl.test.lua | 2 +- test/box-py/bootstrap.result | 5 +-- test/box/access_misc.result | 4 +-- test/box/access_sysview.result | 4 +-- test/box/alter.result | 1 + test/sql/gh2141-delete-trigger-drop-table.result | 4 +-- test/sql/gh2141-delete-trigger-drop-table.test.lua | 4 +-- test/sql/persistency.result | 8 ++--- test/sql/persistency.test.lua | 8 ++--- test/sql/upgrade.result | 37 ++++++++++++++++++--- test/sql/upgrade.test.lua | 9 ++++- 17 files changed, 91 insertions(+), 36 deletions(-) diff --git a/src/box/bootstrap.snap b/src/box/bootstrap.snap index d271dca7bc6030f6a05c28c6385ed01a0a02f700..a8a00ec29e7106afbd06294cf6ffe291f90a2e10 100644 GIT binary patch delta 1694 zcmV;P24VT44X6!}9)B}5W;ZrBISNT`b97;DV`VxZVq`I4G%`73EjBVRG%YkYH!&?Z zW-vD`GG;kpI50CYF*i6k3RXjGZ)0mZAbWiZ3e~y`y3GbK0M4rK@!O>U00000D77#B z08l+K04hVU4oT1$Hvs@&JireJkQ`J#QC_IkDFq@CiO~a`bblj$ELmxPvu%zAcout22V@@+qYh(*Vl=;{f7}eD(eMXFOG}!_0MA zQ{^T>M0(5}i{c1=M)gI&wbZ2YVhW35sXv~Nz7(Qnnjr8NZ}$@ zUp0bRm$XW>z1(Z5NvqXk=KEc=B-c_isUoTJ2ZUR*dM!1-%QT>m+wMGHamSAJ@%rPRMSLyuCDh+}quFt5>9Ozi}J*gB7TuV)jUmVAj z2)>>LVt?@L8+U#JVVzsC{o!|=Y2? znnE=dk;V@$}Q!}%H#W9P52AK>p7-TNQScutTXsm^)P+>w-D$EQFg<4-^ zuBGP71PT+P@}*DK<;=+c?lS69k%%@L3D;6{V-bU73-g&u)G?peF(Oltn9gNDsvHwj zJ%849-1#T^@Xx3Mfl+`V1LBw zxYGG%KQC`?fW}mmT8Fk87Xe^M0)a@V;aFr43CsWhfB+}}@dXDd=ZXdrfUr1v{|TchhZB_P^);=ymZ zIl7E^Uvlc<%`Fj-7xknjySbbQ4f!DO#f(gG#AT(F2pzK&f)RTwwyKFODV_57>)62c zcU8a_L{GIZbY%Pz#>pe6#^}gK1ydGiF#eR)Gjp;Gt+E+g;bR)c>^vjr(tmsM89goz z1A&B6?YN%{OOg{CnHyC3+<)`5__2GC1PwVg^uSGQF#eR)Gjp;GO~6}!wtV)haNl!i zV3weV8pz9g_D>aT=wIklyeHtL&G749Jsmxug;UC;VbMR~u&zFKv>o>O!QR-KmFgwy z50A^=RP+dFcJSHQk?!c?`F}z%LBKyYQbqk3bpDiyd|?vZ^C0TiDxbUXm?dxrK1*3vmvJgznO%+@MU9 z&FbjovR)z~e@Aib@JDa0jX`Rx;muN>Oq+mTOc!e{6IVo}y#OjS&VNwbdcc{Hozr7r zK=WtO9rs}jIa>?olPm@&{Ada=x%f*h`1(JWoBLv1#B$^hO@mwpbE8P oJi~Ha`5lx^HFfBzk{A9#Sl5<&4hy7?2*p>)dXg|iIn@xY?G8vRL;wH) delta 1688 zcmV;J250%G4WbQ@9)CA7F*0H`F*r5~Np5p=VQyn(Iv{3aVKy^mG-EAfIAUZiG-EX~ zEn+h@W-VnnF)%n{F)}n_H#iDbLu_wjYdRo%F*+bHeF_TIx(m9^1|tB@X~^8mr2qf` z001bpFZ}>e)i411LZl8!&{$0YfIW;-52I0K5Pk_XKqcbbL4TXX{Q$^sCLS?$}HOBd`M$VQ%~lv2_F$pGX4H4)bLYoM_F zUb8aSl6^=P9+oQt(}l9N^)X1@PrGh*u`lPJ=cyP)f;QClZ@Z*){1>T_(q9F%FL zljE6A_=ID!QT@tvJ?z<_R2T!6{hf~>w#B#>I;WKup?@S7vOr0qa)qY~fI5W&d5bCs zwodX{59U|iVo}%e2l2wA|FG-3S+-Z+Vpq~s1KEB)q8QjZ$yOh)Y(F2nlAc+XGCKT^!s&9CbvsZc4D&MD^v;)FwULt`^UgPJ+b ze6V$rLo+p;DaLt_=@66Q5JM9)6SJYkZ;OHkm<%u&U@p8^c;Q}TYAscuu^}n66jP!= zsSAv)lXRIdV?$GZ{KY8LHpTJMf2hM)XJN`+oQ9XLUR?IV$3W`b4mGlCgfV9(V7GXb%KiC&^;v-MbrY z@xazejJrfK>QF zeeBpCwTFjl2TBJ`4h~0*4}G~|>m;iSMSm)*4XVT3u^v~qN@ZNCMp9Ce6-vX_NtWjG z{jaRY+YDPL37}3Y<5DvAiz6>-g%~)4;_oABVLTXa8qT0MiZxng-06kRuJ4wV_SiZ} z60B8AgmIAP#R}Y^Mvn)A$>=BX1<=1*uPCV7;wJI7a1oLHe57^$BderS#+_W)I)6zX z957}yT zC6gNKVl4^83lbp=-T(O3#iSJ3$A7HF$X~Uh;uz#)u2r8lgl6Wrk2@AyOZRCSK~7uM z8$U_)nFHdHKZX;08u1@rJKYX)NY>k3oEKG_B~q0v=#;`(!Pa9YNfM{b`_(mY`A-$} z1<~_Xf*rb*hH+Bl7BE_-QC}nl4hTGikVQF_`iE$e&_$E6`_1|3L&1_U0$aafELfe;}4pUpXYH+svoBAh#P z@dgrmFJqZ*`1%)yE8f3x#FG1UA^0m+L$`uR>aa-u*&eP2ar7N_#ALTfgH?K#gg?kF ze^a3!qGf?*Vh-wjTpt$XLw|CdekL=j`lI~c`SthmqPlZpGpu>+RNndo^%05{*RnB2 zFO7q%8RNhP&=_jtJYg6`dMQfI(FYbO;yfkH?`|Oo{6Yv#k>qY&%Nvw|f>|B8+~_3| zhVLkk4}WCVS{_LK8r}@$lW7Cs#dNOLFma;t)C)|ZaU8W>2Amn$Ie$I|1{9wb-EsNF zklWfhpY&pIktb6C&Bb?W!Of5Q9&w?5gxQ?FWDwKz$4GP=9`2|!!?sp>C6rqRrY5g= zslUN<5+2!(#TS%Lizk_JmHd$KZ`E$DKmVEmQD)}$P@7gzU^wj80=lYQ(=+Yk+TKB% itF48e>+~O}byP9oun~gm$Q^t|sV4~omjl%ht?dd`FccL4 diff --git a/src/box/lua/upgrade.lua b/src/box/lua/upgrade.lua index 7258f47..f112a93 100644 --- a/src/box/lua/upgrade.lua +++ b/src/box/lua/upgrade.lua @@ -471,12 +471,16 @@ local function upgrade_to_2_1_0() log.info("create space _trigger") local format = {{name='name', type='string'}, + {name='space_id', type='unsigned'}, {name='opts', type='map'}} _space:insert{_trigger.id, ADMIN, '_trigger', 'memtx', 0, MAP, format} log.info("create index primary on _trigger") _index:insert{_trigger.id, 0, 'primary', 'tree', { unique = true }, {{0, 'string'}}} + log.info("create index secondary on _trigger") + _index:insert{_trigger.id, 1, 'space_id', 'tree', { unique = false }, + {{1, 'unsigned'}}} local stat1_ft = {{name='tbl', type='string'}, {name='idx', type='string'}, diff --git a/src/box/schema_def.h b/src/box/schema_def.h index eb07332..9b003c4 100644 --- a/src/box/schema_def.h +++ b/src/box/schema_def.h @@ -217,6 +217,12 @@ enum { BOX_SPACE_SEQUENCE_FIELD_IS_GENERATED = 2, }; +enum { + BOX_TRIGGER_FIELD_NAME = 0, + BOX_TRIGGER_FIELD_SPACE_ID = 1, + BOX_TRIGGER_FIELD_OPTS = 2, +}; + /* * Different objects which can be subject to access * control. diff --git a/src/box/sql.c b/src/box/sql.c index d18f379..564e5bf 100644 --- a/src/box/sql.c +++ b/src/box/sql.c @@ -669,8 +669,11 @@ int tarantoolSqlite3RenameTrigger(const char *trig_name, if (box_index_get(BOX_TRIGGER_ID, 0, key_begin, key, &tuple) != 0) return SQL_TARANTOOL_ERROR; assert(tuple != NULL); - assert(tuple_field_count(tuple) == 2); - const char *field = box_tuple_field(tuple, 1); + assert(tuple_field_count(tuple) == 3); + const char *field = box_tuple_field(tuple, BOX_TRIGGER_FIELD_SPACE_ID); + assert(mp_typeof(*field) == MP_UINT); + uint32_t space_id = mp_decode_uint(&field); + field = box_tuple_field(tuple, BOX_TRIGGER_FIELD_OPTS); assert(mp_typeof(*field) == MP_MAP); mp_decode_map(&field); const char *sql_str = mp_decode_str(&field, &key_len); @@ -693,16 +696,18 @@ int tarantoolSqlite3RenameTrigger(const char *trig_name, uint32_t trigger_stmt_new_len = trigger_stmt_len + new_table_name_len - old_table_name_len + 2 * (!is_quoted); assert(trigger_stmt_new_len > 0); - key_len = mp_sizeof_array(2) + mp_sizeof_str(trig_name_len) + + key_len = mp_sizeof_array(3) + mp_sizeof_str(trig_name_len) + mp_sizeof_map(1) + mp_sizeof_str(3) + - mp_sizeof_str(trigger_stmt_new_len); + mp_sizeof_str(trigger_stmt_new_len) + + mp_sizeof_uint(space_id); char *new_tuple = (char*)region_alloc(&fiber()->gc, key_len); if (new_tuple == NULL) { diag_set(OutOfMemory, key_len, "region_alloc", "new_tuple"); return SQL_TARANTOOL_ERROR; } - char *new_tuple_end = mp_encode_array(new_tuple, 2); + char *new_tuple_end = mp_encode_array(new_tuple, 3); new_tuple_end = mp_encode_str(new_tuple_end, trig_name, trig_name_len); + new_tuple_end = mp_encode_uint(new_tuple_end, space_id); new_tuple_end = mp_encode_map(new_tuple_end, 1); new_tuple_end = mp_encode_str(new_tuple_end, "sql", 3); new_tuple_end = mp_encode_str(new_tuple_end, trigger_stmt, @@ -1253,7 +1258,7 @@ void tarantoolSqlite3LoadSchema(InitData *init) init, TARANTOOL_SYS_TRIGGER_NAME, BOX_TRIGGER_ID, 0, "CREATE TABLE \""TARANTOOL_SYS_TRIGGER_NAME"\" (" - "\"name\" TEXT PRIMARY KEY, \"opts\")" + "\"name\" TEXT PRIMARY KEY, \"space_id\" INT, \"opts\")" ); sql_schema_put( @@ -1308,14 +1313,14 @@ void tarantoolSqlite3LoadSchema(InitData *init) const char *field, *ptr; char *name, *sql; unsigned len; - assert(tuple_field_count(tuple) == 2); + assert(tuple_field_count(tuple) == 3); field = tuple_field(tuple, 0); assert (field != NULL); ptr = mp_decode_str(&field, &len); name = strndup(ptr, len); - field = tuple_field(tuple, 1); + field = tuple_field(tuple, BOX_TRIGGER_FIELD_OPTS); assert (field != NULL); mp_decode_array(&field); ptr = mp_decode_str(&field, &len); diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h index ecbd573..19f5b86 100644 --- a/src/box/sql/sqliteInt.h +++ b/src/box/sql/sqliteInt.h @@ -3032,6 +3032,8 @@ struct Parse { */ struct Trigger { char *zName; /* The name of the trigger */ + /** The ID of space the trigger refers to. */ + uint32_t space_id; char *table; /* The table or view to which the trigger applies */ u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT */ u8 tr_tm; /* One of TRIGGER_BEFORE, TRIGGER_AFTER */ diff --git a/src/box/sql/trigger.c b/src/box/sql/trigger.c index 84ea8db..b83c096 100644 --- a/src/box/sql/trigger.c +++ b/src/box/sql/trigger.c @@ -169,6 +169,7 @@ sqlite3BeginTrigger(Parse * pParse, /* The parse context of the CREATE TRIGGER s if (pTrigger == 0) goto trigger_cleanup; pTrigger->zName = zName; + pTrigger->space_id = pTab->def->id; zName = 0; pTrigger->table = sqlite3DbStrDup(db, pTableName->a[0].zName); pTrigger->pSchema = db->pSchema; @@ -255,7 +256,7 @@ sqlite3FinishTrigger(Parse * pParse, /* Parser context */ /* makerecord(cursor(iRecord), [reg(iFirstCol), reg(iFirstCol+1)]) */ iFirstCol = pParse->nMem + 1; - pParse->nMem += 2; + pParse->nMem += 3; iRecord = ++pParse->nMem; zOpts = sqlite3DbMallocRaw(pParse->db, @@ -275,9 +276,10 @@ sqlite3FinishTrigger(Parse * pParse, /* Parser context */ sqlite3VdbeAddOp4(v, OP_String8, 0, iFirstCol, 0, zName, P4_DYNAMIC); - sqlite3VdbeAddOp4(v, OP_Blob, zOptsSz, iFirstCol + 1, + sqlite3VdbeAddOp2(v, OP_Integer, pTrig->space_id, iFirstCol + 1); + sqlite3VdbeAddOp4(v, OP_Blob, zOptsSz, iFirstCol + 2, MSGPACK_SUBTYPE, zOpts, P4_DYNAMIC); - sqlite3VdbeAddOp3(v, OP_MakeRecord, iFirstCol, 2, iRecord); + sqlite3VdbeAddOp3(v, OP_MakeRecord, iFirstCol, 3, iRecord); sqlite3VdbeAddOp2(v, OP_IdxInsert, iCursor, iRecord); /* Do not account nested operations: the count of such * operations depends on Tarantool data dictionary internals, diff --git a/test/app-tap/tarantoolctl.test.lua b/test/app-tap/tarantoolctl.test.lua index cee9164..02ef5ea 100755 --- a/test/app-tap/tarantoolctl.test.lua +++ b/test/app-tap/tarantoolctl.test.lua @@ -339,7 +339,7 @@ do check_ctlcat_xlog(test_i, dir, "--from=3 --to=6 --format=json --show-system --replica 1 --replica 2", "\n", 3) check_ctlcat_xlog(test_i, dir, "--from=3 --to=6 --format=json --show-system --replica 2", "\n", 0) check_ctlcat_snap(test_i, dir, "--space=280", "---\n", 21) - check_ctlcat_snap(test_i, dir, "--space=288", "---\n", 46) + check_ctlcat_snap(test_i, dir, "--space=288", "---\n", 47) end) end) diff --git a/test/box-py/bootstrap.result b/test/box-py/bootstrap.result index ad9501b..b5c16c0 100644 --- a/test/box-py/bootstrap.result +++ b/test/box-py/bootstrap.result @@ -65,8 +65,8 @@ box.space._space:select{} {'name': 'object_id', 'type': 'unsigned'}, {'name': 'privilege', 'type': 'unsigned'}]] - [320, 1, '_cluster', 'memtx', 0, {}, [{'name': 'id', 'type': 'unsigned'}, {'name': 'uuid', 'type': 'string'}]] - - [328, 1, '_trigger', 'memtx', 0, {}, [{'name': 'name', 'type': 'string'}, {'name': 'opts', - 'type': 'map'}]] + - [328, 1, '_trigger', 'memtx', 0, {}, [{'name': 'name', 'type': 'string'}, {'name': 'space_id', + 'type': 'unsigned'}, {'name': 'opts', 'type': 'map'}]] - [330, 1, '_truncate', 'memtx', 0, {}, [{'name': 'id', 'type': 'unsigned'}, {'name': 'count', 'type': 'unsigned'}]] - [340, 1, '_space_sequence', 'memtx', 0, {}, [{'name': 'id', 'type': 'unsigned'}, @@ -122,6 +122,7 @@ box.space._index:select{} - [320, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned']]] - [320, 1, 'uuid', 'tree', {'unique': true}, [[1, 'string']]] - [328, 0, 'primary', 'tree', {'unique': true}, [[0, 'string']]] + - [328, 1, 'space_id', 'tree', {'unique': false}, [[1, 'unsigned']]] - [330, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned']]] - [340, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned']]] - [340, 1, 'sequence', 'tree', {'unique': false}, [[1, 'unsigned']]] diff --git a/test/box/access_misc.result b/test/box/access_misc.result index 19e82bb..5a2563d 100644 --- a/test/box/access_misc.result +++ b/test/box/access_misc.result @@ -798,8 +798,8 @@ box.space._space:select() {'name': 'object_id', 'type': 'unsigned'}, {'name': 'privilege', 'type': 'unsigned'}]] - [320, 1, '_cluster', 'memtx', 0, {}, [{'name': 'id', 'type': 'unsigned'}, {'name': 'uuid', 'type': 'string'}]] - - [328, 1, '_trigger', 'memtx', 0, {}, [{'name': 'name', 'type': 'string'}, {'name': 'opts', - 'type': 'map'}]] + - [328, 1, '_trigger', 'memtx', 0, {}, [{'name': 'name', 'type': 'string'}, {'name': 'space_id', + 'type': 'unsigned'}, {'name': 'opts', 'type': 'map'}]] - [330, 1, '_truncate', 'memtx', 0, {}, [{'name': 'id', 'type': 'unsigned'}, {'name': 'count', 'type': 'unsigned'}]] - [340, 1, '_space_sequence', 'memtx', 0, {}, [{'name': 'id', 'type': 'unsigned'}, diff --git a/test/box/access_sysview.result b/test/box/access_sysview.result index 3f93b5e..ae04266 100644 --- a/test/box/access_sysview.result +++ b/test/box/access_sysview.result @@ -234,7 +234,7 @@ box.session.su('guest') ... #box.space._vindex:select{} --- -- 47 +- 48 ... #box.space._vuser:select{} --- @@ -262,7 +262,7 @@ box.session.su('guest') ... #box.space._vindex:select{} --- -- 47 +- 48 ... #box.space._vuser:select{} --- diff --git a/test/box/alter.result b/test/box/alter.result index 217c41d..c41b52f 100644 --- a/test/box/alter.result +++ b/test/box/alter.result @@ -224,6 +224,7 @@ _index:select{} - [320, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned']]] - [320, 1, 'uuid', 'tree', {'unique': true}, [[1, 'string']]] - [328, 0, 'primary', 'tree', {'unique': true}, [[0, 'string']]] + - [328, 1, 'space_id', 'tree', {'unique': false}, [[1, 'unsigned']]] - [330, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned']]] - [340, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned']]] - [340, 1, 'sequence', 'tree', {'unique': false}, [[1, 'unsigned']]] diff --git a/test/sql/gh2141-delete-trigger-drop-table.result b/test/sql/gh2141-delete-trigger-drop-table.result index ba7016c..ec5a380 100644 --- a/test/sql/gh2141-delete-trigger-drop-table.result +++ b/test/sql/gh2141-delete-trigger-drop-table.result @@ -24,7 +24,7 @@ box.sql.execute("CREATE TRIGGER tt_ad AFTER DELETE ON t BEGIN SELECT 1; END") --- ... -- check that these triggers exist -box.sql.execute("SELECT * FROM \"_trigger\"") +box.sql.execute("SELECT \"name\", \"opts\" FROM \"_trigger\"") --- - - ['TT_AD', !!binary gaNzcWzZOkNSRUFURSBUUklHR0VSIHR0X2FkIEFGVEVSIERFTEVURSBPTiB0IEJFR0lOIFNFTEVDVCAxOyBFTkQ=] - ['TT_AI', !!binary gaNzcWzZOkNSRUFURSBUUklHR0VSIHR0X2FpIEFGVEVSIElOU0VSVCBPTiB0IEJFR0lOIFNFTEVDVCAxOyBFTkQ=] @@ -38,7 +38,7 @@ box.sql.execute("DROP TABLE t") --- ... -- check that triggers were dropped with deleted table -box.sql.execute("SELECT * FROM \"_trigger\"") +box.sql.execute("SELECT \"name\", \"opts\" FROM \"_trigger\"") --- - [] ... diff --git a/test/sql/gh2141-delete-trigger-drop-table.test.lua b/test/sql/gh2141-delete-trigger-drop-table.test.lua index e6a030c..87110a4 100644 --- a/test/sql/gh2141-delete-trigger-drop-table.test.lua +++ b/test/sql/gh2141-delete-trigger-drop-table.test.lua @@ -11,10 +11,10 @@ box.sql.execute("CREATE TRIGGER tt_bd BEFORE DELETE ON t BEGIN SELECT 1; END") box.sql.execute("CREATE TRIGGER tt_ad AFTER DELETE ON t BEGIN SELECT 1; END") -- check that these triggers exist -box.sql.execute("SELECT * FROM \"_trigger\"") +box.sql.execute("SELECT \"name\", \"opts\" FROM \"_trigger\"") -- drop table box.sql.execute("DROP TABLE t") -- check that triggers were dropped with deleted table -box.sql.execute("SELECT * FROM \"_trigger\"") +box.sql.execute("SELECT \"name\", \"opts\" FROM \"_trigger\"") diff --git a/test/sql/persistency.result b/test/sql/persistency.result index 7a7f6b8..d85d7cc 100644 --- a/test/sql/persistency.result +++ b/test/sql/persistency.result @@ -140,7 +140,7 @@ box.sql.execute("INSERT INTO barfoo VALUES ('foobar', 1000)") box.sql.execute("CREATE TRIGGER tfoobar AFTER INSERT ON foobar BEGIN INSERT INTO barfoo VALUES ('trigger test', 9999); END") --- ... -box.sql.execute("SELECT * FROM \"_trigger\""); +box.sql.execute("SELECT \"name\", \"opts\" FROM \"_trigger\""); --- - - ['TFOOBAR', !!binary gaNzcWzZaUNSRUFURSBUUklHR0VSIHRmb29iYXIgQUZURVIgSU5TRVJUIE9OIGZvb2JhciBCRUdJTiBJTlNFUlQgSU5UTyBiYXJmb28gVkFMVUVTICgndHJpZ2dlciB0ZXN0JywgOTk5OSk7IEVORA==] ... @@ -166,7 +166,7 @@ box.sql.execute("SELECT a FROM t1 ORDER BY b, a LIMIT 10 OFFSET 20;"); ... test_run:cmd('restart server default'); -- prove that trigger survived -box.sql.execute("SELECT * FROM \"_trigger\""); +box.sql.execute("SELECT \"name\", \"opts\" FROM \"_trigger\""); --- - - ['TFOOBAR', !!binary gaNzcWzZaUNSRUFURSBUUklHR0VSIHRmb29iYXIgQUZURVIgSU5TRVJUIE9OIGZvb2JhciBCRUdJTiBJTlNFUlQgSU5UTyBiYXJmb28gVkFMVUVTICgndHJpZ2dlciB0ZXN0JywgOTk5OSk7IEVORA==] ... @@ -179,7 +179,7 @@ box.sql.execute("SELECT * FROM barfoo WHERE foo = 9999"); - - ['trigger test', 9999] ... -- and still persistent -box.sql.execute("SELECT * FROM \"_trigger\"") +box.sql.execute("SELECT \"name\", \"opts\" FROM \"_trigger\"") --- - - ['TFOOBAR', !!binary gaNzcWzZaUNSRUFURSBUUklHR0VSIHRmb29iYXIgQUZURVIgSU5TRVJUIE9OIGZvb2JhciBCRUdJTiBJTlNFUlQgSU5UTyBiYXJmb28gVkFMVUVTICgndHJpZ2dlciB0ZXN0JywgOTk5OSk7IEVORA==] ... @@ -193,7 +193,7 @@ box.sql.execute("DROP TRIGGER tfoobar") - error: 'no such trigger: TFOOBAR' ... -- Should be empty -box.sql.execute("SELECT * FROM \"_trigger\"") +box.sql.execute("SELECT \"name\", \"opts\" FROM \"_trigger\"") --- - [] ... diff --git a/test/sql/persistency.test.lua b/test/sql/persistency.test.lua index bd05545..e994a62 100644 --- a/test/sql/persistency.test.lua +++ b/test/sql/persistency.test.lua @@ -49,7 +49,7 @@ box.sql.execute("INSERT INTO barfoo VALUES ('foobar', 1000)") -- create a trigger box.sql.execute("CREATE TRIGGER tfoobar AFTER INSERT ON foobar BEGIN INSERT INTO barfoo VALUES ('trigger test', 9999); END") -box.sql.execute("SELECT * FROM \"_trigger\""); +box.sql.execute("SELECT \"name\", \"opts\" FROM \"_trigger\""); -- Many entries box.sql.execute("CREATE TABLE t1(a,b,c,PRIMARY KEY(b,c));") @@ -59,21 +59,21 @@ box.sql.execute("SELECT a FROM t1 ORDER BY b, a LIMIT 10 OFFSET 20;"); test_run:cmd('restart server default'); -- prove that trigger survived -box.sql.execute("SELECT * FROM \"_trigger\""); +box.sql.execute("SELECT \"name\", \"opts\" FROM \"_trigger\""); -- ... functional box.sql.execute("INSERT INTO foobar VALUES ('foobar trigger test', 8888)") box.sql.execute("SELECT * FROM barfoo WHERE foo = 9999"); -- and still persistent -box.sql.execute("SELECT * FROM \"_trigger\"") +box.sql.execute("SELECT \"name\", \"opts\" FROM \"_trigger\"") -- and can be dropped just once box.sql.execute("DROP TRIGGER tfoobar") -- Should error box.sql.execute("DROP TRIGGER tfoobar") -- Should be empty -box.sql.execute("SELECT * FROM \"_trigger\"") +box.sql.execute("SELECT \"name\", \"opts\" FROM \"_trigger\"") -- prove barfoo2 still exists box.sql.execute("INSERT INTO barfoo VALUES ('xfoo', 1)") diff --git a/test/sql/upgrade.result b/test/sql/upgrade.result index dcdb689..882bdd0 100644 --- a/test/sql/upgrade.result +++ b/test/sql/upgrade.result @@ -19,8 +19,8 @@ test_run:switch('upgrade') -- test system tables box.space._space.index['name']:get('_trigger') --- -- [328, 1, '_trigger', 'memtx', 0, {}, [{'name': 'name', 'type': 'string'}, {'name': 'opts', - 'type': 'map'}]] +- [328, 1, '_trigger', 'memtx', 0, {}, [{'name': 'name', 'type': 'string'}, {'name': 'space_id', + 'type': 'unsigned'}, {'name': 'opts', 'type': 'map'}]] ... box.space._space.index['name']:get('_sql_stat1') --- @@ -69,6 +69,9 @@ box.sql.execute("CREATE TABLE t_out(x INTEGER PRIMARY KEY);") box.sql.execute("CREATE TRIGGER t1t AFTER INSERT ON t BEGIN INSERT INTO t_out VALUES(1); END;") --- ... +box.sql.execute("CREATE TRIGGER t2t AFTER INSERT ON t BEGIN INSERT INTO t_out VALUES(2); END;") +--- +... box.space._space.index['name']:get('T') --- - [513, 1, 'T', 'memtx', 1, {'sql': 'CREATE TABLE t(x INTEGER PRIMARY KEY)'}, [{'type': 'integer', @@ -79,10 +82,33 @@ box.space._space.index['name']:get('T_OUT') - [514, 1, 'T_OUT', 'memtx', 1, {'sql': 'CREATE TABLE t_out(x INTEGER PRIMARY KEY)'}, [{'type': 'integer', 'nullable_action': 'abort', 'name': 'X', 'is_nullable': false}]] ... -box.space._trigger:get('T1T') +t1t = box.space._trigger:get('T1T') +--- +... +t2t = box.space._trigger:get('T2T') +--- +... +t1t.name +--- +- T1T +... +t1t.opts --- -- ['T1T', {'sql': 'CREATE TRIGGER t1t AFTER INSERT ON t BEGIN INSERT INTO t_out VALUES(1); - END;'}] +- {'sql': 'CREATE TRIGGER t1t AFTER INSERT ON t BEGIN INSERT INTO t_out VALUES(1); + END;'} +... +t2t.name +--- +- T2T +... +t2t.opts +--- +- {'sql': 'CREATE TRIGGER t2t AFTER INSERT ON t BEGIN INSERT INTO t_out VALUES(2); + END;'} +... +assert(t1t.id == t2t.id) +--- +- true ... box.sql.execute("INSERT INTO T VALUES(1);") --- @@ -94,6 +120,7 @@ box.space.T:select() box.space.T_OUT:select() --- - - [1] + - [2] ... box.sql.execute("SELECT * FROM T") --- diff --git a/test/sql/upgrade.test.lua b/test/sql/upgrade.test.lua index d0add86..6560710 100644 --- a/test/sql/upgrade.test.lua +++ b/test/sql/upgrade.test.lua @@ -25,9 +25,16 @@ box.space._index:get({box.space._space.index['name']:get('T1').id, 0}) box.sql.execute("CREATE TABLE t(x INTEGER PRIMARY KEY);") box.sql.execute("CREATE TABLE t_out(x INTEGER PRIMARY KEY);") box.sql.execute("CREATE TRIGGER t1t AFTER INSERT ON t BEGIN INSERT INTO t_out VALUES(1); END;") +box.sql.execute("CREATE TRIGGER t2t AFTER INSERT ON t BEGIN INSERT INTO t_out VALUES(2); END;") box.space._space.index['name']:get('T') box.space._space.index['name']:get('T_OUT') -box.space._trigger:get('T1T') +t1t = box.space._trigger:get('T1T') +t2t = box.space._trigger:get('T2T') +t1t.name +t1t.opts +t2t.name +t2t.opts +assert(t1t.id == t2t.id) box.sql.execute("INSERT INTO T VALUES(1);") box.space.T:select() -- 2.7.4