Tarantool development patches archive
 help / color / mirror / Atom feed
From: imeevma@tarantool.org
To: v.shpilevoy@tarantool.org
Cc: tarantool-patches@freelists.org
Subject: [tarantool-patches] [PATCH v6 2/7] sql: fix "PRAGMA parser_trace" result
Date: Thu, 21 Feb 2019 16:00:45 +0300	[thread overview]
Message-ID: <3330c181b0cca9143b66eac2fd57f2a774194c20.1550753723.git.imeevma@gmail.com> (raw)
In-Reply-To: <cover.1550753723.git.imeevma@gmail.com>

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

  parent reply	other threads:[~2019-02-21 13:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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=3330c181b0cca9143b66eac2fd57f2a774194c20.1550753723.git.imeevma@gmail.com \
    --to=imeevma@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [tarantool-patches] [PATCH v6 2/7] sql: fix "PRAGMA parser_trace" result' \
    /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