* [tarantool-patches] [PATCH v1] sql: change of PRAGMA INDEX_INFO syntax
@ 2018-06-12 9:32 Ivan Ilyin
2018-06-17 20:06 ` [tarantool-patches] " Alexander Turenko
0 siblings, 1 reply; 2+ messages in thread
From: Ivan Ilyin @ 2018-06-12 9:32 UTC (permalink / raw)
To: tarantool-patches; +Cc: Ivan Ilyin
This change removes 'pragma index_xinfo' syntax. 'pragma index_info'
now works as 'pragma index_xinfo' and also displays type of columns in
index.
Fixes #3194
---
src/box/sql/parse.y | 2 +-
src/box/sql/pragma.c | 65 +++++++++++++-----------------------
src/box/sql/pragma.h | 12 +++----
test/sql-tap/index-info.test.lua | 71 +++++++++++++++++++++++++++-------------
4 files changed, 75 insertions(+), 75 deletions(-)
diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y
index 2e5f349..1c6f8b7 100644
--- a/src/box/sql/parse.y
+++ b/src/box/sql/parse.y
@@ -1278,7 +1278,7 @@ cmd ::= PRAGMA nm(X) EQ minus_num(Y). {
cmd ::= PRAGMA nm(X) LP minus_num(Y) RP. {
sqlite3Pragma(pParse,&X,&Y,0,1);
}
-cmd ::= PRAGMA nm(X) EQ nm(Z) DOT nm(Y). {
+cmd ::= PRAGMA nm(X) LP nm(Z) DOT nm(Y) RP. {
sqlite3Pragma(pParse,&X,&Y,&Z,0);
}
cmd ::= PRAGMA . {
diff --git a/src/box/sql/pragma.c b/src/box/sql/pragma.c
index 9dab5a7..ec0dff3 100644
--- a/src/box/sql/pragma.c
+++ b/src/box/sql/pragma.c
@@ -447,54 +447,32 @@ sqlite3Pragma(Parse * pParse, Token * pId, /* First part of [schema.]id field */
if (pIdx) {
int i;
int mx;
- if (pPragma->iArg) {
- /* PRAGMA index_xinfo (newer
- * version with more rows and
- * columns)
- */
- pParse->nMem = 6;
- } else {
- /* PRAGMA index_info (legacy
- * version)
- */
- pParse->nMem = 3;
- }
+ pParse->nMem = 7;
mx = index_column_count(pIdx);
assert(pParse->nMem <=
pPragma->nPragCName);
for (i = 0; i < mx; i++) {
i16 cnum = pIdx->aiColumn[i];
assert(pIdx->pTable);
- sqlite3VdbeMultiLoad(v, 1,
- "iis", i,
- cnum,
- cnum <
- 0 ? 0 :
- pIdx->
- pTable->
- def->
- fields[cnum].
- name);
- if (pPragma->iArg) {
- const char *c_n;
- uint32_t id;
- struct coll *coll =
- sql_index_collation(pIdx, i, &id);
- if (coll != NULL)
- c_n = coll_by_id(id)->name;
- else
- c_n = "BINARY";
- enum sort_order sort_order;
- sort_order = sql_index_column_sort_order(pIdx,
- i);
- sqlite3VdbeMultiLoad(v,
- 4,
- "isi",
- sort_order,
- c_n,
- i <
- mx);
- }
+ const char *c_n;
+ uint32_t id;
+ struct coll *coll =
+ sql_index_collation(pIdx, i, &id);
+ if (coll != NULL)
+ c_n = coll_by_id(id)->name;
+ else
+ c_n = "BINARY";
+ enum sort_order sort_order;
+ sort_order = sql_index_column_sort_order(pIdx,
+ i);
+ enum field_type type = pIdx->pTable->
+ def->fields[cnum].type;
+ sqlite3VdbeMultiLoad(v, 1, "iisisis", i,
+ cnum, cnum < 0 ? 0 :
+ pIdx->pTable->def->
+ fields[cnum].name,
+ sort_order, c_n, i < mx,
+ field_type_strs[type]);
sqlite3VdbeAddOp2(v,
OP_ResultRow,
1,
@@ -503,7 +481,8 @@ sqlite3Pragma(Parse * pParse, Token * pId, /* First part of [schema.]id field */
}
}
break;
- }
+ }
+
case PragTyp_INDEX_LIST:{
if (zRight) {
Index *pIdx;
diff --git a/src/box/sql/pragma.h b/src/box/sql/pragma.h
index f966018..25a2d8a 100644
--- a/src/box/sql/pragma.h
+++ b/src/box/sql/pragma.h
@@ -100,6 +100,8 @@ typedef struct PragmaName {
u8 nPragCName; /* Num of col names. 0 means use pragma name */
u32 iArg; /* Extra argument */
} PragmaName;
+/* The order of pragmas in this array is important: it has */
+/* to be sorted. For more info see pragma_locate function. */
static const PragmaName aPragmaName[] = {
{ /* zName: */ "busy_timeout",
/* ePragTyp: */ PragTyp_BUSY_TIMEOUT,
@@ -177,20 +179,14 @@ static const PragmaName aPragmaName[] = {
/* ePragTyp: */ PragTyp_INDEX_INFO,
/* ePragFlg: */
PragFlg_NeedSchema | PragFlg_Result1 | PragFlg_SchemaOpt,
- /* ColNames: */ 10, 3,
- /* iArg: */ 0},
+ /* ColNames: */ 10, 7,
+ /* iArg: */ 1},
{ /* zName: */ "index_list",
/* ePragTyp: */ PragTyp_INDEX_LIST,
/* ePragFlg: */
PragFlg_NeedSchema | PragFlg_Result1 | PragFlg_SchemaOpt,
/* ColNames: */ 19, 5,
/* iArg: */ 0},
- { /* zName: */ "index_xinfo",
- /* ePragTyp: */ PragTyp_INDEX_INFO,
- /* ePragFlg: */
- PragFlg_NeedSchema | PragFlg_Result1 | PragFlg_SchemaOpt,
- /* ColNames: */ 13, 6,
- /* iArg: */ 1},
#endif
#if defined(SQLITE_DEBUG) && !defined(SQLITE_OMIT_PARSER_TRACE)
{ /* zName: */ "parser_trace",
diff --git a/test/sql-tap/index-info.test.lua b/test/sql-tap/index-info.test.lua
index d3bb70e..471b308 100755
--- a/test/sql-tap/index-info.test.lua
+++ b/test/sql-tap/index-info.test.lua
@@ -1,50 +1,75 @@
#!/usr/bin/env tarantool
test = require("sqltester")
-test:plan(4)
+test:plan(8)
test:execsql([[
- CREATE TABLE t1(a INT PRIMARY KEY, b INT UNIQUE, c INT);
- INSERT INTO t1 VALUES (1, 1, 1), (2, 2, 2);
- INSERT INTO t1 VALUES (3, 3, 3), (4, 4, 4);
+ CREATE TABLE t1(a INT PRIMARY KEY, b INT UNIQUE, c INT, d STRING);
+ INSERT INTO t1 VALUES (1, 1, 1, 'abcd'), (2, 2, 2, 'abcde');
+ INSERT INTO t1 VALUES (3, 3, 3, 'abcdef'), (4, 4, 4, 'abcdefg');
CREATE INDEX t1ix1 ON t1(a);
CREATE INDEX t1ix2 ON t1(a, b);
CREATE INDEX t1ix3 ON t1(a, b, c);
+ CREATE INDEX t1ix4 ON t1(b);
+ CREATE INDEX t1ix5 ON t1(b, c);
+ CREATE INDEX t1ix6 ON t1(d);
]])
-test:do_execsql_test(
+test:do_catchsql_test(
"index-info-1.1",
- "PRAGMA index_info = t1.t1ix1;",
+ "PRAGMA index_xinfo (t1.t1ix1);",
{
- -- <index-info-1.1>
- 0, 0, 'A'
- -- <index-info-1.1>
+ 1,"no such pragma: INDEX_XINFO"
})
-test:do_execsql_test(
+test:do_catchsql_test(
"index-info-1.2",
- "PRAGMA index_info = t1.t1ix2;",
+ "PRAGMA index_info = t1.t1ix1;",
{
- -- <index-info-1.1>
- 0, 0, 'A', 1, 1, 'B',
- -- <index-info-1.1>
+ 1,"near \".\": syntax error"
})
test:do_execsql_test(
"index-info-1.3",
- "PRAGMA index_info = t1.t1ix3;",
+ "PRAGMA index_info (t1.t1ix1);",
{
- -- <index-info-1.1>
- 0, 0, 'A', 1, 1, 'B', 2, 2, 'C'
- -- <index-info-1.1>
+ 0, 0, 'A', 0, 'BINARY', 1, 'integer',
})
test:do_execsql_test(
- "index-info-1.1",
- "PRAGMA index_xinfo = t1.t1ix1;",
+ "index-info-1.4",
+ "PRAGMA index_info (t1.t1ix2);",
+ {
+ 0, 0, 'A', 0, 'BINARY', 1, 'integer', 1, 1, 'B', 0, 'BINARY', 1, 'integer',
+ })
+
+
+test:do_execsql_test(
+ "index-info-1.5",
+ "PRAGMA index_info (t1.t1ix3);",
+ {
+ 0, 0, 'A', 0, 'BINARY', 1, 'integer', 1, 1, 'B', 0, 'BINARY', 1, 'integer', 2,
+ 2, 'C', 0, 'BINARY', 1, 'integer',
+ })
+
+test:do_execsql_test(
+ "index-info-1.6",
+ "PRAGMA index_info (t1.t1ix4);",
+ {
+ 0, 1, 'B', 0, 'BINARY', 1, 'integer',
+ })
+
+test:do_execsql_test(
+ "index-info-1.7",
+ "PRAGMA index_info (t1.t1ix5);",
+ {
+ 0, 1, 'B', 0, 'BINARY', 1, 'integer', 1, 2, 'C', 0, 'BINARY', 1, 'integer',
+ })
+
+test:do_execsql_test(
+ "index-info-1.8",
+ "PRAGMA index_info (t1.t1ix6);",
{
- -- <index-info-1.1>
- 0, 0, 'A', 0, 'BINARY', 1,
- -- <index-info-1.1>
+ 0, 3, 'D', 0, 'BINARY', 1, 'scalar',
})
test:finish_test()
--
2.7.4
^ permalink raw reply [flat|nested] 2+ messages in thread
* [tarantool-patches] Re: [PATCH v1] sql: change of PRAGMA INDEX_INFO syntax
2018-06-12 9:32 [tarantool-patches] [PATCH v1] sql: change of PRAGMA INDEX_INFO syntax Ivan Ilyin
@ 2018-06-17 20:06 ` Alexander Turenko
0 siblings, 0 replies; 2+ messages in thread
From: Alexander Turenko @ 2018-06-17 20:06 UTC (permalink / raw)
To: Ivan Ilyin; +Cc: tarantool-patches
Hi Ivan!
See my comments below.
WBR, Alexander Turenko.
On Tue, Jun 12, 2018 at 12:32:20PM +0300, Ivan Ilyin wrote:
> This change removes 'pragma index_xinfo' syntax. 'pragma index_info'
> now works as 'pragma index_xinfo' and also displays type of columns in
> index.
>
> Fixes #3194
> ---
Don't forget to include branch name in the message to
tarantool-patches@.
TARGET=test job fails in CI for your branch: see [1]. It fails before
sql-tap suite and the fail does not related to your changes. But it is
your responsibility to check whether the fail is flaky (restarting this
job should make it green) and bring it into focus of your mentor if the
fail is persistent.
[1]: https://travis-ci.org/tarantool/tarantool/jobs/391176317
> diff --git a/src/box/sql/pragma.c b/src/box/sql/pragma.c
> index 9dab5a7..ec0dff3 100644
> --- a/src/box/sql/pragma.c
> +++ b/src/box/sql/pragma.c
> <...>
> + const char *c_n;
> + uint32_t id;
> + struct coll *coll =
> + sql_index_collation(pIdx, i, &id);
> + if (coll != NULL)
> + c_n = coll_by_id(id)->name;
> + else
> + c_n = "BINARY";
> + enum sort_order sort_order;
> + sort_order = sql_index_column_sort_order(pIdx,
> + i);
> + enum field_type type = pIdx->pTable->
> + def->fields[cnum].type;
> + sqlite3VdbeMultiLoad(v, 1, "iisisis", i,
> + cnum, cnum < 0 ? 0 :
> + pIdx->pTable->def->
> + fields[cnum].name,
> + sort_order, c_n, i < mx,
> + field_type_strs[type]);
Tab width is 8 symbols, please fix indent.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-06-17 20:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-12 9:32 [tarantool-patches] [PATCH v1] sql: change of PRAGMA INDEX_INFO syntax Ivan Ilyin
2018-06-17 20:06 ` [tarantool-patches] " Alexander Turenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox