From: Nikita Pettik <korablev@tarantool.org> To: tarantool-patches@freelists.org Cc: v.shpilevoy@tarantool.org, kostja@tarantool.org, alexander.turenko@tarantool.org, Nikita Pettik <korablev@tarantool.org> Subject: [tarantool-patches] [PATCH 4/8] sql: refactor sql_prepare() and sqlPrepare() Date: Tue, 27 Aug 2019 16:34:25 +0300 [thread overview] Message-ID: <4f5b2224bd19b3b988220e3bf4e1e55ed7ad45dd.1566907520.git.korablev@tarantool.org> (raw) In-Reply-To: <cover.1566907519.git.korablev@tarantool.org> In-Reply-To: <cover.1566907519.git.korablev@tarantool.org> - Removed saveSqlFlag as argument from sqlPrepare(). It was used to indicate that its caller is sql_prepare_v2() not sql_prepare(). Since in previous commit we've left only one version of this function let's remove this flag at all. - Removed struct db from list of sql_prepare() arguments. There's one global database handler and it can be obtained by sql_get() call. Hence, it makes no sense to pass around this argument. Needed for #3292 --- src/box/execute.c | 3 +-- src/box/sql/analyze.c | 15 +++++++-------- src/box/sql/legacy.c | 2 +- src/box/sql/prepare.c | 10 ++++------ src/box/sql/sqlInt.h | 3 +-- src/box/sql/vdbe.h | 2 +- src/box/sql/vdbeInt.h | 1 - src/box/sql/vdbeapi.c | 7 +++---- src/box/sql/vdbeaux.c | 5 +---- 9 files changed, 19 insertions(+), 29 deletions(-) diff --git a/src/box/execute.c b/src/box/execute.c index b8d161815..078753342 100644 --- a/src/box/execute.c +++ b/src/box/execute.c @@ -441,8 +441,7 @@ sql_prepare_and_execute(const char *sql, int len, const struct sql_bind *bind, struct region *region) { struct sql_stmt *stmt; - struct sql *db = sql_get(); - if (sql_prepare(db, sql, len, &stmt, NULL) != 0) + if (sql_prepare(sql, len, &stmt, NULL) != 0) return -1; assert(stmt != NULL); port_sql_create(port, stmt); diff --git a/src/box/sql/analyze.c b/src/box/sql/analyze.c index bd52d12df..fa3d364e9 100644 --- a/src/box/sql/analyze.c +++ b/src/box/sql/analyze.c @@ -1344,7 +1344,7 @@ sample_compare(const void *a, const void *b, void *arg) * @retval 0 on success, -1 otherwise. */ static int -load_stat_from_space(struct sql *db, const char *sql_select_prepare, +load_stat_from_space(const char *sql_select_prepare, const char *sql_select_load, struct index_stat *stats) { struct index **indexes = NULL; @@ -1360,7 +1360,7 @@ load_stat_from_space(struct sql *db, const char *sql_select_prepare, } } sql_stmt *stmt = NULL; - int rc = sql_prepare(db, sql_select_prepare, -1, &stmt, 0); + int rc = sql_prepare(sql_select_prepare, -1, &stmt, 0); if (rc) goto finalize; uint32_t current_idx_count = 0; @@ -1428,7 +1428,7 @@ load_stat_from_space(struct sql *db, const char *sql_select_prepare, rc = sql_finalize(stmt); if (rc) goto finalize; - rc = sql_prepare(db, sql_select_load, -1, &stmt, 0); + rc = sql_prepare(sql_select_load, -1, &stmt, 0); if (rc) goto finalize; struct index *prev_index = NULL; @@ -1506,12 +1506,11 @@ load_stat_from_space(struct sql *db, const char *sql_select_prepare, } static int -load_stat_to_index(struct sql *db, const char *sql_select_load, - struct index_stat **stats) +load_stat_to_index(const char *sql_select_load, struct index_stat **stats) { assert(stats != NULL && *stats != NULL); struct sql_stmt *stmt = NULL; - if (sql_prepare(db, sql_select_load, -1, &stmt, 0) != 0) + if (sql_prepare(sql_select_load, -1, &stmt, 0) != 0) return -1; uint32_t current_idx_count = 0; while (sql_step(stmt) == SQL_ROW) { @@ -1697,7 +1696,7 @@ sql_analysis_load(struct sql *db) const char *load_query = "SELECT \"tbl\",\"idx\",\"neq\",\"nlt\"," "\"ndlt\",\"sample\" FROM \"_sql_stat4\""; /* Load the statistics from the _sql_stat4 table. */ - if (load_stat_from_space(db, init_query, load_query, stats) != 0) + if (load_stat_from_space(init_query, load_query, stats) != 0) goto fail; /* * Now we have complete statistics for each index @@ -1740,7 +1739,7 @@ sql_analysis_load(struct sql *db) */ const char *order_query = "SELECT \"tbl\",\"idx\" FROM " "\"_sql_stat4\" GROUP BY \"tbl\",\"idx\""; - if (load_stat_to_index(db, order_query, heap_stats) == 0) + if (load_stat_to_index(order_query, heap_stats) == 0) return box_txn_commit(); fail: box_txn_rollback(); diff --git a/src/box/sql/legacy.c b/src/box/sql/legacy.c index bfd1e32b9..16507b334 100644 --- a/src/box/sql/legacy.c +++ b/src/box/sql/legacy.c @@ -70,7 +70,7 @@ sql_exec(sql * db, /* The database on which the SQL executes */ char **azVals = 0; pStmt = 0; - rc = sql_prepare(db, zSql, -1, &pStmt, &zLeftover); + rc = sql_prepare(zSql, -1, &pStmt, &zLeftover); assert(rc == 0 || pStmt == NULL); if (rc != 0) continue; diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c index ba3b7d71f..f72f9aa23 100644 --- a/src/box/sql/prepare.c +++ b/src/box/sql/prepare.c @@ -46,7 +46,6 @@ static int sqlPrepare(sql * db, /* Database handle. */ const char *zSql, /* UTF-8 encoded SQL statement. */ int nBytes, /* Length of zSql in bytes. */ - int saveSqlFlag, /* True to copy SQL text into the sql_stmt */ Vdbe * pReprepare, /* VM being reprepared */ sql_stmt ** ppStmt, /* OUT: A pointer to the prepared statement */ const char **pzTail /* OUT: End of parsed string */ @@ -156,8 +155,7 @@ sqlPrepare(sql * db, /* Database handle. */ if (db->init.busy == 0) { Vdbe *pVdbe = sParse.pVdbe; - sqlVdbeSetSql(pVdbe, zSql, (int)(sParse.zTail - zSql), - saveSqlFlag); + sqlVdbeSetSql(pVdbe, zSql, (int)(sParse.zTail - zSql)); } if (sParse.pVdbe != NULL && (rc != 0 || db->mallocFailed)) { sqlVdbeFinalize(sParse.pVdbe); @@ -192,7 +190,7 @@ sqlReprepare(Vdbe * p) zSql = sql_sql((sql_stmt *) p); assert(zSql != 0); /* Reprepare only called for prepare_v2() statements */ db = sqlVdbeDb(p); - if (sqlPrepare(db, zSql, -1, 0, p, &pNew, 0) != 0) { + if (sqlPrepare(db, zSql, -1, p, &pNew, 0) != 0) { assert(pNew == 0); return -1; } @@ -205,10 +203,10 @@ sqlReprepare(Vdbe * p) } int -sql_prepare(struct sql *db, const char *sql, int length, struct sql_stmt **stmt, +sql_prepare(const char *sql, int length, struct sql_stmt **stmt, const char **sql_tail) { - int rc = sqlPrepare(db, sql, length, 1, 0, stmt, sql_tail); + int rc = sqlPrepare(sql_get(), sql, length, 0, stmt, sql_tail); assert(rc == 0 || stmt == NULL || *stmt == NULL); return rc; } diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h index 2ad96b93a..d2fc76919 100644 --- a/src/box/sql/sqlInt.h +++ b/src/box/sql/sqlInt.h @@ -450,14 +450,13 @@ typedef void (*sql_destructor_type) (void *); /** * Prepare (compile into VDBE byte-code) statement. * - * @param db Database handle. * @param sql UTF-8 encoded SQL statement. * @param length Length of @param sql in bytes. * @param[out] stmt A pointer to the prepared statement. * @param[out] sql_tail End of parsed string. */ int -sql_prepare(struct sql *db, const char *sql, int length, struct sql_stmt **stmt, +sql_prepare(const char *sql, int length, struct sql_stmt **stmt, const char **sql_tail); int diff --git a/src/box/sql/vdbe.h b/src/box/sql/vdbe.h index 06f258805..b5b13a269 100644 --- a/src/box/sql/vdbe.h +++ b/src/box/sql/vdbe.h @@ -246,7 +246,7 @@ void sqlVdbeSetNumCols(Vdbe *, int); int sqlVdbeSetColName(Vdbe *, int, int, const char *, void (*)(void *)); void sqlVdbeCountChanges(Vdbe *); sql *sqlVdbeDb(Vdbe *); -void sqlVdbeSetSql(Vdbe *, const char *z, int n, int); +void sqlVdbeSetSql(Vdbe *, const char *z, int n); void sqlVdbeSwap(Vdbe *, Vdbe *); VdbeOp *sqlVdbeTakeOpArray(Vdbe *, int *, int *); sql_value *sqlVdbeGetBoundValue(Vdbe *, int, u8); diff --git a/src/box/sql/vdbeInt.h b/src/box/sql/vdbeInt.h index 3a416aea5..0b6109234 100644 --- a/src/box/sql/vdbeInt.h +++ b/src/box/sql/vdbeInt.h @@ -414,7 +414,6 @@ struct Vdbe { bft explain:2; /* True if EXPLAIN present on SQL command */ bft changeCntOn:1; /* True to update the change-counter */ bft runOnlyOnce:1; /* Automatically expire on reset */ - bft isPrepareV2:1; /* True if prepared with prepare_v2() */ u32 aCounter[5]; /* Counters used by sql_stmt_status() */ char *zSql; /* Text of the SQL statement that generated this */ void *pFree; /* Free this when deleting the vdbe */ diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c index 0b54a9429..a25f063cc 100644 --- a/src/box/sql/vdbeapi.c +++ b/src/box/sql/vdbeapi.c @@ -112,7 +112,7 @@ sql_clear_bindings(sql_stmt * pStmt) sqlVdbeMemRelease(&p->aVar[i]); p->aVar[i].flags = MEM_Null; } - if (p->isPrepareV2 && p->expmask) { + if (p->expmask) { p->expired = 1; } return rc; @@ -454,7 +454,7 @@ sqlStep(Vdbe * p) if (rc != SQL_ROW) checkProfileCallback(db, p); - if (p->isPrepareV2 && rc != SQL_ROW && rc != SQL_DONE) { + if (rc != SQL_ROW && rc != SQL_DONE) { /* If this statement was prepared using sql_prepare(), and an * error has occurred, then return an error. */ @@ -845,8 +845,7 @@ vdbeUnbind(Vdbe * p, int i) * as if there had been a schema change, on the first sql_step() call * following any change to the bindings of that parameter. */ - if (p->isPrepareV2 && - ((i < 32 && p->expmask & ((u32) 1 << i)) + if (((i < 32 && p->expmask & ((u32) 1 << i)) || p->expmask == 0xffffffff) ) { p->expired = 1; diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c index 61dc74dc1..e09c88fd1 100644 --- a/src/box/sql/vdbeaux.c +++ b/src/box/sql/vdbeaux.c @@ -89,14 +89,12 @@ sql_vdbe_prepare(struct Vdbe *vdbe) * Remember the SQL string for a prepared statement. */ void -sqlVdbeSetSql(Vdbe * p, const char *z, int n, int isPrepareV2) +sqlVdbeSetSql(Vdbe * p, const char *z, int n) { - assert(isPrepareV2 == 1 || isPrepareV2 == 0); if (p == 0) return; assert(p->zSql == 0); p->zSql = sqlDbStrNDup(p->db, z, n); - p->isPrepareV2 = (u8) isPrepareV2; } /* @@ -120,7 +118,6 @@ sqlVdbeSwap(Vdbe * pA, Vdbe * pB) zTmp = pA->zSql; pA->zSql = pB->zSql; pB->zSql = zTmp; - pB->isPrepareV2 = pA->isPrepareV2; } /* -- 2.15.1
next prev parent reply other threads:[~2019-08-27 13:34 UTC|newest] Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-08-27 13:34 [tarantool-patches] [PATCH 0/8] rfc: introduce dry-run execution of SQL queries Nikita Pettik 2019-08-27 13:34 ` [tarantool-patches] [PATCH 1/8] port: increase padding of struct port Nikita Pettik 2019-08-28 9:33 ` [tarantool-patches] " Konstantin Osipov 2019-08-29 20:46 ` Vladislav Shpilevoy 2019-08-27 13:34 ` [tarantool-patches] [PATCH 2/8] port: move struct port_sql to box/port.h Nikita Pettik 2019-08-28 9:33 ` [tarantool-patches] " Konstantin Osipov 2019-08-29 20:46 ` Vladislav Shpilevoy 2019-08-27 13:34 ` [tarantool-patches] [PATCH 3/8] sql: remove sql_prepare_v2() Nikita Pettik 2019-08-28 9:33 ` [tarantool-patches] " Konstantin Osipov 2019-08-29 20:46 ` Vladislav Shpilevoy 2019-08-27 13:34 ` Nikita Pettik [this message] 2019-08-28 9:35 ` [tarantool-patches] Re: [PATCH 4/8] sql: refactor sql_prepare() and sqlPrepare() Konstantin Osipov 2019-08-29 20:46 ` Vladislav Shpilevoy 2019-08-27 13:34 ` [tarantool-patches] [PATCH 5/8] sql: move sql_prepare() declaration to box/execute.h Nikita Pettik 2019-08-28 9:35 ` [tarantool-patches] " Konstantin Osipov 2019-08-27 13:34 ` [tarantool-patches] [PATCH 6/8] refactoring: use sql_prepare() and sql_execute() in tx_process_sql() Nikita Pettik 2019-08-28 9:37 ` [tarantool-patches] " Konstantin Osipov 2019-08-29 20:46 ` Vladislav Shpilevoy 2019-08-27 13:34 ` [tarantool-patches] [PATCH 7/8] netbox: allow passing options to :execute() Nikita Pettik 2019-08-28 9:38 ` [tarantool-patches] " Konstantin Osipov 2019-08-29 20:46 ` Vladislav Shpilevoy 2019-08-27 13:34 ` [tarantool-patches] [PATCH 8/8] sql: introduce dry-run execution Nikita Pettik 2019-08-28 9:39 ` [tarantool-patches] " Konstantin Osipov 2019-08-29 20:46 ` Vladislav Shpilevoy 2019-08-28 9:31 ` [tarantool-patches] Re: [PATCH 0/8] rfc: introduce dry-run execution of SQL queries Konstantin Osipov 2019-08-29 20:46 ` Vladislav Shpilevoy
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=4f5b2224bd19b3b988220e3bf4e1e55ed7ad45dd.1566907520.git.korablev@tarantool.org \ --to=korablev@tarantool.org \ --cc=alexander.turenko@tarantool.org \ --cc=kostja@tarantool.org \ --cc=tarantool-patches@freelists.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [tarantool-patches] [PATCH 4/8] sql: refactor sql_prepare() and sqlPrepare()' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox