Tarantool development patches archive
 help / color / mirror / Atom feed
* [tarantool-patches] [PATCH v6 0/7] sql: set column types for EXPLAIN and PRAGMA
@ 2019-02-21 13:00 imeevma
  2019-02-21 13:00 ` [tarantool-patches] [PATCH v6 1/7] sql: remove unused macros from pragma.c and pragma.h imeevma
                   ` (8 more replies)
  0 siblings, 9 replies; 13+ messages in thread
From: imeevma @ 2019-02-21 13:00 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

This patch-set defines the types for the result columns of EXPLAIN
and PRAGMA commands. In addition, it fixes some problems of the
PRAGMA commands that have something to do with their result.

https://github.com/tarantool/tarantool/issues/3832
https://github.com/tarantool/tarantool/tree/imeevma/gh-3832-no-column-types

Changes in sixth version:
  - Rebase to current 2.1
  - New patch that removes gh-3733-pragma.test.lua
  - Other small fixes.

https://www.freelists.org/post/tarantool-patches/PATCH-v1-11-sql-set-column-types-for-EXPLAIN-and-PRAGMA
https://www.freelists.org/post/tarantool-patches/PATCH-v2-06-sql-set-column-types-for-EXPLAIN-and-PRAGMA
https://www.freelists.org/post/tarantool-patches/PATCH-v3-06-sql-set-column-types-for-EXPLAIN-and-PRAGMA
https://www.freelists.org/post/tarantool-patches/PATCH-v4-06-sql-set-column-types-for-EXPLAIN-and-PRAGMA
https://www.freelists.org/post/tarantool-patches/PATCH-v5-06-sql-set-column-types-for-EXPLAIN-and-PRAGMA

Mergen Imeev (7):
  sql: remove unused macros from pragma.c and pragma.h
  sql: fix "PRAGMA parser_trace" result
  sql: Show currently set sql_default_engine
  sql: fix "PRAGMA case_sensitive_like" result
  sql: get results of PRAGMA statement as result set
  sql: set column types for EXPLAIN and PRAGMA
  sql: remove test gh-3733-pragma.test.lua

 src/box/execute.c                    |   5 +-
 src/box/sql/CMakeLists.txt           |   2 -
 src/box/sql/parse.y                  |   6 +-
 src/box/sql/pragma.c                 | 193 +++++++++---------------
 src/box/sql/pragma.h                 | 238 ++++++++++++++++++------------
 src/box/sql/prepare.c                |  53 +++++--
 src/box/sql/printf.c                 |   2 +-
 src/box/sql/select.c                 |  22 +--
 src/box/sql/sqlInt.h                 |  22 +--
 src/box/sql/where.c                  |  46 +++---
 src/box/sql/whereInt.h               |   4 +-
 test/sql-tap/gh-2367-pragma.test.lua |  65 --------
 test/sql-tap/gh-3733-pragma.test.lua | 177 ----------------------
 test/sql-tap/pragma.test.lua         | 278 +++++++++++++++++++++++++++++++++++
 test/sql/engine.cfg                  |   3 +
 test/sql/iproto.result               |  69 +++++++++
 test/sql/iproto.test.lua             |  18 ++-
 test/sql/sql-debug.result            |  45 ++++++
 test/sql/sql-debug.test.lua          |  17 +++
 test/sql/suite.ini                   |   2 +-
 20 files changed, 731 insertions(+), 536 deletions(-)
 delete mode 100755 test/sql-tap/gh-2367-pragma.test.lua
 delete mode 100755 test/sql-tap/gh-3733-pragma.test.lua
 create mode 100755 test/sql-tap/pragma.test.lua
 create mode 100644 test/sql/sql-debug.result
 create mode 100644 test/sql/sql-debug.test.lua

-- 
2.7.4

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [tarantool-patches] [PATCH v6 1/7] sql: remove unused macros from pragma.c and pragma.h
  2019-02-21 13:00 [tarantool-patches] [PATCH v6 0/7] sql: set column types for EXPLAIN and PRAGMA imeevma
@ 2019-02-21 13:00 ` imeevma
  2019-02-21 13:00 ` [tarantool-patches] [PATCH v6 2/7] sql: fix "PRAGMA parser_trace" result imeevma
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: imeevma @ 2019-02-21 13:00 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

Some macros in pragma.c and pragma.h are obsolete because the
values they are checking are no longer used or their usage makes
no sense. Let's remove them.
---
 src/box/sql/CMakeLists.txt |  2 --
 src/box/sql/parse.y        |  6 +++---
 src/box/sql/pragma.c       |  4 ----
 src/box/sql/pragma.h       | 31 ++-----------------------------
 src/box/sql/printf.c       |  2 +-
 src/box/sql/select.c       | 22 +++++++++++-----------
 src/box/sql/sqlInt.h       | 18 +-----------------
 src/box/sql/where.c        | 46 ++++++++++++++++++++--------------------------
 src/box/sql/whereInt.h     |  4 ++--
 9 files changed, 40 insertions(+), 95 deletions(-)

diff --git a/src/box/sql/CMakeLists.txt b/src/box/sql/CMakeLists.txt
index 0db0b3b..5c47e97 100644
--- a/src/box/sql/CMakeLists.txt
+++ b/src/box/sql/CMakeLists.txt
@@ -1,7 +1,5 @@
 if(CMAKE_BUILD_TYPE STREQUAL "Debug")
   add_definitions(-DSQL_DEBUG=1)
-  add_definitions(-DSQL_ENABLE_SELECTTRACE)
-  add_definitions(-DSQL_ENABLE_WHERETRACE)
 endif()
 
 set(EXT_SRC_DIR ${CMAKE_SOURCE_DIR}/extra)
diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y
index 661e695..2f8e5d3 100644
--- a/src/box/sql/parse.y
+++ b/src/box/sql/parse.y
@@ -449,11 +449,11 @@ multiselect_op(A) ::= EXCEPT|INTERSECT(OP).  {A = @OP; /*A-overwrites-OP*/}
 %endif SQL_OMIT_COMPOUND_SELECT
 oneselect(A) ::= SELECT(S) distinct(D) selcollist(W) from(X) where_opt(Y)
                  groupby_opt(P) having_opt(Q) orderby_opt(Z) limit_opt(L). {
-#ifdef SELECTTRACE_ENABLED
+#ifdef SQL_DEBUG
   Token s = S; /*A-overwrites-S*/
 #endif
   A = sqlSelectNew(pParse,W,X,Y,P,Q,Z,D,L.pLimit,L.pOffset);
-#ifdef SELECTTRACE_ENABLED
+#ifdef SQL_DEBUG
   /* Populate the Select.zSelName[] string that is used to help with
   ** query planner debugging, to differentiate between multiple Select
   ** objects in a complex query.
@@ -476,7 +476,7 @@ oneselect(A) ::= SELECT(S) distinct(D) selcollist(W) from(X) where_opt(Y)
       sql_snprintf(sizeof(A->zSelName), A->zSelName, "%.*s", i, z);
     }
   }
-#endif /* SELECTRACE_ENABLED */
+#endif /* SQL_DEBUG */
 }
 oneselect(A) ::= values(A).
 
