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 4C4F829D72 for ; Tue, 2 Oct 2018 06:49:06 -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 B2yey3WW8Qf2 for ; Tue, 2 Oct 2018 06:49:06 -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 CD72629B74 for ; Tue, 2 Oct 2018 06:49:05 -0400 (EDT) From: AKhatskevich Subject: [tarantool-patches] [PATCH 2/3] sql: delete foreign_keys pragma Date: Tue, 2 Oct 2018 13:48:35 +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: korablev@tarantool.org, tarantool-patches@freelists.org Part of #3696 --- src/box/sql.c | 3 +-- src/box/sql/CMakeLists.txt | 1 - src/box/sql/fkey.c | 21 ++++----------------- src/box/sql/insert.c | 3 +-- src/box/sql/pragma.h | 7 ------- src/box/sql/sqliteInt.h | 2 +- test/sql-tap/tkt-b1d3a2e531.test.lua | 8 +------- test/sql-tap/triggerC.test.lua | 5 +---- test/sql/transitive-transactions.result | 3 --- test/sql/transitive-transactions.test.lua | 1 - 10 files changed, 9 insertions(+), 45 deletions(-) diff --git a/src/box/sql.c b/src/box/sql.c index ab4a587a5..a9077dd32 100644 --- a/src/box/sql.c +++ b/src/box/sql.c @@ -59,8 +59,7 @@ static const char nil_key[] = { 0x90 }; /* Empty MsgPack array. */ static const uint32_t default_sql_flags = SQLITE_ShortColNames | SQLITE_EnableTrigger | SQLITE_AutoIndex - | SQLITE_RecTriggers - | SQLITE_ForeignKeys; + | SQLITE_RecTriggers; void sql_init() diff --git a/src/box/sql/CMakeLists.txt b/src/box/sql/CMakeLists.txt index 1f852424a..aa57add59 100644 --- a/src/box/sql/CMakeLists.txt +++ b/src/box/sql/CMakeLists.txt @@ -16,7 +16,6 @@ include_directories(${SQL_SRC_DIR}) include_directories(${SQL_BIN_DIR}) add_definitions(-DSQLITE_MAX_WORKER_THREADS=0) -add_definitions(-DSQLITE_DEFAULT_FOREIGN_KEYS=1) add_definitions(-DSQLITE_OMIT_AUTOMATIC_INDEX) set(TEST_DEFINITIONS diff --git a/src/box/sql/fkey.c b/src/box/sql/fkey.c index b2d2a19e7..091778fc8 100644 --- a/src/box/sql/fkey.c +++ b/src/box/sql/fkey.c @@ -527,12 +527,6 @@ fkey_emit_check(struct Parse *parser, struct Table *tab, int reg_old, */ assert((reg_old == 0) != (reg_new == 0)); - /* - * If foreign-keys are disabled, this function is a no-op. - */ - if ((user_session->sql_flags & SQLITE_ForeignKeys) == 0) - return; - /* * Loop through all the foreign key constraints for which * tab is the child table. @@ -674,9 +668,6 @@ fkey_emit_check(struct Parse *parser, struct Table *tab, int reg_old, bool fkey_is_required(uint32_t space_id, const int *changes) { - struct session *user_session = current_session(); - if ((user_session->sql_flags & SQLITE_ForeignKeys) == 0) - return false; struct space *space = space_by_id(space_id); if (changes == NULL) { /* @@ -919,16 +910,12 @@ void fkey_emit_actions(struct Parse *parser, struct Table *tab, int reg_old, const int *changes) { - struct session *user_session = current_session(); /* - * If foreign-key support is enabled, iterate through all - * FKs that refer to table tab. If there is an action - * associated with the FK for this operation (either - * update or delete), invoke the associated trigger - * sub-program. + * Iterate through all FKs that refer to table tab. + * If there is an action associated with the FK for + * this operation (either update or delete), + * invoke the associated trigger sub-program. */ - if ((user_session->sql_flags & SQLITE_ForeignKeys) == 0) - return; struct space *space = space_by_id(tab->def->id); assert(space != NULL); struct fkey *fk; diff --git a/src/box/sql/insert.c b/src/box/sql/insert.c index 03f4e1b14..c696f39f1 100644 --- a/src/box/sql/insert.c +++ b/src/box/sql/insert.c @@ -1278,8 +1278,7 @@ xferOptimization(Parse * pParse, /* Parser context */ * So the extra complication to make this rule less restrictive is probably * not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e] */ - if ((user_session->sql_flags & SQLITE_ForeignKeys) != 0 && - !rlist_empty(&dest->child_fkey)) + if (!rlist_empty(&dest->child_fkey)) return 0; if ((user_session->sql_flags & SQLITE_CountRows) != 0) { return 0; /* xfer opt does not play well with PRAGMA count_changes */ diff --git a/src/box/sql/pragma.h b/src/box/sql/pragma.h index ecc9ee879..c135202d4 100644 --- a/src/box/sql/pragma.h +++ b/src/box/sql/pragma.h @@ -135,13 +135,6 @@ static const PragmaName aPragmaName[] = { PragFlg_NeedSchema | PragFlg_Result1 | PragFlg_SchemaOpt, /* ColNames: */ 29, 8, /* iArg: */ 0}, -#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) - { /* zName: */ "foreign_keys", - /* ePragTyp: */ PragTyp_FLAG, - /* ePragFlg: */ PragFlg_Result0 | PragFlg_NoColumns1, - /* ColNames: */ 0, 0, - /* iArg: */ SQLITE_ForeignKeys}, -#endif #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) { /* zName: */ "full_column_names", /* ePragTyp: */ PragTyp_FLAG, diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h index e9c15dbb3..b2d527834 100644 --- a/src/box/sql/sqliteInt.h +++ b/src/box/sql/sqliteInt.h @@ -1562,7 +1562,7 @@ struct sqlite3 { #define SQLITE_ReadUncommitted 0x0004000 /* For shared-cache mode */ #define SQLITE_ReverseOrder 0x00020000 /* Reverse unordered SELECTs */ #define SQLITE_RecTriggers 0x00040000 /* Enable recursive triggers */ -#define SQLITE_ForeignKeys 0x00080000 /* Enforce foreign key constraints */ +/* 0x00080000 Free bit */ #define SQLITE_AutoIndex 0x00100000 /* Enable automatic indexes */ #define SQLITE_PreferBuiltin 0x00200000 /* Preference to built-in funcs */ #define SQLITE_EnableTrigger 0x01000000 /* True to enable triggers */ diff --git a/test/sql-tap/tkt-b1d3a2e531.test.lua b/test/sql-tap/tkt-b1d3a2e531.test.lua index 85b0f46d7..324ffa0c8 100755 --- a/test/sql-tap/tkt-b1d3a2e531.test.lua +++ b/test/sql-tap/tkt-b1d3a2e531.test.lua @@ -1,6 +1,6 @@ #!/usr/bin/env tarantool test = require("sqltester") -test:plan(12) +test:plan(11) --!./tcltestrunner.lua -- 2011 August 22 @@ -24,12 +24,6 @@ test:plan(12) testprefix = "tkt-b1d3a2e531" -test:do_execsql_test( - 1.0, - [[ - PRAGMA foreign_keys = 'ON' - ]]) - test:do_execsql_test( 1.1, [[ diff --git a/test/sql-tap/triggerC.test.lua b/test/sql-tap/triggerC.test.lua index 06e6e5bd2..d5fdc1470 100755 --- a/test/sql-tap/triggerC.test.lua +++ b/test/sql-tap/triggerC.test.lua @@ -1146,12 +1146,10 @@ test:do_execsql_test( test:do_execsql_test( "triggerC-15.1.1", [[ - -- test is not respects fk - PRAGMA foreign_keys='false'; PRAGMA recursive_triggers = 1; CREATE TABLE node( id not null primary key, - pid int not null default 0 references node, + pid int not null default 0, key varchar not null, path varchar default '', unique(pid, key) @@ -1170,7 +1168,6 @@ test:do_execsql_test( INSERT INTO node(id, pid, key) VALUES(900, 90, 'test2'); DELETE FROM node WHERE id=9; SELECT * FROM node; - PRAGMA foreign_keys='true'; ]]) -- Tarantool: such indentifiers are not working diff --git a/test/sql/transitive-transactions.result b/test/sql/transitive-transactions.result index a01b1d0b0..88685b4c1 100644 --- a/test/sql/transitive-transactions.result +++ b/test/sql/transitive-transactions.result @@ -27,9 +27,6 @@ box.sql.execute('START TRANSACTION;') box.commit(); box.sql.execute('START TRANSACTION;') box.rollback(); --- ... -box.sql.execute('pragma foreign_keys = 1;'); ---- -... box.sql.execute('CREATE TABLE parent(id INT PRIMARY KEY, y INT UNIQUE);'); --- ... diff --git a/test/sql/transitive-transactions.test.lua b/test/sql/transitive-transactions.test.lua index 1ac2b8d64..5127202e3 100644 --- a/test/sql/transitive-transactions.test.lua +++ b/test/sql/transitive-transactions.test.lua @@ -13,7 +13,6 @@ box.begin() box.sql.execute('ROLLBACK'); box.sql.execute('START TRANSACTION;') box.commit(); box.sql.execute('START TRANSACTION;') box.rollback(); -box.sql.execute('pragma foreign_keys = 1;'); box.sql.execute('CREATE TABLE parent(id INT PRIMARY KEY, y INT UNIQUE);'); box.sql.execute('CREATE TABLE child(id INT PRIMARY KEY, x INT REFERENCES parent(y) DEFERRABLE INITIALLY DEFERRED);'); -- 2.14.1