diff --git a/src/box/sql/pragma.c b/src/box/sql/pragma.c
index 499c677..2eda204 100644
--- a/src/box/sql/pragma.c
+++ b/src/box/sql/pragma.c
@@ -481,7 +481,6 @@ sqlPragma(Parse * pParse, Token * pId,	/* First part of [schema.]id field */
 	/* Jump to the appropriate pragma handler */
 	switch (pPragma->ePragTyp) {
 
-#ifndef SQL_OMIT_FLAG_PRAGMAS
 	case PragTyp_FLAG:{
 			if (zRight == 0) {
 				setPragmaResultColumnNames(v, pPragma);
@@ -510,9 +509,7 @@ sqlPragma(Parse * pParse, Token * pId,	/* First part of [schema.]id field */
 			}
 			break;
 		}
-#endif				/* SQL_OMIT_FLAG_PRAGMAS */
 
-#ifndef SQL_OMIT_SCHEMA_PRAGMAS
 	case PragTyp_TABLE_INFO:
 		sql_pragma_table_info(pParse, zRight);
 		break;
@@ -554,7 +551,6 @@ sqlPragma(Parse * pParse, Token * pId,	/* First part of [schema.]id field */
 		box_iterator_free(iter);
 		break;
 	}
-#endif				/* SQL_OMIT_SCHEMA_PRAGMAS */
 
 	case PragTyp_FOREIGN_KEY_LIST:{
 		if (zRight == NULL)
diff --git a/src/box/sql/pragma.h b/src/box/sql/pragma.h
index d2775ac..088b64d 100644
--- a/src/box/sql/pragma.h
+++ b/src/box/sql/pragma.h
@@ -87,41 +87,32 @@ static const PragmaName aPragmaName[] = {
 	 /* ePragFlg:  */ PragFlg_NoColumns,
 	 /* ColNames:  */ 0, 0,
 	 /* iArg:      */ 0},
-#if !defined(SQL_OMIT_SCHEMA_PRAGMAS)
 	{ /* zName:     */ "collation_list",
 	 /* ePragTyp:  */ PragTyp_COLLATION_LIST,
 	 /* ePragFlg:  */ PragFlg_Result0,
 	 /* ColNames:  */ 19, 2,
 	 /* iArg:      */ 0},
-#endif
-#if !defined(SQL_OMIT_FLAG_PRAGMAS)
 	{ /* zName:     */ "count_changes",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
 	 /* ColNames:  */ 0, 0,
 	 /* iArg:      */ SQL_CountRows},
-#endif
-#if !defined(SQL_OMIT_FLAG_PRAGMAS)
 	{ /* zName:     */ "defer_foreign_keys",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
 	 /* ColNames:  */ 0, 0,
 	 /* iArg:      */ SQL_DeferFKs},
-#endif
 	{ /* zName:     */ "foreign_key_list",
 	 /* ePragTyp:  */ PragTyp_FOREIGN_KEY_LIST,
 	 /* ePragFlg:  */
 	 PragFlg_NeedSchema | PragFlg_Result1 | PragFlg_SchemaOpt,
 	 /* ColNames:  */ 21, 8,
 	 /* iArg:      */ 0},
-#if !defined(SQL_OMIT_FLAG_PRAGMAS)
 	{ /* zName:     */ "full_column_names",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
 	 /* ColNames:  */ 0, 0,
 	 /* iArg:      */ SQL_FullColNames},
-#endif
-#if !defined(SQL_OMIT_SCHEMA_PRAGMAS)
 	{ /* zName:     */ "index_info",
 	 /* ePragTyp:  */ PragTyp_INDEX_INFO,
 	 /* ePragFlg:  */
@@ -134,42 +125,35 @@ static const PragmaName aPragmaName[] = {
 	 PragFlg_NeedSchema | PragFlg_Result1 | PragFlg_SchemaOpt,
 	 /* ColNames:  */ 16, 3,
 	 /* iArg:      */ 0},
-#endif
-#if defined(SQL_DEBUG) && !defined(SQL_OMIT_PARSER_TRACE)
+#if defined(SQL_DEBUG)
 	{ /* zName:     */ "parser_trace",
 	 /* ePragTyp:  */ PragTyp_PARSER_TRACE,
 	 /* ePragFlg:  */ 0,
 	 /* ColNames:  */ 0, 0,
 	 /* iArg:      */ 0},
 #endif
-#if !defined(SQL_OMIT_FLAG_PRAGMAS)
 	{ /* zName:     */ "recursive_triggers",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
 	 /* ColNames:  */ 0, 0,
 	 /* iArg:      */ SQL_RecTriggers},
-#endif
-#if !defined(SQL_OMIT_FLAG_PRAGMAS)
 	{ /* zName:     */ "reverse_unordered_selects",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
 	 /* ColNames:  */ 0, 0,
 	 /* iArg:      */ SQL_ReverseOrder},
-#endif
-#if !defined(SQL_OMIT_FLAG_PRAGMAS) && defined(SQL_ENABLE_SELECTTRACE)
+#if defined(SQL_DEBUG)
 	{ /* zName:     */ "select_trace",
 	/* ePragTyp:  */ PragTyp_FLAG,
 	/* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
 	/* ColNames:  */ 0, 0,
 	/* iArg:      */ SQL_SelectTrace},
 #endif
-#if !defined(SQL_OMIT_FLAG_PRAGMAS)
 	{ /* zName:     */ "short_column_names",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
 	 /* ColNames:  */ 0, 0,
 	 /* iArg:      */ SQL_ShortColNames},
-#endif
 	{ /* zName:     */ "sql_compound_select_limit",
 	/* ePragTyp:  */ PragTyp_COMPOUND_SELECT_LIMIT,
 	/* ePragFlg:  */ PragFlg_Result0,
@@ -180,7 +164,6 @@ static const PragmaName aPragmaName[] = {
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
 	 /* ColNames:  */ 0, 0,
 	 /* iArg:      */ 0},
-#if !defined(SQL_OMIT_FLAG_PRAGMAS)
 #if defined(SQL_DEBUG)
 	{ /* zName:     */ "sql_trace",
 	 /* ePragTyp:  */ PragTyp_FLAG,
@@ -188,24 +171,18 @@ static const PragmaName aPragmaName[] = {
 	 /* ColNames:  */ 0, 0,
 	 /* iArg:      */ SQL_SqlTrace},
 #endif
-#endif
-#if !defined(SQL_OMIT_SCHEMA_PRAGMAS)
 	{ /* zName:     */ "stats",
 	 /* ePragTyp:  */ PragTyp_STATS,
 	 /* ePragFlg:  */
 	 PragFlg_NeedSchema | PragFlg_Result0 | PragFlg_SchemaReq,
 	 /* ColNames:  */ 6, 4,
 	 /* iArg:      */ 0},
-#endif
-#if !defined(SQL_OMIT_SCHEMA_PRAGMAS)
 	{ /* zName:     */ "table_info",
 	 /* ePragTyp:  */ PragTyp_TABLE_INFO,
 	 /* ePragFlg:  */
 	 PragFlg_NeedSchema | PragFlg_Result1 | PragFlg_SchemaOpt,
 	 /* ColNames:  */ 0, 6,
 	 /* iArg:      */ 0},
-#endif
-#if !defined(SQL_OMIT_FLAG_PRAGMAS)
 #if defined(SQL_DEBUG)
 	{ /* zName:     */ "vdbe_addoptrace",
 	 /* ePragTyp:  */ PragTyp_FLAG,
@@ -233,10 +210,6 @@ static const PragmaName aPragmaName[] = {
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
 	 /* ColNames:  */ 0, 0,
 	 /* iArg:      */ SQL_VdbeTrace},
-#endif
-#endif
-#if !defined(SQL_OMIT_FLAG_PRAGMAS) && defined(SQL_ENABLE_WHERETRACE)
-
 	{ /* zName:     */ "where_trace",
 	/* ePragTyp:  */ PragTyp_FLAG,
 	/* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
diff --git a/src/box/sql/printf.c b/src/box/sql/printf.c
index aeb1fc2..e8f66af 100644
--- a/src/box/sql/printf.c
+++ b/src/box/sql/printf.c
@@ -1196,7 +1196,7 @@ sql_log(int iErrCode, const char *zFormat, ...)
 	}
 }
 
-#if (defined(SQL_DEBUG) || defined(SQL_ENABLE_SELECTTRACE))
+#if defined(SQL_DEBUG)
 /*
  * A version of printf() that understands %lld.  Used for debugging.
  */
diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index f469de5..41b3d24 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -45,7 +45,7 @@
 /*
  * Trace output macros
  */
-#ifdef SELECTTRACE_ENABLED
+#ifdef SQL_DEBUG
 /***/ int sqlSelectTrace = 0;
 #define SELECTTRACE(K,P,S,X)  \
   if(sqlSelectTrace&(K))   \
@@ -174,7 +174,7 @@ sqlSelectNew(Parse * pParse,	/* Parsing context */
 	pNew->selFlags = selFlags;
 	pNew->iLimit = 0;
 	pNew->iOffset = 0;
-#ifdef SELECTTRACE_ENABLED
+#ifdef SQL_DEBUG
 	pNew->zSelName[0] = 0;
 	if (user_session->sql_flags & SQL_SelectTrace)
 		sqlSelectTrace = 0xfff;
@@ -208,7 +208,7 @@ sqlSelectNew(Parse * pParse,	/* Parsing context */
 	return pNew;
 }
 
-#ifdef SELECTTRACE_ENABLED
+#ifdef SQL_DEBUG
 /*
  * Set the name of a Select object
  */
@@ -4215,7 +4215,7 @@ flattenSubquery(Parse * pParse,		/* Parsing context */
 	 */
 	sql_select_delete(db, pSub1);
 
-#ifdef SELECTTRACE_ENABLED
+#ifdef SQL_DEBUG
 	if (sqlSelectTrace & 0x100) {
 		SELECTTRACE(0x100, pParse, p, ("After flattening:\n"));
 		sqlTreeViewSelect(0, p, 0);
@@ -5444,7 +5444,7 @@ sqlSelect(Parse * pParse,		/* The parser context */
 		return 1;
 	}
 	memset(&sAggInfo, 0, sizeof(sAggInfo));
-#ifdef SELECTTRACE_ENABLED
+#ifdef SQL_DEBUG
 	pParse->nSelectIndent++;
 	SELECTTRACE(1, pParse, p, ("begin processing:\n"));
 	if (sqlSelectTrace & 0x100) {
@@ -5480,7 +5480,7 @@ sqlSelect(Parse * pParse,		/* The parser context */
 	}
 	assert(p->pEList != 0);
 	isAgg = (p->selFlags & SF_Aggregate) != 0;
-#ifdef SELECTTRACE_ENABLED
+#ifdef SQL_DEBUG
 	if (sqlSelectTrace & 0x100) {
 		SELECTTRACE(0x100, pParse, p, ("after name resolution:\n"));
 		sqlTreeViewSelect(0, p, 0);
@@ -5547,7 +5547,7 @@ sqlSelect(Parse * pParse,		/* The parser context */
 		}
 		sqlVdbeResolveLabel(v, end);
 
-#ifdef SELECTTRACE_ENABLED
+#ifdef SQL_DEBUG
 		SELECTTRACE(1, pParse, p, ("end compound-select processing\n"));
 		pParse->nSelectIndent--;
 #endif
@@ -5595,7 +5595,7 @@ sqlSelect(Parse * pParse,		/* The parser context */
 		    && pushDownWhereTerms(pParse, pSub, p->pWhere,
 					  pItem->iCursor)
 		    ) {
-#ifdef SELECTTRACE_ENABLED
+#ifdef SQL_DEBUG
 			if (sqlSelectTrace & 0x100) {
 				SELECTTRACE(0x100, pParse, p,
 					    ("After WHERE-clause push-down:\n"));
@@ -5700,7 +5700,7 @@ sqlSelect(Parse * pParse,		/* The parser context */
 	pHaving = p->pHaving;
 	sDistinct.isTnct = (p->selFlags & SF_Distinct) != 0;
 
-#ifdef SELECTTRACE_ENABLED
+#ifdef SQL_DEBUG
 	if (sqlSelectTrace & 0x400) {
 		SELECTTRACE(0x400, pParse, p,
 			    ("After all FROM-clause analysis:\n"));
@@ -5733,7 +5733,7 @@ sqlSelect(Parse * pParse,		/* The parser context */
 		 */
 		assert(sDistinct.isTnct);
 
-#ifdef SELECTTRACE_ENABLED
+#ifdef SQL_DEBUG
 		if (sqlSelectTrace & 0x400) {
 			SELECTTRACE(0x400, pParse, p,
 				    ("Transform DISTINCT into GROUP BY:\n"));
@@ -6385,7 +6385,7 @@ sqlSelect(Parse * pParse,		/* The parser context */
 
 	sqlDbFree(db, sAggInfo.aCol);
 	sqlDbFree(db, sAggInfo.aFunc);
-#ifdef SELECTTRACE_ENABLED
+#ifdef SQL_DEBUG
 	SELECTTRACE(1, pParse, p, ("end processing\n"));
 	pParse->nSelectIndent--;
 #endif
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 2830ab6..a52c0bd 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -1290,22 +1290,6 @@ extern const int sqlone;
 #endif
 
 /*
- * SELECTTRACE_ENABLED will be either 1 or 0 depending on whether or not
- * the Select query generator tracing logic is turned on.
- */
-#if defined(SQL_DEBUG) || defined(SQL_ENABLE_SELECTTRACE)
-#define SELECTTRACE_ENABLED
-#else
-#undef SELECTTRACE_ENABLED
-#endif
-
-#if defined(SQL_DEBUG) || defined(SQL_ENABLE_WHERETRACE)
-#define WHERETRACE_ENABLED
-#else
-#undef WHERETRACE_ENABLED
-#endif
-
-/*
  * A convenience macro that returns the number of elements in
  * an array.
  */
@@ -3855,7 +3839,7 @@ Expr *sqlExprDup(sql *, Expr *, int);
 SrcList *sqlSrcListDup(sql *, SrcList *, int);
 IdList *sqlIdListDup(sql *, IdList *);
 Select *sqlSelectDup(sql *, Select *, int);
-#ifdef SELECTTRACE_ENABLED
+#ifdef SQL_DEBUG
 void sqlSelectSetName(Select *, const char *);
 #else
 #define sqlSelectSetName(A,B)
diff --git a/src/box/sql/where.c b/src/box/sql/where.c
index fc05c9f..61b1868 100644
--- a/src/box/sql/where.c
+++ b/src/box/sql/where.c
@@ -50,7 +50,7 @@
 static int whereLoopResize(sql *, WhereLoop *, int);
 
 /* Test variable that can be set to enable WHERE tracing */
-#ifdef WHERETRACE_ENABLED
+#ifdef SQL_DEBUG
 /***/ int sqlWhereTrace = 0; /* -1; */
 #endif
 
@@ -145,7 +145,7 @@ sqlWhereOkOnePass(WhereInfo * pWInfo, int *aiCur)
 	if (pWInfo->eOnePass == ONEPASS_MULTI) {
 		pWInfo->eOnePass = ONEPASS_OFF;
 	}
-#ifdef WHERETRACE_ENABLED
+#ifdef SQL_DEBUG
 	if (sqlWhereTrace && pWInfo->eOnePass != ONEPASS_OFF) {
 		sqlDebugPrintf("%s cursors: %d %d\n",
 				   pWInfo->eOnePass ==
@@ -1491,7 +1491,7 @@ whereRangeScanEst(Parse * pParse,	/* Parsing & code generating context */
 		nNew = 10;
 	if (nNew < nOut)
 		nOut = nNew;
-#if defined(WHERETRACE_ENABLED)
+#if defined(SQL_DEBUG)
 	if (pLoop->nOut > nOut) {
 		WHERETRACE(0x10, ("Range scan lowers nOut from %d to %d\n",
 				  pLoop->nOut, nOut));
@@ -1605,7 +1605,7 @@ whereInScanEst(Parse * pParse,	/* Parsing & code generating context */
 	return rc;
 }
 
-#ifdef WHERETRACE_ENABLED
+#ifdef SQL_DEBUG
 /*
  * Print the content of a WhereTerm object
  */
@@ -1649,9 +1649,7 @@ whereTermPrint(WhereTerm * pTerm, int iTerm)
 		sqlTreeViewExpr(0, pTerm->pExpr, 0);
 	}
 }
-#endif
 
-#ifdef WHERETRACE_ENABLED
 /*
  * Show the complete content of a WhereClause
  */
@@ -1663,9 +1661,7 @@ sqlWhereClausePrint(WhereClause * pWC)
 		whereTermPrint(&pWC->a[i], i);
 	}
 }
-#endif
 
-#ifdef WHERETRACE_ENABLED
 /*
  * Print a WhereLoop object for debugging purposes
  */
@@ -1677,12 +1673,10 @@ whereLoopPrint(WhereLoop * p, WhereClause * pWC)
 	struct SrcList_item *pItem = pWInfo->pTabList->a + p->iTab;
 	struct space_def *space_def = pItem->space->def;
 	Bitmask mAll = (((Bitmask) 1) << (nb * 4)) - 1;
-#ifdef SQL_DEBUG
 	sqlDebugPrintf("%c%2d.%0*llx.%0*llx", p->cId,
 			   p->iTab, nb, p->maskSelf, nb, p->prereq & mAll);
 	sqlDebugPrintf(" %12s",
 			   pItem->zAlias ? pItem->zAlias : space_def->name);
-#endif
 	const char *zName;
 	if (p->index_def != NULL && (zName = p->index_def->name) != NULL) {
 		if (strncmp(zName, "sql_autoindex_", 17) == 0) {
@@ -2043,14 +2037,14 @@ whereLoopInsert(WhereLoopBuilder * pBuilder, WhereLoop * pTemplate)
 	 */
 	if (pBuilder->pOrSet != 0) {
 		if (pTemplate->nLTerm) {
-#ifdef WHERETRACE_ENABLED
+#ifdef SQL_DEBUG
 			u16 n = pBuilder->pOrSet->n;
 			int x =
 #endif
 			    whereOrInsert(pBuilder->pOrSet, pTemplate->prereq,
 					  pTemplate->rRun,
 					  pTemplate->nOut);
-#ifdef WHERETRACE_ENABLED		/* 0x8 */
+#ifdef SQL_DEBUG		/* 0x8 */
 			if (sqlWhereTrace & 0x8) {
 				sqlDebugPrintf(x ? "   or-%d:  " :
 						   "   or-X:  ", n);
@@ -2070,7 +2064,7 @@ whereLoopInsert(WhereLoopBuilder * pBuilder, WhereLoop * pTemplate)
 		/* There already exists a WhereLoop on the list that is better
 		 * than pTemplate, so just ignore pTemplate
 		 */
-#ifdef WHERETRACE_ENABLED		/* 0x8 */
+#ifdef SQL_DEBUG		/* 0x8 */
 		if (sqlWhereTrace & 0x8) {
 			sqlDebugPrintf("   skip: ");
 			whereLoopPrint(pTemplate, pBuilder->pWC);
@@ -2085,7 +2079,7 @@ whereLoopInsert(WhereLoopBuilder * pBuilder, WhereLoop * pTemplate)
 	 * with pTemplate[] if p[] exists, or if p==NULL then allocate a new
 	 * WhereLoop and insert it.
 	 */
-#ifdef WHERETRACE_ENABLED		/* 0x8 */
+#ifdef SQL_DEBUG		/* 0x8 */
 	if (sqlWhereTrace & 0x8) {
 		if (p != 0) {
 			sqlDebugPrintf("replace: ");
@@ -2117,7 +2111,7 @@ whereLoopInsert(WhereLoopBuilder * pBuilder, WhereLoop * pTemplate)
 			if (pToDel == 0)
 				break;
 			*ppTail = pToDel->pNextLoop;
-#ifdef WHERETRACE_ENABLED		/* 0x8 */
+#ifdef SQL_DEBUG		/* 0x8 */
 			if (sqlWhereTrace & 0x8) {
 				sqlDebugPrintf(" delete: ");
 				whereLoopPrint(pToDel, pBuilder->pWC);
@@ -3004,7 +2998,7 @@ whereLoopAddOr(WhereLoopBuilder * pBuilder, Bitmask mPrereq, Bitmask mUnusable)
 					continue;
 				}
 				sCur.n = 0;
-#ifdef WHERETRACE_ENABLED
+#ifdef SQL_DEBUG
 				WHERETRACE(0x200,
 					   ("OR-term %d of %p has %d subterms:\n",
 					    (int)(pOrTerm - pOrWC->a), pTerm,
@@ -3502,7 +3496,7 @@ sqlWhereIsSorted(WhereInfo * pWInfo)
 	return pWInfo->sorted;
 }
 
-#ifdef WHERETRACE_ENABLED
+#ifdef SQL_DEBUG
 /* For debugging use only: */
 static const char *
 wherePathName(WherePath * pPath, int nLoop, WhereLoop * pLast)
@@ -3770,7 +3764,7 @@ wherePathSolver(WhereInfo * pWInfo, LogEst nRowEst)
 						 * paths currently in the best-so-far buffer.  So discard
 						 * this candidate as not viable.
 						 */
-#ifdef WHERETRACE_ENABLED	/* 0x4 */
+#ifdef SQL_DEBUG	/* 0x4 */
 						if (sqlWhereTrace & 0x4) {
 							sqlDebugPrintf("Skip   %s cost=%-3d,%3d order=%c\n",
 									   wherePathName(pFrom, iLoop,
@@ -3793,7 +3787,7 @@ wherePathSolver(WhereInfo * pWInfo, LogEst nRowEst)
 						jj = mxI;
 					}
 					pTo = &aTo[jj];
-#ifdef WHERETRACE_ENABLED	/* 0x4 */
+#ifdef SQL_DEBUG	/* 0x4 */
 					if (sqlWhereTrace & 0x4) {
 						sqlDebugPrintf
 						    ("New    %s cost=%-3d,%3d order=%c\n",
@@ -3813,7 +3807,7 @@ wherePathSolver(WhereInfo * pWInfo, LogEst nRowEst)
 					if (pTo->rCost < rCost
 					    || (pTo->rCost == rCost
 						&& pTo->nRow <= nOut)) {
-#ifdef WHERETRACE_ENABLED	/* 0x4 */
+#ifdef SQL_DEBUG	/* 0x4 */
 						if (sqlWhereTrace & 0x4) {
 							sqlDebugPrintf("Skip   %s cost=%-3d,%3d order=%c",
 									   wherePathName(pFrom, iLoop,
@@ -3838,7 +3832,7 @@ wherePathSolver(WhereInfo * pWInfo, LogEst nRowEst)
 					/* Control reaches here if the candidate path is better than the
 					 * pTo path.  Replace pTo with the candidate.
 					 */
-#ifdef WHERETRACE_ENABLED	/* 0x4 */
+#ifdef SQL_DEBUG	/* 0x4 */
 					if (sqlWhereTrace & 0x4) {
 						sqlDebugPrintf("Update %s cost=%-3d,%3d order=%c",
 								   wherePathName(pFrom, iLoop,
@@ -3887,7 +3881,7 @@ wherePathSolver(WhereInfo * pWInfo, LogEst nRowEst)
 			}
 		}
 
-#ifdef WHERETRACE_ENABLED	/* >=2 */
+#ifdef SQL_DEBUG	/* >=2 */
 		if (sqlWhereTrace & 0x02) {
 			sqlDebugPrintf("---- after round %d ----\n", iLoop);
 			for (ii = 0, pTo = aTo; ii < nTo; ii++, pTo++) {
@@ -4247,7 +4241,7 @@ sqlWhereBegin(Parse * pParse,	/* The parser context */
 	u8 bFordelete = 0;	/* OPFLAG_FORDELETE or zero, as appropriate */
 	struct session *user_session = current_session();
 
-#ifdef WHERETRACE_ENABLED
+#ifdef SQL_DEBUG
 	if (user_session->sql_flags & SQL_WhereTrace)
 		sqlWhereTrace = 0xfff;
 	else
@@ -4410,7 +4404,7 @@ sqlWhereBegin(Parse * pParse,	/* The parser context */
 	}
 
 	/* Construct the WhereLoop objects */
-#if defined(WHERETRACE_ENABLED)
+#if defined(SQL_DEBUG)
 	if (sqlWhereTrace & 0xffff) {
 		sqlDebugPrintf("*** Optimizer Start *** (wctrlFlags: 0x%x",
 				   wctrlFlags);
@@ -4429,7 +4423,7 @@ sqlWhereBegin(Parse * pParse,	/* The parser context */
 		if (rc)
 			goto whereBeginError;
 
-#ifdef WHERETRACE_ENABLED
+#ifdef SQL_DEBUG
 		if (sqlWhereTrace) {	/* Display all of the WhereLoop objects */
 			WhereLoop *p;
 			int i;
@@ -4460,7 +4454,7 @@ sqlWhereBegin(Parse * pParse,	/* The parser context */
 	if (pParse->nErr || NEVER(db->mallocFailed)) {
 		goto whereBeginError;
 	}
-#ifdef WHERETRACE_ENABLED
+#ifdef SQL_DEBUG
 	if (sqlWhereTrace) {
 		sqlDebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut);
 		if (pWInfo->nOBSat > 0) {
diff --git a/src/box/sql/whereInt.h b/src/box/sql/whereInt.h
index 7a0312d..1f4b22a 100644
--- a/src/box/sql/whereInt.h
+++ b/src/box/sql/whereInt.h
@@ -39,7 +39,7 @@
 /*
  * Trace output macros
  */
-#ifdef WHERETRACE_ENABLED
+#ifdef SQL_DEBUG
 /***/ extern int sqlWhereTrace;
 #define WHERETRACE(K,X)  if(sqlWhereTrace&(K)) sqlDebugPrintf X
 #else
@@ -444,7 +444,7 @@ struct WhereInfo {
  * where.c:
  */
 Bitmask sqlWhereGetMask(WhereMaskSet *, int);
-#ifdef WHERETRACE_ENABLED
+#ifdef SQL_DEBUG
 void sqlWhereClausePrint(WhereClause * pWC);
 #endif
 WhereTerm *sqlWhereFindTerm(WhereClause * pWC,	/* The WHERE clause to be searched */
-- 
2.7.4

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [tarantool-patches] [PATCH v6 2/7] sql: fix "PRAGMA parser_trace" result
  2019-02-21 13:00 [tarantool-patches] [PATCH v6 0/7] sql: set column types for EXPLAIN and PRAGMA imeevma
  2019-02-21 13:00 ` [tarantool-patches] [PATCH v6 1/7] sql: remove unused macros from pragma.c and pragma.h imeevma
@ 2019-02-21 13:00 ` imeevma
  2019-02-21 13:00 ` [tarantool-patches] [PATCH v6 3/7] sql: Show currently set sql_default_engine imeevma
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: imeevma @ 2019-02-21 13:00 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

Currently PRAGMA parser_trace returns an empty table. This seems
wrong, since other similar pragmas return their status. Fixed in
the current patch.
---
 src/box/sql/pragma.c        | 59 +++++++++++++++++----------------------------
 src/box/sql/pragma.h        |  7 +++---
 src/box/sql/sqlInt.h        |  2 ++
 test/sql/engine.cfg         |  3 +++
 test/sql/sql-debug.result   | 23 ++++++++++++++++++
 test/sql/sql-debug.test.lua | 12 +++++++++
 test/sql/suite.ini          |  2 +-
 7 files changed, 66 insertions(+), 42 deletions(-)
 create mode 100644 test/sql/sql-debug.result
 create mode 100644 test/sql/sql-debug.test.lua

diff --git a/src/box/sql/pragma.c b/src/box/sql/pragma.c
index 2eda204..1d36655 100644
--- a/src/box/sql/pragma.c
+++ b/src/box/sql/pragma.c
@@ -482,33 +482,30 @@ sqlPragma(Parse * pParse, Token * pId,	/* First part of [schema.]id field */
 	switch (pPragma->ePragTyp) {
 
 	case PragTyp_FLAG:{
-			if (zRight == 0) {
-				setPragmaResultColumnNames(v, pPragma);
-				returnSingleInt(v,
-						(user_session->
-						 sql_flags & pPragma->iArg) !=
-						0);
-			} else {
-				int mask = pPragma->iArg;	/* Mask of bits to set
-								 * or clear.
-								 */
-
-				if (sqlGetBoolean(zRight, 0)) {
-					user_session->sql_flags |= mask;
-				} else {
-					user_session->sql_flags &= ~mask;
-				}
-
-				/* Many of the flag-pragmas modify the code
-				 * generated by the SQL * compiler (eg.
-				 * count_changes). So add an opcode to expire
-				 * all * compiled SQL statements after
-				 * modifying a pragma value.
-				 */
-				sqlVdbeAddOp0(v, OP_Expire);
+		if (zRight == NULL) {
+			setPragmaResultColumnNames(v, pPragma);
+			returnSingleInt(v, (user_session->sql_flags &
+					    pPragma->iArg) != 0);
+		} else {
+			/* Mask of bits to set or clear. */
+			int mask = pPragma->iArg;
+			bool is_pragma_set = sqlGetBoolean(zRight, 0);
+
+			if (is_pragma_set)
+				user_session->sql_flags |= mask;
+			else
+				user_session->sql_flags &= ~mask;
+#if defined(SQL_DEBUG)
+			if (mask == PARSER_TRACE_FLAG) {
+				if (is_pragma_set)
+					sqlParserTrace(stdout, "parser: ");
+				else
+					sqlParserTrace(0, 0);
 			}
-			break;
+#endif
 		}
+		break;
+	}
 
 	case PragTyp_TABLE_INFO:
 		sql_pragma_table_info(pParse, zRight);
@@ -585,18 +582,6 @@ sqlPragma(Parse * pParse, Token * pId,	/* First part of [schema.]id field */
 		}
 		break;
 	}
-#ifndef NDEBUG
-	case PragTyp_PARSER_TRACE:{
-			if (zRight) {
-				if (sqlGetBoolean(zRight, 0)) {
-					sqlParserTrace(stdout, "parser: ");
-				} else {
-					sqlParserTrace(0, 0);
-				}
-			}
-			break;
-		}
-#endif
 
 		/*
 		 * Reinstall the LIKE and functions. The variant
diff --git a/src/box/sql/pragma.h b/src/box/sql/pragma.h
index 088b64d..9c8e79c 100644
--- a/src/box/sql/pragma.h
+++ b/src/box/sql/pragma.h
@@ -13,7 +13,6 @@
 #define PragTyp_INDEX_LIST                    11
 #define PragTyp_STATS                         15
 #define PragTyp_TABLE_INFO                    17
-#define PragTyp_PARSER_TRACE                  24
 #define PragTyp_DEFAULT_ENGINE                25
 #define PragTyp_COMPOUND_SELECT_LIMIT         26
 
@@ -127,10 +126,10 @@ static const PragmaName aPragmaName[] = {
 	 /* iArg:      */ 0},
 #if defined(SQL_DEBUG)
 	{ /* zName:     */ "parser_trace",
-	 /* ePragTyp:  */ PragTyp_PARSER_TRACE,
-	 /* ePragFlg:  */ 0,
+	 /* ePragTyp:  */ PragTyp_FLAG,
+	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
 	 /* ColNames:  */ 0, 0,
-	 /* iArg:      */ 0},
+	 /* iArg:      */ PARSER_TRACE_FLAG},
 #endif
 	{ /* zName:     */ "recursive_triggers",
 	 /* ePragTyp:  */ PragTyp_FLAG,
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index a52c0bd..0d8945d 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -1522,6 +1522,8 @@ struct sql {
  * Possible values for the sql.flags.
  */
 #define SQL_VdbeTrace      0x00000001	/* True to trace VDBE execution */
+/* Debug print info about SQL query as it parsed */
+#define PARSER_TRACE_FLAG  0x00000002
 #define SQL_FullColNames   0x00000004	/* Show full column names on SELECT */
 #define SQL_ShortColNames  0x00000040	/* Show short columns names */
 #define SQL_CountRows      0x00000080	/* Count rows changed by INSERT, */
diff --git a/test/sql/engine.cfg b/test/sql/engine.cfg
index 0007d8d..0fed962 100644
--- a/test/sql/engine.cfg
+++ b/test/sql/engine.cfg
@@ -1,4 +1,7 @@
 {
+    "sql-debug.test.lua": {
+        "memtx": {"engine": "memtx"}
+    },
     "*": {
         "memtx": {"engine": "memtx"},
         "vinyl": {"engine": "vinyl"}
diff --git a/test/sql/sql-debug.result b/test/sql/sql-debug.result
new file mode 100644
index 0000000..9388578
--- /dev/null
+++ b/test/sql/sql-debug.result
@@ -0,0 +1,23 @@
+remote = require('net.box')
+---
+...
+test_run = require('test_run').new()
+---
+...
+--
+-- gh-3832: Some statements do not return column type
+-- Check that "PRAGMA parser_trace" returns 0 or 1 if called
+-- without parameter.
+result = box.sql.execute('PRAGMA parser_trace')
+---
+...
+box.sql.execute('PRAGMA parser_trace = 1')
+---
+...
+box.sql.execute('PRAGMA parser_trace')
+---
+- - [1]
+...
+box.sql.execute('PRAGMA parser_trace = '.. result[1][1])
+---
+...
diff --git a/test/sql/sql-debug.test.lua b/test/sql/sql-debug.test.lua
new file mode 100644
index 0000000..721ef19
--- /dev/null
+++ b/test/sql/sql-debug.test.lua
@@ -0,0 +1,12 @@
+remote = require('net.box')
+test_run = require('test_run').new()
+
+--
+-- gh-3832: Some statements do not return column type
+
+-- Check that "PRAGMA parser_trace" returns 0 or 1 if called
+-- without parameter.
+result = box.sql.execute('PRAGMA parser_trace')
+box.sql.execute('PRAGMA parser_trace = 1')
+box.sql.execute('PRAGMA parser_trace')
+box.sql.execute('PRAGMA parser_trace = '.. result[1][1])
diff --git a/test/sql/suite.ini b/test/sql/suite.ini
index 4504731..ce6ccb7 100644
--- a/test/sql/suite.ini
+++ b/test/sql/suite.ini
@@ -6,4 +6,4 @@ use_unix_sockets = True
 config = engine.cfg
 is_parallel = True
 lua_libs = lua/sql_tokenizer.lua
-release_disabled = errinj.test.lua view_delayed_wal.test.lua
+release_disabled = errinj.test.lua view_delayed_wal.test.lua sql-debug.test.lua
-- 
2.7.4

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [tarantool-patches] [PATCH v6 3/7] sql: Show currently set sql_default_engine
  2019-02-21 13:00 [tarantool-patches] [PATCH v6 0/7] sql: set column types for EXPLAIN and PRAGMA imeevma
  2019-02-21 13:00 ` [tarantool-patches] [PATCH v6 1/7] sql: remove unused macros from pragma.c and pragma.h imeevma
  2019-02-21 13:00 ` [tarantool-patches] [PATCH v6 2/7] sql: fix "PRAGMA parser_trace" result imeevma
@ 2019-02-21 13:00 ` imeevma
  2019-02-21 15:52   ` [tarantool-patches] " Konstantin Osipov
  2019-02-21 13:00 ` [tarantool-patches] [PATCH v6 4/7] sql: fix "PRAGMA case_sensitive_like" result imeevma
                   ` (5 subsequent siblings)
  8 siblings, 1 reply; 13+ messages in thread
From: imeevma @ 2019-02-21 13:00 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

After this patch, "PRAGMA sql_default_engine" called without
arguments will return currently set sql_default_engine.
---
 src/box/sql/pragma.c                 | 18 +++++---
 test/sql-tap/gh-2367-pragma.test.lua | 65 ----------------------------
 test/sql-tap/gh-3733-pragma.test.lua | 13 +-----
 test/sql-tap/pragma.test.lua         | 84 ++++++++++++++++++++++++++++++++++++
 4 files changed, 98 insertions(+), 82 deletions(-)
 delete mode 100755 test/sql-tap/gh-2367-pragma.test.lua
 create mode 100755 test/sql-tap/pragma.test.lua

diff --git a/src/box/sql/pragma.c b/src/box/sql/pragma.c
index 1d36655..097f22b 100644
--- a/src/box/sql/pragma.c
+++ b/src/box/sql/pragma.c
@@ -605,12 +605,20 @@ sqlPragma(Parse * pParse, Token * pId,	/* First part of [schema.]id field */
 			pParse->nErr++;
 			goto pragma_out;
 		}
-		if (sql_default_engine_set(zRight) != 0) {
-			pParse->rc = SQL_TARANTOOL_ERROR;
-			pParse->nErr++;
-			goto pragma_out;
+		if (zRight == NULL) {
+			const char *engine_name =
+				sql_storage_engine_strs[current_session()->
+							sql_default_engine];
+			sqlVdbeLoadString(v, 1, engine_name);
+			sqlVdbeAddOp2(v, OP_ResultRow, 1, 1);
+		} else {
+			if (sql_default_engine_set(zRight) != 0) {
+				pParse->rc = SQL_TARANTOOL_ERROR;
+				pParse->nErr++;
+				goto pragma_out;
+			}
+			sqlVdbeAddOp0(v, OP_Expire);
 		}
-		sqlVdbeAddOp0(v, OP_Expire);
 		break;
 	}
 
diff --git a/test/sql-tap/gh-2367-pragma.test.lua b/test/sql-tap/gh-2367-pragma.test.lua
deleted file mode 100755
index d874bce..0000000
--- a/test/sql-tap/gh-2367-pragma.test.lua
+++ /dev/null
@@ -1,65 +0,0 @@
-#!/usr/bin/env tarantool
-test = require("sqltester")
-
-test:plan(7)
-
-test:do_catchsql_test(
-	"pragma-1.3",
-	[[
-		PRAGMA kek = 'ON';
-	]], {
-		1, "Pragma 'KEK' does not exist"
-	})
-
----
---- gh-2199: SQL default engine pragma
----
-test:do_catchsql_test(
-	"pragma-2.1",
-	[[
-		pragma sql_default_engine='creepy';
-	]], {
-	1, "Space engine 'creepy' does not exist"
-})
-
-test:do_catchsql_test(
-	"pragma-2.2",
-	[[
-		pragma sql_default_engine='vinyl';
-	]], {
-	0
-})
-
-test:do_catchsql_test(
-	"pragma-2.3",
-	[[
-		pragma sql_default_engine='memtx';
-	]], {
-	0
-})
-
-test:do_catchsql_test(
-	"pragma-2.4",
-	[[
-		pragma sql_default_engine;
-	]], {
-	1, 'Illegal parameters, \'sql_default_engine\' was not specified'
-})
-
-test:do_catchsql_test(
-	"pragma-2.5",
-	[[
-		pragma sql_default_engine 'memtx';
-	]], {
-	1, 'near \"\'memtx\'\": syntax error'
-})
-
-test:do_catchsql_test(
-	"pragma-2.5",
-	[[
-		pragma sql_default_engine 1;
-	]], {
-	1, 'near \"1\": syntax error'
-})
-
-test:finish_test()
diff --git a/test/sql-tap/gh-3733-pragma.test.lua b/test/sql-tap/gh-3733-pragma.test.lua
index 991ef82..0f856aa 100755
--- a/test/sql-tap/gh-3733-pragma.test.lua
+++ b/test/sql-tap/gh-3733-pragma.test.lua
@@ -1,7 +1,7 @@
 #!/usr/bin/env tarantool
 test = require("sqltester")
 
-test:plan(17)
+test:plan(16)
 
 ---
 --- Prerequisites
@@ -105,17 +105,6 @@ test:do_execsql_test(
 })
 
 ---
---- pragma sql_default_engine requires value
----
-test:do_catchsql_test(
-	"pragma-6.1",
-	[[
-        pragma sql_default_engine;
-    ]], {
-	1, "Illegal parameters, 'sql_default_engine' was not specified"
-})
-
----
 --- pragma sql_default_engine accepts string values and rejects IDs
 ---
 test:do_catchsql_test(
diff --git a/test/sql-tap/pragma.test.lua b/test/sql-tap/pragma.test.lua
new file mode 100755
index 0000000..5055ba7
--- /dev/null
+++ b/test/sql-tap/pragma.test.lua
@@ -0,0 +1,84 @@
+#!/usr/bin/env tarantool
+test = require("sqltester")
+
+test:plan(8)
+
+test:do_catchsql_test(
+	"pragma-1.3",
+	[[
+		PRAGMA kek = 'ON';
+	]], {
+		1, "Pragma 'KEK' does not exist"
+	})
+
+---
+--- gh-2199: SQL default engine pragma
+---
+test:do_catchsql_test(
+	"pragma-2.1",
+	[[
+		pragma sql_default_engine='creepy';
+	]], {
+	1, "Space engine 'creepy' does not exist"
+})
+
+test:do_catchsql_test(
+	"pragma-2.2",
+	[[
+		pragma sql_default_engine='vinyl';
+	]], {
+	0
+})
+
+test:do_catchsql_test(
+	"pragma-2.3",
+	[[
+		pragma sql_default_engine='memtx';
+	]], {
+	0
+})
+
+test:do_catchsql_test(
+	"pragma-2.4",
+	[[
+		pragma sql_default_engine 'memtx';
+	]], {
+	1, 'near \"\'memtx\'\": syntax error'
+})
+
+test:do_catchsql_test(
+	"pragma-2.5",
+	[[
+		pragma sql_default_engine 1;
+	]], {
+	1, 'near \"1\": syntax error'
+})
+
+--
+-- gh-3832: Some statements do not return column type
+--
+-- Check that "PRAGMA sql_default_engine" called without arguments
+-- returns currently set sql_default_engine.
+test:do_execsql_test(
+	"pragma-3.1",
+	[[
+		pragma sql_default_engine='vinyl';
+		pragma sql_default_engine;
+	]], {
+	-- <pragma-3.1>
+	'vinyl'
+	-- <pragma-3.1>
+})
+
+test:do_execsql_test(
+	"pragma-3.2",
+	[[
+		pragma sql_default_engine='memtx';
+		pragma sql_default_engine;
+	]], {
+	-- <pragma-3.2>
+	'memtx'
+	-- <pragma-3.2>
+})
+
+test:finish_test()
-- 
2.7.4

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [tarantool-patches] [PATCH v6 4/7] sql: fix "PRAGMA case_sensitive_like" result
  2019-02-21 13:00 [tarantool-patches] [PATCH v6 0/7] sql: set column types for EXPLAIN and PRAGMA imeevma
                   ` (2 preceding siblings ...)
  2019-02-21 13:00 ` [tarantool-patches] [PATCH v6 3/7] sql: Show currently set sql_default_engine imeevma
@ 2019-02-21 13:00 ` imeevma
  2019-02-21 13:00 ` [tarantool-patches] [PATCH v6 5/7] sql: get results of PRAGMA statement as result set imeevma
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: imeevma @ 2019-02-21 13:00 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

Currently PRAGMA case_sensitive_like returns nothing. This seems
wrong, since other similar pragmas return their status. Fixed in
the current patch.
---
 src/box/sql/pragma.c         | 21 +++++++--------------
 src/box/sql/pragma.h         |  7 +++----
 src/box/sql/sqlInt.h         |  2 ++
 test/sql-tap/pragma.test.lua | 18 +++++++++++++++++-
 4 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/src/box/sql/pragma.c b/src/box/sql/pragma.c
index 097f22b..c2431bf 100644
--- a/src/box/sql/pragma.c
+++ b/src/box/sql/pragma.c
@@ -503,6 +503,13 @@ sqlPragma(Parse * pParse, Token * pId,	/* First part of [schema.]id field */
 					sqlParserTrace(0, 0);
 			}
 #endif
+			/*
+			 * Reinstall the LIKE and functions. The
+			 * variant of LIKE * used will be case
+			 * sensitive or not depending on the RHS.
+			 */
+			if (mask == LIKE_CASE_SENS_FLAG)
+				sqlRegisterLikeFunctions(db, !is_pragma_set);
 		}
 		break;
 	}
@@ -583,20 +590,6 @@ sqlPragma(Parse * pParse, Token * pId,	/* First part of [schema.]id field */
 		break;
 	}
 
-		/*
-		 * Reinstall the LIKE and functions. The variant
-		 * of LIKE * used will be case sensitive or not
-		 * depending on the RHS.
-		 */
-	case PragTyp_CASE_SENSITIVE_LIKE:{
-			if (zRight) {
-				int is_like_ci =
-					!(sqlGetBoolean(zRight, 0));
-				sqlRegisterLikeFunctions(db, is_like_ci);
-			}
-			break;
-		}
-
 	case PragTyp_DEFAULT_ENGINE: {
 		if (!token_is_string(pValue)) {
 			diag_set(ClientError, ER_ILLEGAL_PARAMS,
diff --git a/src/box/sql/pragma.h b/src/box/sql/pragma.h
index 9c8e79c..31c83b5 100644
--- a/src/box/sql/pragma.h
+++ b/src/box/sql/pragma.h
@@ -5,7 +5,6 @@
  */
 
 /* The various pragma types */
-#define PragTyp_CASE_SENSITIVE_LIKE            2
 #define PragTyp_COLLATION_LIST                 3
 #define PragTyp_FLAG                           5
 #define PragTyp_FOREIGN_KEY_LIST               9
@@ -82,10 +81,10 @@ typedef struct PragmaName {
  */
 static const PragmaName aPragmaName[] = {
 	{ /* zName:     */ "case_sensitive_like",
-	 /* ePragTyp:  */ PragTyp_CASE_SENSITIVE_LIKE,
-	 /* ePragFlg:  */ PragFlg_NoColumns,
+	 /* ePragTyp:  */ PragTyp_FLAG,
+	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
 	 /* ColNames:  */ 0, 0,
-	 /* iArg:      */ 0},
+	 /* iArg:      */ LIKE_CASE_SENS_FLAG},
 	{ /* zName:     */ "collation_list",
 	 /* ePragTyp:  */ PragTyp_COLLATION_LIST,
 	 /* ePragFlg:  */ PragFlg_Result0,
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 0d8945d..ace9b0d 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -1525,6 +1525,8 @@ struct sql {
 /* Debug print info about SQL query as it parsed */
 #define PARSER_TRACE_FLAG  0x00000002
 #define SQL_FullColNames   0x00000004	/* Show full column names on SELECT */
+/* True if LIKE is case sensitive. */
+#define LIKE_CASE_SENS_FLAG 0x00000008
 #define SQL_ShortColNames  0x00000040	/* Show short columns names */
 #define SQL_CountRows      0x00000080	/* Count rows changed by INSERT, */
 					  /*   DELETE, or UPDATE and return */
diff --git a/test/sql-tap/pragma.test.lua b/test/sql-tap/pragma.test.lua
index 5055ba7..935cb96 100755
--- a/test/sql-tap/pragma.test.lua
+++ b/test/sql-tap/pragma.test.lua
@@ -1,7 +1,7 @@
 #!/usr/bin/env tarantool
 test = require("sqltester")
 
-test:plan(8)
+test:plan(9)
 
 test:do_catchsql_test(
 	"pragma-1.3",
@@ -81,4 +81,20 @@ test:do_execsql_test(
 	-- <pragma-3.2>
 })
 
+-- Check that "PRAGMA case_sensitive_like" returns its status
+-- (0 or 1) if called without parameter.
+test:do_test(
+	"pragma-3.3",
+	function()
+		old_value = box.sql.execute('PRAGMA case_sensitive_like')
+		box.sql.execute('PRAGMA case_sensitive_like = 1')
+		new_value = box.sql.execute('PRAGMA case_sensitive_like')
+		box.sql.execute('PRAGMA case_sensitive_like = '.. old_value[1][1])
+		return new_value[1][1]
+	end,
+	-- <pragma-3.3>
+	1
+	-- <pragma-3.3>
+	)
+
 test:finish_test()
-- 
2.7.4

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [tarantool-patches] [PATCH v6 5/7] sql: get results of PRAGMA statement as result set
  2019-02-21 13:00 [tarantool-patches] [PATCH v6 0/7] sql: set column types for EXPLAIN and PRAGMA imeevma
                   ` (3 preceding siblings ...)
  2019-02-21 13:00 ` [tarantool-patches] [PATCH v6 4/7] sql: fix "PRAGMA case_sensitive_like" result imeevma
@ 2019-02-21 13:00 ` imeevma
  2019-02-21 13:00 ` [tarantool-patches] [PATCH v6 6/7] sql: set column types for EXPLAIN and PRAGMA imeevma
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: imeevma @ 2019-02-21 13:00 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

Currently box.sql.execute ('PRAGMA') returns nothing, but prints
list of pragmas and their statuses to stdout. Such strategy is
considered to be wrong since output of this command would be
unavailable for users who redirect stdout, use net box connection
etc. This patch makes the command to return result as the rest of
SQL commands. The result contains only FLAG-type pragmas and their
statuses.
---
 src/box/sql/pragma.c        | 56 ++++++++++++++-------------------------------
 test/sql/sql-debug.result   | 22 ++++++++++++++++++
 test/sql/sql-debug.test.lua |  5 ++++
 3 files changed, 44 insertions(+), 39 deletions(-)

diff --git a/src/box/sql/pragma.c b/src/box/sql/pragma.c
index c2431bf..e166197 100644
--- a/src/box/sql/pragma.c
+++ b/src/box/sql/pragma.c
@@ -168,48 +168,26 @@ pragmaLocate(const char *zName)
 	return lwr > upr ? 0 : &aPragmaName[mid];
 }
 
-#ifdef PRINT_PRAGMA
-#undef PRINT_PRAGMA
-#endif
-#define PRINT_PRAGMA(pragma_name, pragma_flag) do {			       \
-	int nCoolSpaces = 30 - strlen(pragma_name);			       \
-	if (user_session->sql_flags & (pragma_flag)) {			       \
-		printf("%s %*c --  [true] \n", pragma_name, nCoolSpaces, ' '); \
-	} else {							       \
-		printf("%s %*c --  [false] \n", pragma_name, nCoolSpaces, ' ');\
-	}								       \
-} while (0)
-
-#define PRINT_STR_PRAGMA(pragma_name, str_value) do {			       \
-	int nCoolSpaces = 30 - strlen(pragma_name);			       \
-	printf("%s %*c --  '%s' \n", pragma_name, nCoolSpaces, ' ', str_value);\
-} while (0)
-
 static void
-printActivePragmas(struct session *user_session)
+vdbe_emit_pragma_status(struct Parse *parse)
 {
-	int i;
-	for (i = 0; i < ArraySize(aPragmaName); ++i) {
-		switch (aPragmaName[i].ePragTyp) {
-			case PragTyp_FLAG:
-				PRINT_PRAGMA(aPragmaName[i].zName, aPragmaName[i].iArg);
-				break;
-			case PragTyp_DEFAULT_ENGINE: {
-				const char *engine_name =
-					sql_storage_engine_strs[
-						current_session()->
-							sql_default_engine];
-				PRINT_STR_PRAGMA(aPragmaName[i].zName,
-						 engine_name);
-				break;
-			}
-		}
-	}
+	struct Vdbe *v = sqlGetVdbe(parse);
+	struct session *user_session = current_session();
+
+	sqlVdbeSetNumCols(v, 2);
+	sqlVdbeSetColName(v, 0, COLNAME_NAME, "pragma_name", SQL_STATIC);
+	sqlVdbeSetColName(v, 0, COLNAME_DECLTYPE, "TEXT", SQL_STATIC);
+	sqlVdbeSetColName(v, 1, COLNAME_NAME, "pragma_value", SQL_STATIC);
+	sqlVdbeSetColName(v, 1, COLNAME_DECLTYPE, "INTEGER", SQL_STATIC);
 
-	printf("Other available pragmas: \n");
-	for (i = 0; i < ArraySize(aPragmaName); ++i) {
+	parse->nMem = 2;
+	for (int i = 0; i < ArraySize(aPragmaName); ++i) {
 		if (aPragmaName[i].ePragTyp != PragTyp_FLAG)
-			printf("-- %s \n", aPragmaName[i].zName);
+			continue;
+		sqlVdbeAddOp4(v, OP_String8, 0, 1, 0, aPragmaName[i].zName, 0);
+		int val = (user_session->sql_flags & aPragmaName[i].iArg) != 0;
+		sqlVdbeAddOp2(v, OP_Integer, val, 2);
+		sqlVdbeAddOp2(v, OP_ResultRow, 1, 2);
 	}
 }
 
@@ -454,7 +432,7 @@ sqlPragma(Parse * pParse, Token * pId,	/* First part of [schema.]id field */
 
 	zLeft = sqlNameFromToken(db, pId);
 	if (!zLeft) {
-		printActivePragmas(user_session);
+		vdbe_emit_pragma_status(pParse);
 		return;
 	}
 
diff --git a/test/sql/sql-debug.result b/test/sql/sql-debug.result
index 9388578..a857392 100644
--- a/test/sql/sql-debug.result
+++ b/test/sql/sql-debug.result
@@ -21,3 +21,25 @@ box.sql.execute('PRAGMA parser_trace')
 box.sql.execute('PRAGMA parser_trace = '.. result[1][1])
 ---
 ...
+--
+-- Make PRAGMA command return the result as a result set.
+--
+box.sql.execute('PRAGMA')
+---
+- - ['case_sensitive_like', 0]
+  - ['count_changes', 0]
+  - ['defer_foreign_keys', 0]
+  - ['full_column_names', 0]
+  - ['parser_trace', 0]
+  - ['recursive_triggers', 1]
+  - ['reverse_unordered_selects', 0]
+  - ['select_trace', 0]
+  - ['short_column_names', 1]
+  - ['sql_trace', 0]
+  - ['vdbe_addoptrace', 0]
+  - ['vdbe_debug', 0]
+  - ['vdbe_eqp', 0]
+  - ['vdbe_listing', 0]
+  - ['vdbe_trace', 0]
+  - ['where_trace', 0]
+...
diff --git a/test/sql/sql-debug.test.lua b/test/sql/sql-debug.test.lua
index 721ef19..e429c38 100644
--- a/test/sql/sql-debug.test.lua
+++ b/test/sql/sql-debug.test.lua
@@ -10,3 +10,8 @@ result = box.sql.execute('PRAGMA parser_trace')
 box.sql.execute('PRAGMA parser_trace = 1')
 box.sql.execute('PRAGMA parser_trace')
 box.sql.execute('PRAGMA parser_trace = '.. result[1][1])
+
+--
+-- Make PRAGMA command return the result as a result set.
+--
+box.sql.execute('PRAGMA')
-- 
2.7.4

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [tarantool-patches] [PATCH v6 6/7] sql: set column types for EXPLAIN and PRAGMA
  2019-02-21 13:00 [tarantool-patches] [PATCH v6 0/7] sql: set column types for EXPLAIN and PRAGMA imeevma
                   ` (4 preceding siblings ...)
  2019-02-21 13:00 ` [tarantool-patches] [PATCH v6 5/7] sql: get results of PRAGMA statement as result set imeevma
@ 2019-02-21 13:00 ` imeevma
  2019-02-21 13:00 ` [tarantool-patches] [PATCH v6 7/7] sql: remove test gh-3733-pragma.test.lua imeevma
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: imeevma @ 2019-02-21 13:00 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

Currently, EXPLAIN and PRAGMA do not set the column types for the
result. This is incorrect, since any returned row must have a
column type. This patch defines the types for these columns.

Closes #3832
---
 src/box/execute.c        |   5 +-
 src/box/sql/pragma.c     |  37 ++++-----
 src/box/sql/pragma.h     | 193 +++++++++++++++++++++++++++++++++--------------
 src/box/sql/prepare.c    |  53 +++++++++----
 test/sql/iproto.result   |  69 +++++++++++++++++
 test/sql/iproto.test.lua |  18 ++++-
 6 files changed, 279 insertions(+), 96 deletions(-)

diff --git a/src/box/execute.c b/src/box/execute.c
index 7f1a40d..7c77df2 100644
--- a/src/box/execute.c
+++ b/src/box/execute.c
@@ -482,11 +482,12 @@ sql_get_description(struct sql_stmt *stmt, struct obuf *out,
 		const char *name = sql_column_name(stmt, i);
 		const char *type = sql_column_datatype(stmt, i);
 		/*
-		 * Can not fail, since all column names are
-		 * preallocated during prepare phase and the
+		 * Can not fail, since all column names and types
+		 * are preallocated during prepare phase and the
 		 * column_name simply returns them.
 		 */
 		assert(name != NULL);
+		assert(type != NULL);
 		size += mp_sizeof_str(strlen(name));
 		size += mp_sizeof_str(strlen(type));
 		char *pos = (char *) obuf_alloc(out, size);
diff --git a/src/box/sql/pragma.c b/src/box/sql/pragma.c
index e166197..5b0e9f2 100644
--- a/src/box/sql/pragma.c
+++ b/src/box/sql/pragma.c
@@ -112,25 +112,18 @@ sqlGetBoolean(const char *z, u8 dflt)
  * the rest of the file if PRAGMAs are omitted from the build.
  */
 
-/*
- * Set result column names for a pragma.
- */
+/** Set result column names and types for a pragma. */
 static void
-setPragmaResultColumnNames(Vdbe * v,	/* The query under construction */
-			   const PragmaName * pPragma	/* The pragma */
-    )
+vdbe_set_pragma_result_columns(struct Vdbe *v, const struct PragmaName *pragma)
 {
-	u8 n = pPragma->nPragCName;
-	sqlVdbeSetNumCols(v, n == 0 ? 1 : n);
-	if (n == 0) {
-		sqlVdbeSetColName(v, 0, COLNAME_NAME, pPragma->zName,
-				      SQL_STATIC);
-	} else {
-		int i, j;
-		for (i = 0, j = pPragma->iPragCName; i < n; i++, j++) {
-			sqlVdbeSetColName(v, i, COLNAME_NAME, pragCName[j],
-					      SQL_STATIC);
-		}
+	int n = pragma->nPragCName;
+	assert(n > 0);
+	sqlVdbeSetNumCols(v, n);
+	for (int i = 0, j = pragma->iPragCName; i < n; ++i) {
+		sqlVdbeSetColName(v, i, COLNAME_NAME, pragCName[j++],
+				  SQL_STATIC);
+		sqlVdbeSetColName(v, i, COLNAME_DECLTYPE, pragCName[j++],
+				  SQL_STATIC);
 	}
 }
 
@@ -451,17 +444,15 @@ sqlPragma(Parse * pParse, Token * pId,	/* First part of [schema.]id field */
 		goto pragma_out;
 	}
 	/* Register the result column names for pragmas that return results */
-	if ((pPragma->mPragFlg & PragFlg_NoColumns) == 0
-	    && ((pPragma->mPragFlg & PragFlg_NoColumns1) == 0 || zRight == 0)
-	    ) {
-		setPragmaResultColumnNames(v, pPragma);
-	}
+	if ((pPragma->mPragFlg & PragFlg_NoColumns) == 0 &&
+	    ((pPragma->mPragFlg & PragFlg_NoColumns1) == 0 || zRight == NULL))
+		vdbe_set_pragma_result_columns(v, pPragma);
 	/* Jump to the appropriate pragma handler */
 	switch (pPragma->ePragTyp) {
 
 	case PragTyp_FLAG:{
 		if (zRight == NULL) {
-			setPragmaResultColumnNames(v, pPragma);
+			vdbe_set_pragma_result_columns(v, pPragma);
 			returnSingleInt(v, (user_session->sql_flags &
 					    pPragma->iArg) != 0);
 		} else {
diff --git a/src/box/sql/pragma.h b/src/box/sql/pragma.h
index 31c83b5..aa7e7cd 100644
--- a/src/box/sql/pragma.h
+++ b/src/box/sql/pragma.h
@@ -24,46 +24,129 @@
 #define PragFlg_SchemaOpt  0x40	/* Schema restricts name search if present */
 #define PragFlg_SchemaReq  0x80	/* Schema required - "main" is default */
 
-/* Names of columns for pragmas that return multi-column result
- * or that return single-column results where the name of the
- * result column is different from the name of the pragma
+/**
+ * Column names and types for pragmas. The type of the column is
+ * the following value after its name.
  */
 static const char *const pragCName[] = {
 	/* Used by: table_info */
 	/*   0 */ "cid",
-	/*   1 */ "name",
-	/*   2 */ "type",
-	/*   3 */ "notnull",
-	/*   4 */ "dflt_value",
-	/*   5 */ "pk",
+	/*   1 */ "INTEGER",
+	/*   2 */ "name",
+	/*   3 */ "TEXT",
+	/*   4 */ "type",
+	/*   3 */ "TEXT",
+	/*   6 */ "notnull",
+	/*   1 */ "INTEGER",
+	/*   8 */ "dflt_value",
+	/*   9 */ "TEXT",
+	/*  10 */ "pk",
+	/*  11 */ "INTEGER",
 	/* Used by: stats */
-	/*   6 */ "table",
-	/*   7 */ "index",
-	/*   8 */ "width",
-	/*   9 */ "height",
+	/*  12 */ "table",
+	/*  13 */ "TEXT",
+	/*  14 */ "index",
+	/*  15 */ "TEXT",
+	/*  16 */ "width",
+	/*  17 */ "INTEGER",
+	/*  18 */ "height",
+	/*  19 */ "INTEGER",
 	/* Used by: index_info */
-	/*  10 */ "seqno",
-	/*  11 */ "cid",
-	/*  12 */ "name",
-	/*  13 */ "desc",
-	/*  14 */ "coll",
-	/*  15 */ "type",
+	/*  20 */ "seqno",
+	/*  21 */ "INTEGER",
+	/*  22 */ "cid",
+	/*  23 */ "INTEGER",
+	/*  24 */ "name",
+	/*  25 */ "TEXT",
+	/*  26 */ "desc",
+	/*  27 */ "INTEGER",
+	/*  28 */ "coll",
+	/*  29 */ "TEXT",
+	/*  30 */ "type",
+	/*  31 */ "TEXT",
 	/* Used by: index_list */
-	/*  16 */ "seq",
-	/*  17 */ "name",
-	/*  18 */ "unique",
+	/*  32 */ "seq",
+	/*  33 */ "INTEGER",
+	/*  34 */ "name",
+	/*  35 */ "TEXT",
+	/*  36 */ "unique",
+	/*  37 */ "INTEGER",
 	/* Used by: collation_list */
-	/*  19 */ "seq",
-	/*  20 */ "name",
+	/*  38 */ "seq",
+	/*  39 */ "INTEGER",
+	/*  40 */ "name",
+	/*  41 */ "TEXT",
 	/* Used by: foreign_key_list */
-	/*  21 */ "id",
-	/*  22 */ "seq",
-	/*  23 */ "table",
-	/*  24 */ "from",
-	/*  25 */ "to",
-	/*  26 */ "on_update",
-	/*  27 */ "on_delete",
-	/*  28 */ "match",
+	/*  42 */ "id",
+	/*  43 */ "INTEGER",
+	/*  44 */ "seq",
+	/*  45 */ "INTEGER",
+	/*  46 */ "table",
+	/*  47 */ "TEXT",
+	/*  48 */ "from",
+	/*  49 */ "TEXT",
+	/*  50 */ "to",
+	/*  51 */ "TEXT",
+	/*  52 */ "on_update",
+	/*  53 */ "TEXT",
+	/*  54 */ "on_delete",
+	/*  55 */ "TEXT",
+	/*  56 */ "match",
+	/*  57 */ "TEXT",
+	/* Used by: case_sensitive_like */
+	/*  58 */ "case_sensitive_like",
+	/*  59 */ "INTEGER",
+	/* Used by: count_changes */
+	/*  60 */ "count_changes",
+	/*  61 */ "INTEGER",
+	/* Used by: defer_foreign_keys */
+	/*  62 */ "defer_foreign_keys",
+	/*  63 */ "INTEGER",
+	/* Used by: full_column_names */
+	/*  64 */ "full_column_names",
+	/*  65 */ "INTEGER",
+	/* Used by: parser_trace */
+	/*  66 */ "parser_trace",
+	/*  67 */ "INTEGER",
+	/* Used by: recursive_triggers */
+	/*  68 */ "recursive_triggers",
+	/*  69 */ "INTEGER",
+	/* Used by: reverse_unordered_selects */
+	/*  70 */ "reverse_unordered_selects",
+	/*  71 */ "INTEGER",
+	/* Used by: select_trace */
+	/*  72 */ "select_trace",
+	/*  73 */ "INTEGER",
+	/* Used by: short_column_names */
+	/*  74 */ "short_column_names",
+	/*  75 */ "INTEGER",
+	/* Used by: sql_compound_select_limit */
+	/*  76 */ "sql_compound_select_limit",
+	/*  77 */ "INTEGER",
+	/* Used by: sql_default_engine */
+	/*  78 */ "sql_default_engine",
+	/*  79 */ "TEXT",
+	/* Used by: sql_trace */
+	/*  80 */ "sql_trace",
+	/*  81 */ "INTEGER",
+	/* Used by: vdbe_addoptrace */
+	/*  82 */ "vdbe_addoptrace",
+	/*  83 */ "INTEGER",
+	/* Used by: vdbe_debug */
+	/*  84 */ "vdbe_debug",
+	/*  85 */ "INTEGER",
+	/* Used by: vdbe_eqp */
+	/*  86 */ "vdbe_eqp",
+	/*  87 */ "INTEGER",
+	/* Used by: vdbe_listing */
+	/*  88 */ "vdbe_listing",
+	/*  89 */ "INTEGER",
+	/* Used by: vdbe_trace */
+	/*  90 */ "vdbe_trace",
+	/*  91 */ "INTEGER",
+	/* Used by: where_trace */
+	/*  92 */ "where_trace",
+	/*  93 */ "INTEGER",
 };
 
 /* Definitions of all built-in pragmas */
@@ -72,7 +155,7 @@ typedef struct PragmaName {
 	u8 ePragTyp;		/* PragTyp_XXX value */
 	u8 mPragFlg;		/* Zero or more PragFlg_XXX values */
 	u8 iPragCName;		/* Start of column names in pragCName[] */
-	u8 nPragCName;		/* Num of col names. 0 means use pragma name */
+	u8 nPragCName;		/* Num of col names. */
 	u32 iArg;		/* Extra argument */
 } PragmaName;
 /**
@@ -83,97 +166,97 @@ static const PragmaName aPragmaName[] = {
 	{ /* zName:     */ "case_sensitive_like",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 0, 0,
+	 /* ColNames:  */ 58, 1,
 	 /* iArg:      */ LIKE_CASE_SENS_FLAG},
 	{ /* zName:     */ "collation_list",
 	 /* ePragTyp:  */ PragTyp_COLLATION_LIST,
 	 /* ePragFlg:  */ PragFlg_Result0,
-	 /* ColNames:  */ 19, 2,
+	 /* ColNames:  */ 38, 2,
 	 /* iArg:      */ 0},
 	{ /* zName:     */ "count_changes",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 0, 0,
+	 /* ColNames:  */ 60, 1,
 	 /* iArg:      */ SQL_CountRows},
 	{ /* zName:     */ "defer_foreign_keys",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 0, 0,
+	 /* ColNames:  */ 62, 1,
 	 /* iArg:      */ SQL_DeferFKs},
 	{ /* zName:     */ "foreign_key_list",
 	 /* ePragTyp:  */ PragTyp_FOREIGN_KEY_LIST,
 	 /* ePragFlg:  */
 	 PragFlg_NeedSchema | PragFlg_Result1 | PragFlg_SchemaOpt,
-	 /* ColNames:  */ 21, 8,
+	 /* ColNames:  */ 42, 8,
 	 /* iArg:      */ 0},
 	{ /* zName:     */ "full_column_names",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 0, 0,
+	 /* ColNames:  */ 64, 1,
 	 /* iArg:      */ SQL_FullColNames},
 	{ /* zName:     */ "index_info",
 	 /* ePragTyp:  */ PragTyp_INDEX_INFO,
 	 /* ePragFlg:  */
 	 PragFlg_NeedSchema | PragFlg_Result1 | PragFlg_SchemaOpt,
-	 /* ColNames:  */ 10, 6,
+	 /* ColNames:  */ 20, 6,
 	 /* iArg:      */ 1},
 	{ /* zName:     */ "index_list",
 	 /* ePragTyp:  */ PragTyp_INDEX_LIST,
 	 /* ePragFlg:  */
 	 PragFlg_NeedSchema | PragFlg_Result1 | PragFlg_SchemaOpt,
-	 /* ColNames:  */ 16, 3,
+	 /* ColNames:  */ 32, 3,
 	 /* iArg:      */ 0},
 #if defined(SQL_DEBUG)
 	{ /* zName:     */ "parser_trace",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 0, 0,
+	 /* ColNames:  */ 66, 1,
 	 /* iArg:      */ PARSER_TRACE_FLAG},
 #endif
 	{ /* zName:     */ "recursive_triggers",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 0, 0,
+	 /* ColNames:  */ 68, 1,
 	 /* iArg:      */ SQL_RecTriggers},
 	{ /* zName:     */ "reverse_unordered_selects",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 0, 0,
+	 /* ColNames:  */ 70, 1,
 	 /* iArg:      */ SQL_ReverseOrder},
 #if defined(SQL_DEBUG)
 	{ /* zName:     */ "select_trace",
 	/* ePragTyp:  */ PragTyp_FLAG,
 	/* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	/* ColNames:  */ 0, 0,
+	/* ColNames:  */ 72, 1,
 	/* iArg:      */ SQL_SelectTrace},
 #endif
 	{ /* zName:     */ "short_column_names",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 0, 0,
+	 /* ColNames:  */ 73, 1,
 	 /* iArg:      */ SQL_ShortColNames},
 	{ /* zName:     */ "sql_compound_select_limit",
 	/* ePragTyp:  */ PragTyp_COMPOUND_SELECT_LIMIT,
 	/* ePragFlg:  */ PragFlg_Result0,
-	/* ColNames:  */ 0, 0,
+	/* ColNames:  */ 76, 1,
 	/* iArg:      */ 0},
 	{ /* zName:     */ "sql_default_engine",
 	 /* ePragTyp:  */ PragTyp_DEFAULT_ENGINE,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 0, 0,
+	 /* ColNames:  */ 78, 1,
 	 /* iArg:      */ 0},
 #if defined(SQL_DEBUG)
 	{ /* zName:     */ "sql_trace",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 0, 0,
+	 /* ColNames:  */ 80, 1,
 	 /* iArg:      */ SQL_SqlTrace},
 #endif
 	{ /* zName:     */ "stats",
 	 /* ePragTyp:  */ PragTyp_STATS,
 	 /* ePragFlg:  */
 	 PragFlg_NeedSchema | PragFlg_Result0 | PragFlg_SchemaReq,
-	 /* ColNames:  */ 6, 4,
+	 /* ColNames:  */ 12, 4,
 	 /* iArg:      */ 0},
 	{ /* zName:     */ "table_info",
 	 /* ePragTyp:  */ PragTyp_TABLE_INFO,
@@ -185,33 +268,33 @@ static const PragmaName aPragmaName[] = {
 	{ /* zName:     */ "vdbe_addoptrace",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 0, 0,
+	 /* ColNames:  */ 82, 1,
 	 /* iArg:      */ SQL_VdbeAddopTrace},
 	{ /* zName:     */ "vdbe_debug",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 0, 0,
+	 /* ColNames:  */ 84, 1,
 	 /* iArg:      */
 	 SQL_SqlTrace | SQL_VdbeListing | SQL_VdbeTrace},
 	{ /* zName:     */ "vdbe_eqp",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 0, 0,
+	 /* ColNames:  */ 86, 1,
 	 /* iArg:      */ SQL_VdbeEQP},
 	{ /* zName:     */ "vdbe_listing",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 0, 0,
+	 /* ColNames:  */ 88, 1,
 	 /* iArg:      */ SQL_VdbeListing},
 	{ /* zName:     */ "vdbe_trace",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 0, 0,
+	 /* ColNames:  */ 90, 1,
 	 /* iArg:      */ SQL_VdbeTrace},
 	{ /* zName:     */ "where_trace",
 	/* ePragTyp:  */ PragTyp_FLAG,
 	/* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	/* ColNames:  */ 0, 0,
+	/* ColNames:  */ 92, 1,
 	/* iArg:      */ SQL_WhereTrace},
 #endif
 };
diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c
index f6c3429..dd8c5b0 100644
--- a/src/box/sql/prepare.c
+++ b/src/box/sql/prepare.c
@@ -54,7 +54,6 @@ sqlPrepare(sql * db,	/* Database handle. */
 {
 	char *zErrMsg = 0;	/* Error message */
 	int rc = SQL_OK;	/* Result code */
-	int i;			/* Loop counter */
 	Parse sParse;		/* Parsing context */
 	sql_parser_create(&sParse, db);
 	sParse.pReprepare = pReprepare;
@@ -113,24 +112,48 @@ sqlPrepare(sql * db,	/* Database handle. */
 
 	if (rc == SQL_OK && sParse.pVdbe && sParse.explain) {
 		static const char *const azColName[] = {
-			"addr", "opcode", "p1", "p2", "p3", "p4", "p5",
-			    "comment",
-			"selectid", "order", "from", "detail"
+			/*  0 */ "addr",
+			/*  1 */ "INTEGER",
+			/*  2 */ "opcode",
+			/*  3 */ "TEXT",
+			/*  4 */ "p1",
+			/*  5 */ "INTEGER",
+			/*  6 */ "p2",
+			/*  7 */ "INTEGER",
+			/*  8 */ "p3",
+			/*  9 */ "INTEGER",
+			/* 10 */ "p4",
+			/* 11 */ "TEXT",
+			/* 12 */ "p5",
+			/* 13 */ "TEXT",
+			/* 14 */ "comment",
+			/* 15 */ "TEXT",
+			/* 16 */ "selectid",
+			/* 17 */ "INTEGER",
+			/* 18 */ "order",
+			/* 19 */ "INTEGER",
+			/* 20 */ "from",
+			/* 21 */ "INTEGER",
+			/* 22 */ "detail",
+			/* 23 */ "TEXT",
 		};
-		int iFirst, mx;
+
+		int name_first, name_count;
 		if (sParse.explain == 2) {
-			sqlVdbeSetNumCols(sParse.pVdbe, 4);
-			iFirst = 8;
-			mx = 12;
+			name_first = 16;
+			name_count = 4;
 		} else {
-			sqlVdbeSetNumCols(sParse.pVdbe, 8);
-			iFirst = 0;
-			mx = 8;
+			name_first = 0;
+			name_count = 8;
 		}
-		for (i = iFirst; i < mx; i++) {
-			sqlVdbeSetColName(sParse.pVdbe, i - iFirst,
-					      COLNAME_NAME, azColName[i],
-					      SQL_STATIC);
+		sqlVdbeSetNumCols(sParse.pVdbe, name_count);
+		for (int i = 0; i < name_count; i++) {
+			int name_index = 2 * i + name_first;
+			sqlVdbeSetColName(sParse.pVdbe, i, COLNAME_NAME,
+					  azColName[name_index], SQL_STATIC);
+			sqlVdbeSetColName(sParse.pVdbe, i, COLNAME_DECLTYPE,
+					  azColName[name_index + 1],
+					  SQL_STATIC);
 		}
 	}
 
diff --git a/test/sql/iproto.result b/test/sql/iproto.result
index 562e068..da7b40f 100644
--- a/test/sql/iproto.result
+++ b/test/sql/iproto.result
@@ -879,6 +879,75 @@ box.sql.execute('DROP TABLE t1')
 cn:close()
 ---
 ...
+-- gh-3832: Some statements do not return column type
+box.sql.execute('CREATE TABLE t1(id INTEGER PRIMARY KEY)')
+---
+...
+cn = remote.connect(box.cfg.listen)
+---
+...
+-- PRAGMA:
+res = cn:execute("PRAGMA table_info(t1)")
+---
+...
+res.metadata
+---
+- - name: cid
+    type: INTEGER
+  - name: name
+    type: TEXT
+  - name: type
+    type: TEXT
+  - name: notnull
+    type: INTEGER
+  - name: dflt_value
+    type: TEXT
+  - name: pk
+    type: INTEGER
+...
+-- EXPLAIN
+res = cn:execute("EXPLAIN SELECT 1")
+---
+...
+res.metadata
+---
+- - name: addr
+    type: INTEGER
+  - name: opcode
+    type: TEXT
+  - name: p1
+    type: INTEGER
+  - name: p2
+    type: INTEGER
+  - name: p3
+    type: INTEGER
+  - name: p4
+    type: TEXT
+  - name: p5
+    type: TEXT
+  - name: comment
+    type: TEXT
+...
+res = cn:execute("EXPLAIN QUERY PLAN SELECT COUNT(*) FROM t1")
+---
+...
+res.metadata
+---
+- - name: selectid
+    type: INTEGER
+  - name: order
+    type: INTEGER
+  - name: from
+    type: INTEGER
+  - name: detail
+    type: TEXT
+...
+cn:close()
+---
+...
+box.sql.execute('DROP TABLE t1')
+---
+...
 box.schema.user.revoke('guest', 'read,write,execute', 'universe')
 ---
 ...
diff --git a/test/sql/iproto.test.lua b/test/sql/iproto.test.lua
index 5829239..fbdc5a2 100644
--- a/test/sql/iproto.test.lua
+++ b/test/sql/iproto.test.lua
@@ -275,10 +275,26 @@ box.sql.execute('DROP TABLE t1')
 
 cn:close()
 
+-- gh-3832: Some statements do not return column type
+box.sql.execute('CREATE TABLE t1(id INTEGER PRIMARY KEY)')
+cn = remote.connect(box.cfg.listen)
+
+-- PRAGMA:
+res = cn:execute("PRAGMA table_info(t1)")
+res.metadata
+
+-- EXPLAIN
+res = cn:execute("EXPLAIN SELECT 1")
+res.metadata
+res = cn:execute("EXPLAIN QUERY PLAN SELECT COUNT(*) FROM t1")
+res.metadata
+
+cn:close()
+box.sql.execute('DROP TABLE t1')
+
 box.schema.user.revoke('guest', 'read,write,execute', 'universe')
 box.schema.user.revoke('guest', 'create', 'space')
 space = nil
 
 -- Cleanup xlog
 box.snapshot()
-
-- 
2.7.4

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [tarantool-patches] [PATCH v6 7/7] sql: remove test gh-3733-pragma.test.lua
  2019-02-21 13:00 [tarantool-patches] [PATCH v6 0/7] sql: set column types for EXPLAIN and PRAGMA imeevma
                   ` (5 preceding siblings ...)
  2019-02-21 13:00 ` [tarantool-patches] [PATCH v6 6/7] sql: set column types for EXPLAIN and PRAGMA imeevma
@ 2019-02-21 13:00 ` imeevma
  2019-02-25 11:59 ` [tarantool-patches] Re: [PATCH v6 0/7] sql: set column types for EXPLAIN and PRAGMA Vladislav Shpilevoy
  2019-02-27 11:09 ` Kirill Yukhin
  8 siblings, 0 replies; 13+ messages in thread
From: imeevma @ 2019-02-21 13:00 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

---
 test/sql-tap/gh-3733-pragma.test.lua | 166 -------------------------------
 test/sql-tap/pragma.test.lua         | 186 ++++++++++++++++++++++++++++++++++-
 2 files changed, 182 insertions(+), 170 deletions(-)
 delete mode 100755 test/sql-tap/gh-3733-pragma.test.lua

diff --git a/test/sql-tap/gh-3733-pragma.test.lua b/test/sql-tap/gh-3733-pragma.test.lua
deleted file mode 100755
index 0f856aa..0000000
--- a/test/sql-tap/gh-3733-pragma.test.lua
+++ /dev/null
@@ -1,166 +0,0 @@
-#!/usr/bin/env tarantool
-test = require("sqltester")
-
-test:plan(16)
-
----
---- Prerequisites
----
-test:do_execsql_test(
-    "pragma-0.1",
-    [[
-        DROP TABLE IF EXISTS gh3733;
-        CREATE TABLE gh3733(id INT primary key, f float);
-        INSERT INTO gh3733 VALUES(1, 0.1), (2, 0.2), (3, 0.3);
-        CREATE INDEX IDX ON GH3733 (id);
-    ]], {
-
-})
-
----
---- pragma query_only is not supported
----
-test:do_catchsql_test(
-    "pragma-1.1",
-    [[
-        pragma query_only;
-    ]], {
-        1, "Pragma 'QUERY_ONLY' does not exist"
-})
-
----
---- pragma read_uncommitted is not supported
----
-test:do_catchsql_test(
-	"pragma-2.1",
-	[[
-        pragma read_uncommitted;
-    ]], {
-	1, "Pragma 'READ_UNCOMMITTED' does not exist"
-})
-
----
---- pragma index_list returns three columns in a row
----
-test:do_execsql_test(
-	"pragma-3.1",
-	[[
-        pragma index_list(gh3733)
-    ]], {
-	-- <pragma-3.1>
-	0, 'pk_unnamed_GH3733_1', 1, 1, 'IDX', 0
-	-- </pragma-3.1>
-})
-
----
---- pragma index_list returns an empty tuple for unknown table
----
-test:do_execsql_test(
-	"pragma-4.1",
-	[[
-        pragma index_list(fufel);
-    ]], {
-	-- <pragma-4.1>
-	-- </pragma-4.1>
-})
-
----
---- pragma index_info returns an empty tuple for unknown index
----
-test:do_execsql_test(
-	"pragma-5.1",
-	[[
-        pragma index_info(gh3733.IDX)
-    ]], {
-	-- <pragma-5.1>
-	0, 0, 'ID', 0, 'BINARY', 'integer'
-	-- </pragma-5.1>
-})
-
-test:do_execsql_test(
-	"pragma-5.2",
-	[[
-        pragma index_info(no_table);
-    ]], {
-	-- <pragma-5.2>
-	-- </pragma-5.2>
-})
-
-test:do_execsql_test(
-	"pragma-5.3",
-	[[
-        pragma index_info(wrong_table.IDX);
-    ]], {
-	-- <pragma-5.3>
-	-- </pragma-5.3>
-})
-
-test:do_execsql_test(
-	"pragma-5.4",
-	[[
-        pragma index_info(gh3733.wrong_index);
-    ]], {
-	-- <pragma-5.4>
-	-- </pragma-5.4>
-})
-
----
---- pragma sql_default_engine accepts string values and rejects IDs
----
-test:do_catchsql_test(
-	"pragma-7.1",
-	[[
-        pragma sql_default_engine(the_engine);
-    ]], {
-	1, "Illegal parameters, string value is expected"
-})
-test:do_catchsql_test(
-	"pragma-7.2",
-	[[
-        pragma sql_default_engine(THE_ENGINE);
-    ]], {
-	1, "Illegal parameters, string value is expected"
-})
-test:do_catchsql_test(
-	"pragma-7.3",
-	[[
-        pragma sql_default_engine("THE_ENGINE");
-    ]], {
-	1, "Illegal parameters, string value is expected"
-})
-
-test:do_catchsql_test(
-	"pragma-7.4",
-	[[
-        pragma sql_default_engine('THE_ENGINE');
-    ]], {
-	1, "Space engine 'THE_ENGINE' does not exist"
-})
-
-test:do_catchsql_test(
-	"pragma-7.5",
-	[[
-        pragma sql_default_engine(memtx);
-    ]], {
-	1, "Illegal parameters, string value is expected"
-})
-
-test:do_catchsql_test(
-	"pragma-7.6",
-	[[
-        pragma sql_default_engine("memtx");
-    ]], {
-	1, "Illegal parameters, string value is expected"
-})
-
-test:do_execsql_test(
-	"pragma-7.7",
-	[[
-        pragma sql_default_engine('memtx');
-    ]], {
-	-- <pragma-7.7>
-
-	-- </pragma-7.7>
-})
-
-test:finish_test()
diff --git a/test/sql-tap/pragma.test.lua b/test/sql-tap/pragma.test.lua
index 935cb96..975a0e9 100755
--- a/test/sql-tap/pragma.test.lua
+++ b/test/sql-tap/pragma.test.lua
@@ -1,7 +1,7 @@
 #!/usr/bin/env tarantool
 test = require("sqltester")
 
-test:plan(9)
+test:plan(24)
 
 test:do_catchsql_test(
 	"pragma-1.3",
@@ -67,7 +67,7 @@ test:do_execsql_test(
 	]], {
 	-- <pragma-3.1>
 	'vinyl'
-	-- <pragma-3.1>
+	-- </pragma-3.1>
 })
 
 test:do_execsql_test(
@@ -78,7 +78,7 @@ test:do_execsql_test(
 	]], {
 	-- <pragma-3.2>
 	'memtx'
-	-- <pragma-3.2>
+	-- </pragma-3.2>
 })
 
 -- Check that "PRAGMA case_sensitive_like" returns its status
@@ -94,7 +94,185 @@ test:do_test(
 	end,
 	-- <pragma-3.3>
 	1
-	-- <pragma-3.3>
+	-- </pragma-3.3>
 	)
 
+--
+-- gh-3733: remove useless or obsolete pragmas
+--
+
+---
+--- Prerequisites
+---
+test:execsql(
+	[[
+		DROP TABLE IF EXISTS gh3733;
+		CREATE TABLE gh3733(id INT primary key, f float);
+		INSERT INTO gh3733 VALUES(1, 0.1), (2, 0.2), (3, 0.3);
+		CREATE INDEX IDX ON GH3733 (id);
+	]])
+
+---
+--- pragma query_only is not supported
+---
+test:do_catchsql_test(
+	"pragma-4.1",
+	[[
+		pragma query_only;
+	]], {
+	-- <pragma-4.1>
+	1, "Pragma 'QUERY_ONLY' does not exist"
+	-- </pragma-4.1>
+})
+
+---
+--- pragma read_uncommitted is not supported
+---
+test:do_catchsql_test(
+	"pragma-5.1",
+	[[
+		pragma read_uncommitted;
+	]], {
+	-- <pragma-5.1>
+	1, "Pragma 'READ_UNCOMMITTED' does not exist"
+	-- </pragma-5.1>
+})
+
+---
+--- pragma index_list returns three columns in a row
+---
+test:do_execsql_test(
+	"pragma-6.1",
+	[[
+		pragma index_list(gh3733)
+	]], {
+	-- <pragma-6.1>
+	0, 'pk_unnamed_GH3733_1', 1, 1, 'IDX', 0
+	-- </pragma-6.1>
+})
+
+---
+--- pragma index_list returns an empty tuple for unknown table
+---
+test:do_execsql_test(
+	"pragma-7.1",
+	[[
+		pragma index_list(fufel);
+	]], {
+	-- <pragma-7.1>
+	-- </pragma-7.1>
+})
+
+---
+--- pragma index_info returns an empty tuple for unknown index
+---
+test:do_execsql_test(
+	"pragma-8.1",
+	[[
+		pragma index_info(gh3733.IDX)
+	]], {
+	-- <pragma-8.1>
+	0, 0, 'ID', 0, 'BINARY', 'integer'
+	-- </pragma-8.1>
+})
+
+test:do_execsql_test(
+	"pragma-8.2",
+	[[
+		pragma index_info(no_table);
+	]], {
+	-- <pragma-8.2>
+	-- </pragma-8.2>
+})
+
+test:do_execsql_test(
+	"pragma-8.3",
+	[[
+		pragma index_info(wrong_table.IDX);
+	]], {
+	-- <pragma-8.3>
+	-- </pragma-8.3>
+})
+
+test:do_execsql_test(
+	"pragma-8.4",
+	[[
+		pragma index_info(gh3733.wrong_index);
+	]], {
+	-- <pragma-8.4>
+	-- </pragma-8.4>
+})
+
+---
+--- pragma sql_default_engine accepts string values and rejects IDs
+---
+test:do_catchsql_test(
+	"pragma-9.1",
+	[[
+		pragma sql_default_engine(the_engine);
+	]], {
+	-- <pragma-9.1>
+	1, "Illegal parameters, string value is expected"
+	-- </pragma-9.1>
+})
+
+test:do_catchsql_test(
+	"pragma-9.2",
+	[[
+		pragma sql_default_engine(THE_ENGINE);
+	]], {
+	-- <pragma-9.2>
+	1, "Illegal parameters, string value is expected"
+	-- </pragma-9.2>
+})
+
+test:do_catchsql_test(
+	"pragma-9.3",
+	[[
+		pragma sql_default_engine("THE_ENGINE");
+	]], {
+	-- <pragma-9.3>
+	1, "Illegal parameters, string value is expected"
+	-- </pragma-9.3>
+})
+
+test:do_catchsql_test(
+	"pragma-9.4",
+	[[
+		pragma sql_default_engine('THE_ENGINE');
+	]], {
+	-- <pragma-9.4>
+	1, "Space engine 'THE_ENGINE' does not exist"
+	-- </pragma-9.4>
+})
+
+test:do_catchsql_test(
+	"pragma-9.5",
+	[[
+		pragma sql_default_engine(memtx);
+	]], {
+	-- <pragma-9.5>
+	1, "Illegal parameters, string value is expected"
+	-- </pragma-9.5>
+})
+
+test:do_catchsql_test(
+	"pragma-9.6",
+	[[
+		pragma sql_default_engine("memtx");
+	]], {
+	-- <pragma-9.6>
+	1, "Illegal parameters, string value is expected"
+	-- </pragma-9.6>
+})
+
+test:do_execsql_test(
+	"pragma-9.7",
+	[[
+		pragma sql_default_engine('memtx');
+	]], {
+	-- <pragma-9.7>
+	-- </pragma-9.7>
+})
+
 test:finish_test()
-- 
2.7.4

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [tarantool-patches] Re: [PATCH v6 3/7] sql: Show currently set sql_default_engine
  2019-02-21 13:00 ` [tarantool-patches] [PATCH v6 3/7] sql: Show currently set sql_default_engine imeevma
@ 2019-02-21 15:52   ` Konstantin Osipov
  0 siblings, 0 replies; 13+ messages in thread
From: Konstantin Osipov @ 2019-02-21 15:52 UTC (permalink / raw)
  To: tarantool-patches; +Cc: v.shpilevoy

* imeevma@tarantool.org <imeevma@tarantool.org> [19/02/21 16:48]:
> +				sql_storage_engine_strs[current_session()->
> +							sql_default_engine];

Please ditch sql_storage_engine_strs ina separate patch.

Engine name can be retrieved by engine pointer or by enum engine
id, you can use engine_find() to find engine by name.


-- 
Konstantin Osipov, Moscow, Russia, +7 903 626 22 32
http://tarantool.io - www.twitter.com/kostja_osipov

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [tarantool-patches] Re: [PATCH v6 0/7] sql: set column types for EXPLAIN and PRAGMA
  2019-02-21 13:00 [tarantool-patches] [PATCH v6 0/7] sql: set column types for EXPLAIN and PRAGMA imeevma
                   ` (6 preceding siblings ...)
  2019-02-21 13:00 ` [tarantool-patches] [PATCH v6 7/7] sql: remove test gh-3733-pragma.test.lua imeevma
@ 2019-02-25 11:59 ` Vladislav Shpilevoy
  2019-02-25 21:05   ` Imeev Mergen
  2019-02-27 11:09 ` Kirill Yukhin
  8 siblings, 1 reply; 13+ messages in thread
From: Vladislav Shpilevoy @ 2019-02-25 11:59 UTC (permalink / raw)
  To: tarantool-patches, imeevma

Hi! Thanks for the fixes!

On 21/02/2019 16:00, imeevma@tarantool.org wrote:
> This patch-set defines the types for the result columns of EXPLAIN
> and PRAGMA commands. In addition, it fixes some problems of the
> PRAGMA commands that have something to do with their result.
> 
> https://github.com/tarantool/tarantool/issues/3832
> https://github.com/tarantool/tarantool/tree/imeevma/gh-3832-no-column-types
> 
> Changes in sixth version:
>    - Rebase to current 2.1
>    - New patch that removes gh-3733-pragma.test.lua
>    - Other small fixes.

Neither of these things are worth sending new patches in a
new thread with a bumped version. Please, next time try to
keep the discussion in the same thread if no drastic changes.

The patchset is good now.

Now, please, add docbot request to the last commit,
describing changes in PRAGMA output. Including all the
previous commits too. I mean, that 'PRAGMA' now returns
name/value pairs, how now 'EXPLAIN' works, that
'sql_default_engine' and 'case_sensitive_like' return a
current value, what does 'parser_trace', etc.

Do not resend a new version. Just add a docbot request,
signal here about it, and I will say LGTM.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [tarantool-patches] Re: [PATCH v6 0/7] sql: set column types for EXPLAIN and PRAGMA
  2019-02-25 11:59 ` [tarantool-patches] Re: [PATCH v6 0/7] sql: set column types for EXPLAIN and PRAGMA Vladislav Shpilevoy
@ 2019-02-25 21:05   ` Imeev Mergen
  2019-02-26  9:33     ` Vladislav Shpilevoy
  0 siblings, 1 reply; 13+ messages in thread
From: Imeev Mergen @ 2019-02-25 21:05 UTC (permalink / raw)
  To: Vladislav Shpilevoy, tarantool-patches

Hi! Thank you for review!

On 2/25/19 2:59 PM, Vladislav Shpilevoy wrote:
> Hi! Thanks for the fixes!
>
> On 21/02/2019 16:00, imeevma@tarantool.org wrote:
>> This patch-set defines the types for the result columns of EXPLAIN
>> and PRAGMA commands. In addition, it fixes some problems of the
>> PRAGMA commands that have something to do with their result.
>>
>> https://github.com/tarantool/tarantool/issues/3832
>> https://github.com/tarantool/tarantool/tree/imeevma/gh-3832-no-column-types 
>>
>>
>> Changes in sixth version:
>>    - Rebase to current 2.1
>>    - New patch that removes gh-3733-pragma.test.lua
>>    - Other small fixes.
>
> Neither of these things are worth sending new patches in a
> new thread with a bumped version. Please, next time try to
> keep the discussion in the same thread if no drastic changes.
>
> The patchset is good now.
>
> Now, please, add docbot request to the last commit,
> describing changes in PRAGMA output. Including all the
> previous commits too. I mean, that 'PRAGMA' now returns
> name/value pairs, how now 'EXPLAIN' works, that
> 'sql_default_engine' and 'case_sensitive_like' return a
> current value, what does 'parser_trace', etc.
>
> Do not resend a new version. Just add a docbot request,
> signal here about it, and I will say LGTM.
Fixed, added a docbot request and rebased to current 2.1.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [tarantool-patches] Re: [PATCH v6 0/7] sql: set column types for EXPLAIN and PRAGMA
  2019-02-25 21:05   ` Imeev Mergen
@ 2019-02-26  9:33     ` Vladislav Shpilevoy
  0 siblings, 0 replies; 13+ messages in thread
From: Vladislav Shpilevoy @ 2019-02-26  9:33 UTC (permalink / raw)
  To: tarantool-patches, Imeev Mergen, Kirill Yukhin

LGTM.

On 26/02/2019 00:05, Imeev Mergen wrote:
> Hi! Thank you for review!
> 
> On 2/25/19 2:59 PM, Vladislav Shpilevoy wrote:
>> Hi! Thanks for the fixes!
>>
>> On 21/02/2019 16:00, imeevma@tarantool.org wrote:
>>> This patch-set defines the types for the result columns of EXPLAIN
>>> and PRAGMA commands. In addition, it fixes some problems of the
>>> PRAGMA commands that have something to do with their result.
>>>
>>> https://github.com/tarantool/tarantool/issues/3832
>>> https://github.com/tarantool/tarantool/tree/imeevma/gh-3832-no-column-types
>>>
>>> Changes in sixth version:
>>>    - Rebase to current 2.1
>>>    - New patch that removes gh-3733-pragma.test.lua
>>>    - Other small fixes.
>>
>> Neither of these things are worth sending new patches in a
>> new thread with a bumped version. Please, next time try to
>> keep the discussion in the same thread if no drastic changes.
>>
>> The patchset is good now.
>>
>> Now, please, add docbot request to the last commit,
>> describing changes in PRAGMA output. Including all the
>> previous commits too. I mean, that 'PRAGMA' now returns
>> name/value pairs, how now 'EXPLAIN' works, that
>> 'sql_default_engine' and 'case_sensitive_like' return a
>> current value, what does 'parser_trace', etc.
>>
>> Do not resend a new version. Just add a docbot request,
>> signal here about it, and I will say LGTM.
> Fixed, added a docbot request and rebased to current 2.1.
> 
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [tarantool-patches] Re: [PATCH v6 0/7] sql: set column types for EXPLAIN and PRAGMA
  2019-02-21 13:00 [tarantool-patches] [PATCH v6 0/7] sql: set column types for EXPLAIN and PRAGMA imeevma
                   ` (7 preceding siblings ...)
  2019-02-25 11:59 ` [tarantool-patches] Re: [PATCH v6 0/7] sql: set column types for EXPLAIN and PRAGMA Vladislav Shpilevoy
@ 2019-02-27 11:09 ` Kirill Yukhin
  8 siblings, 0 replies; 13+ messages in thread
From: Kirill Yukhin @ 2019-02-27 11:09 UTC (permalink / raw)
  To: tarantool-patches; +Cc: v.shpilevoy

Hello,

On 21 Feb 16:00, imeevma@tarantool.org wrote:
> This patch-set defines the types for the result columns of EXPLAIN
> and PRAGMA commands. In addition, it fixes some problems of the
> PRAGMA commands that have something to do with their result.
> 
> https://github.com/tarantool/tarantool/issues/3832
> https://github.com/tarantool/tarantool/tree/imeevma/gh-3832-no-column-types

I've checked your patches into 2.1 branch.

--
Regards, Kirill Yukhin

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2019-02-27 11:09 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-21 13:00 [tarantool-patches] [PATCH v6 0/7] sql: set column types for EXPLAIN and PRAGMA imeevma
2019-02-21 13:00 ` [tarantool-patches] [PATCH v6 1/7] sql: remove unused macros from pragma.c and pragma.h imeevma
2019-02-21 13:00 ` [tarantool-patches] [PATCH v6 2/7] sql: fix "PRAGMA parser_trace" result imeevma
2019-02-21 13:00 ` [tarantool-patches] [PATCH v6 3/7] sql: Show currently set sql_default_engine imeevma
2019-02-21 15:52   ` [tarantool-patches] " Konstantin Osipov
2019-02-21 13:00 ` [tarantool-patches] [PATCH v6 4/7] sql: fix "PRAGMA case_sensitive_like" result imeevma
2019-02-21 13:00 ` [tarantool-patches] [PATCH v6 5/7] sql: get results of PRAGMA statement as result set imeevma
2019-02-21 13:00 ` [tarantool-patches] [PATCH v6 6/7] sql: set column types for EXPLAIN and PRAGMA imeevma
2019-02-21 13:00 ` [tarantool-patches] [PATCH v6 7/7] sql: remove test gh-3733-pragma.test.lua imeevma
2019-02-25 11:59 ` [tarantool-patches] Re: [PATCH v6 0/7] sql: set column types for EXPLAIN and PRAGMA Vladislav Shpilevoy
2019-02-25 21:05   ` Imeev Mergen
2019-02-26  9:33     ` Vladislav Shpilevoy
2019-02-27 11:09 ` Kirill Yukhin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox