Tarantool development patches archive
 help / color / mirror / Atom feed
From: imeevma@tarantool.org
To: v.shpilevoy@tarantool.org
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH 2/5] sql: remove PRAGMA "short_column_names"
Date: Wed, 27 Nov 2019 13:13:30 +0300	[thread overview]
Message-ID: <8a50eca87b5b2e87426771ac8c6b2c498b7f4d97.1574849451.git.imeevma@gmail.com> (raw)
In-Reply-To: <cover.1574849451.git.imeevma@gmail.com>

The pragmas "short_column_names" and "full_column_names" allow us
to use three ways to display the column name in metadata:
1) If both are turned off, then the column name was shown as it
was written by the user.
2) If "short_column_names" = OFF and "full_column_names" = ON,
then the column name is displayed as <table name>.<column name>.
3) If "short_column_names" = ON, then the column name is displayed
as <column name>. This is the default option.

But we need only two ways to show the column name:
1) Show the column name as <column name>. This should be the
default option.
2) Show the column name as <table name>.<column name>.

In this regard, we need only one of these pragmas.

Part of #4511
---
 src/box/sql.c                 |  3 +--
 src/box/sql/pragma.h          | 62 +++++++++++++++++++------------------------
 src/box/sql/select.c          | 16 +++--------
 src/box/sql/sqlInt.h          |  1 -
 test/sql-tap/colname.test.lua | 37 +++++++-------------------
 test/sql-tap/select1.test.lua | 13 +++------
 test/sql/sql-debug.result     |  1 -
 7 files changed, 44 insertions(+), 89 deletions(-)

diff --git a/src/box/sql.c b/src/box/sql.c
index f1df555..7c1035c 100644
--- a/src/box/sql.c
+++ b/src/box/sql.c
@@ -59,8 +59,7 @@ static sql *db = NULL;
 
 static const char nil_key[] = { 0x90 }; /* Empty MsgPack array. */
 
-static const uint32_t default_sql_flags = SQL_ShortColNames
-					  | SQL_EnableTrigger
+static const uint32_t default_sql_flags = SQL_EnableTrigger
 					  | SQL_AutoIndex
 					  | SQL_RecTriggers;
 
diff --git a/src/box/sql/pragma.h b/src/box/sql/pragma.h
index 511de23..f337f0b 100644
--- a/src/box/sql/pragma.h
+++ b/src/box/sql/pragma.h
@@ -111,36 +111,33 @@ static const char *const pragCName[] = {
 	/* Used by: select_trace */
 	/*  68 */ "select_trace",
 	/*  69 */ "integer",
-	/* Used by: short_column_names */
-	/*  70 */ "short_column_names",
-	/*  71 */ "integer",
 	/* Used by: sql_compound_select_limit */
-	/*  72 */ "sql_compound_select_limit",
-	/*  73 */ "integer",
+	/*  70 */ "sql_compound_select_limit",
+	/*  71 */ "integer",
 	/* Used by: sql_default_engine */
-	/*  74 */ "sql_default_engine",
-	/*  75 */ "text",
+	/*  72 */ "sql_default_engine",
+	/*  73 */ "text",
 	/* Used by: sql_trace */
-	/*  76 */ "sql_trace",
-	/*  77 */ "integer",
+	/*  74 */ "sql_trace",
+	/*  75 */ "integer",
 	/* Used by: vdbe_addoptrace */
-	/*  78 */ "vdbe_addoptrace",
-	/*  79 */ "integer",
+	/*  76 */ "vdbe_addoptrace",
+	/*  77 */ "integer",
 	/* Used by: vdbe_debug */
-	/*  80 */ "vdbe_debug",
-	/*  81 */ "integer",
+	/*  78 */ "vdbe_debug",
+	/*  79 */ "integer",
 	/* Used by: vdbe_eqp */
-	/*  82 */ "vdbe_eqp",
-	/*  83 */ "integer",
+	/*  80 */ "vdbe_eqp",
+	/*  81 */ "integer",
 	/* Used by: vdbe_listing */
-	/*  84 */ "vdbe_listing",
-	/*  85 */ "integer",
+	/*  82 */ "vdbe_listing",
+	/*  83 */ "integer",
 	/* Used by: vdbe_trace */
-	/*  86 */ "vdbe_trace",
-	/*  87 */ "integer",
+	/*  84 */ "vdbe_trace",
+	/*  85 */ "integer",
 	/* Used by: where_trace */
-	/*  88 */ "where_trace",
-	/*  89 */ "integer",
+	/*  86 */ "where_trace",
+	/*  87 */ "integer",
 };
 
 /* Definitions of all built-in pragmas */
@@ -214,26 +211,21 @@ static const PragmaName aPragmaName[] = {
 	/* ColNames:  */ 68, 1,
 	/* iArg:      */ SQL_SelectTrace},
 #endif
-	{ /* zName:     */ "short_column_names",
-	 /* ePragTyp:  */ PragTyp_FLAG,
-	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 70, 1,
-	 /* iArg:      */ SQL_ShortColNames},
 	{ /* zName:     */ "sql_compound_select_limit",
 	/* ePragTyp:  */ PragTyp_COMPOUND_SELECT_LIMIT,
 	/* ePragFlg:  */ PragFlg_Result0,
-	/* ColNames:  */ 72, 1,
+	/* ColNames:  */ 70, 1,
 	/* iArg:      */ 0},
 	{ /* zName:     */ "sql_default_engine",
 	 /* ePragTyp:  */ PragTyp_DEFAULT_ENGINE,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 74, 1,
+	 /* ColNames:  */ 72, 1,
 	 /* iArg:      */ 0},
 #if defined(SQL_DEBUG)
 	{ /* zName:     */ "sql_trace",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 76, 1,
+	 /* ColNames:  */ 74, 1,
 	 /* iArg:      */ SQL_SqlTrace},
 #endif
 	{ /* zName:     */ "stats",
@@ -252,33 +244,33 @@ static const PragmaName aPragmaName[] = {
 	{ /* zName:     */ "vdbe_addoptrace",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 78, 1,
+	 /* ColNames:  */ 76, 1,
 	 /* iArg:      */ SQL_VdbeAddopTrace},
 	{ /* zName:     */ "vdbe_debug",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 80, 1,
+	 /* ColNames:  */ 78, 1,
 	 /* iArg:      */
 	 SQL_SqlTrace | SQL_VdbeListing | SQL_VdbeTrace},
 	{ /* zName:     */ "vdbe_eqp",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 82, 1,
+	 /* ColNames:  */ 80, 1,
 	 /* iArg:      */ SQL_VdbeEQP},
 	{ /* zName:     */ "vdbe_listing",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 84, 1,
+	 /* ColNames:  */ 82, 1,
 	 /* iArg:      */ SQL_VdbeListing},
 	{ /* zName:     */ "vdbe_trace",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 86, 1,
+	 /* ColNames:  */ 84, 1,
 	 /* iArg:      */ SQL_VdbeTrace},
 	{ /* zName:     */ "where_trace",
 	/* ePragTyp:  */ PragTyp_FLAG,
 	/* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	/* ColNames:  */ 88, 1,
+	/* ColNames:  */ 86, 1,
 	/* iArg:      */ SQL_WhereTrace},
 #endif
 };
diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index 8f93edd..b81c7af 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -1760,7 +1760,6 @@ generateColumnNames(Parse * pParse,	/* Parser context */
 	Vdbe *v = pParse->pVdbe;
 	int i, j;
 	sql *db = pParse->db;
-	int fullNames, shortNames;
 	/* If this is an EXPLAIN, skip this step */
 	if (pParse->explain) {
 		return;
@@ -1778,8 +1777,6 @@ generateColumnNames(Parse * pParse,	/* Parser context */
 	}
 	assert(pTabList != 0);
 	pParse->colNamesSet = 1;
-	fullNames = (pParse->sql_flags & SQL_FullColNames) != 0;
-	shortNames = (pParse->sql_flags & SQL_ShortColNames) != 0;
 	sqlVdbeSetNumCols(v, pEList->nExpr);
 	uint32_t var_count = 0;
 	for (i = 0; i < pEList->nExpr; i++) {
@@ -1806,12 +1803,7 @@ generateColumnNames(Parse * pParse,	/* Parser context */
 			struct space_def *space_def = pTabList->a[j].space->def;
 			assert(iCol >= 0 && iCol < (int)space_def->field_count);
 			zCol = space_def->fields[iCol].name;
-			if (!shortNames && !fullNames) {
-				sqlVdbeSetColName(v, i, COLNAME_NAME,
-						      sqlDbStrDup(db,
-								      pEList->a[i].zSpan),
-						      SQL_DYNAMIC);
-			} else if (fullNames) {
+			if ((pParse->sql_flags & SQL_FullColNames) != 0) {
 				char *zName = 0;
 				zName = sqlMPrintf(db, "%s.%s",
 						       space_def->name, zCol);
@@ -2022,8 +2014,7 @@ sqlResultSetOfSelect(Parse * pParse, Select * pSelect)
 	sql *db = pParse->db;
 
 	uint32_t saved_flags = pParse->sql_flags;
-	pParse->sql_flags |= ~SQL_FullColNames;
-	pParse->sql_flags &= SQL_ShortColNames;
+	pParse->sql_flags = 0;
 	sqlSelectPrep(pParse, pSelect, 0);
 	if (pParse->is_aborted)
 		return NULL;
@@ -4926,8 +4917,7 @@ selectExpander(Walker * pWalker, Select * p)
 		struct ExprList_item *a = pEList->a;
 		ExprList *pNew = 0;
 		uint32_t flags = pParse->sql_flags;
-		int longNames = (flags & SQL_FullColNames) != 0
-		    && (flags & SQL_ShortColNames) == 0;
+		int longNames = (flags & SQL_FullColNames) != 0;
 
 		for (k = 0; k < pEList->nExpr; k++) {
 			pE = a[k].pExpr;
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index b4f1d4c..27a4c41 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -1166,7 +1166,6 @@ 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 */
-#define SQL_ShortColNames  0x00000040	/* Show short columns names */
 #define SQL_SqlTrace       0x00000200	/* Debug print SQL as it executes */
 #define SQL_SelectTrace    0x00000800       /* Debug info about select statement */
 #define SQL_WhereTrace     0x00008000       /* Debug info about optimizer's work */
diff --git a/test/sql-tap/colname.test.lua b/test/sql-tap/colname.test.lua
index 253497c..de03d7c 100755
--- a/test/sql-tap/colname.test.lua
+++ b/test/sql-tap/colname.test.lua
@@ -1,6 +1,6 @@
 #!/usr/bin/env tarantool
 test = require("sqltester")
-test:plan(63)
+test:plan(62)
 
 --!./tcltestrunner.lua
 -- 2008 July 15
@@ -28,16 +28,12 @@ test:plan(63)
 -- (2) A non-trival expression (not a table column name) then the name is
 --     a copy of the expression text.
 --
--- (3) If short_column_names=ON, then just the abbreviated column name without
+-- (3) If full_column_names=OFF, then just the abbreviated column name without
 --     the table name.
 --
--- (4) When short_column_names=OFF and full_column_names=OFF then
---     use case (2) for simple queries and case (5) for joins.
+-- (4) When full_column_names=ON then use the form: TABLE.COLUMN
 --
--- (5) When short_column_names=OFF and full_column_names=ON then
---     use the form: TABLE.COLUMN
---
--- Verify the default settings for short_column_name and full_column_name
+-- Verify the default settings for full_column_name
 --
 local function lreplace(arr, pos, len, val)
     for i = pos + 1, pos + len + 1, 1 do
@@ -49,16 +45,6 @@ end
 test:do_test(
     "colname-1.1",
     function()
-        return test:execsql "PRAGMA short_column_names"
-    end, {
-        -- <colname-1.1>
-        1
-        -- </colname-1.1>
-    })
-
-test:do_test(
-    "colname-1.2",
-    function()
         return test:execsql "PRAGMA full_column_names"
     end, {
         -- <colname-1.2>
@@ -172,12 +158,11 @@ test:do_execsql2_test(
         -- </colname-2.9>
     })
 
--- Tests for short=OFF and full=OFF
+-- Tests for full=OFF
 test:do_test(
     "colname-3.1",
     function()
         test:execsql [[
-            PRAGMA short_column_names='OFF';
             PRAGMA full_column_names='OFF';
             CREATE VIEW v3 AS SELECT tabC.a, txyZ.x, *
               FROM tabc, txyz ORDER BY 1 LIMIT 1;
@@ -199,7 +184,7 @@ test:do_execsql2_test(
         SELECT Tabc.a, tAbc.b, taBc.c FROM tabc
     ]], {
         -- <colname-3.2>
-        "Tabc.a", 1, "tAbc.b", 2, "taBc.c", 3
+        "A", 1, "B", 2, "C", 3
         -- </colname-3.2>
     })
 
@@ -209,7 +194,7 @@ test:do_execsql2_test(
         SELECT +tabc.a, -tabc.b, tabc.c FROM tabc
     ]], {
         -- <colname-3.3>
-        "+tabc.a", 1, "-tabc.b", -2, "tabc.c", 3
+        "+tabc.a", 1, "-tabc.b", -2, "C", 3
         -- </colname-3.3>
     })
 
@@ -229,7 +214,7 @@ test:do_execsql2_test(
         SELECT Tabc.a, Txyz.x, * FROM tabc, txyz;
     ]], {
         -- <colname-3.5>
-        "Tabc.a", 1, "Txyz.x", 4, "A", 1, "B", 2, "C", 3, "X", 4, "Y", 5, "Z", 6
+        "A", 1, "X", 4, "A", 1, "B", 2, "C", 3, "X", 4, "Y", 5, "Z", 6
         -- </colname-3.5>
     })
 
@@ -259,7 +244,7 @@ test:do_execsql2_test(
         SELECT v1.a, * FROM v1 ORDER BY 2;
     ]], {
         -- <colname-3.8>
-        "v1.a",1,"A",1,"X",4,"A_1",1,"B",2,"C",3,"X_1",4,"Y",5,"Z",6
+        "A",1,"A",1,"X",4,"A_1",1,"B",2,"C",3,"X_1",4,"Y",5,"Z",6
         -- </colname-3.8>
     })
 
@@ -293,12 +278,11 @@ test:do_execsql2_test(
         -- </colname-3.11>
     })
 
--- Test for short=OFF and full=ON
+-- Test for full=ON
 test:do_test(
     "colname-4.1",
     function()
         test:execsql [[
-            PRAGMA short_column_names='OFF';
             PRAGMA full_column_names='ON';
             CREATE VIEW v5 AS SELECT tabC.a, txyZ.x, *
               FROM tabc, txyz ORDER BY 1 LIMIT 1;
@@ -456,7 +440,6 @@ test:do_test(
         -- instead of reconnect to database
         -- we are just turning settings to default state
         test:execsql([[
-            PRAGMA short_column_names='ON';
             PRAGMA full_column_names='OFF';
             ]])
         test:execsql [=[
diff --git a/test/sql-tap/select1.test.lua b/test/sql-tap/select1.test.lua
index 4bbfbd6..d8fe7a9 100755
--- a/test/sql-tap/select1.test.lua
+++ b/test/sql-tap/select1.test.lua
@@ -940,7 +940,7 @@ test:do_catchsql2_test(
         SELECT * FROM test1 WHERE f1==11
     ]], {
         -- <select1-6.1.3>
-        0, {"F1", 11, "F2", 22}
+        0, {"TEST1.F1", 11, "TEST1.F2", 22}
         -- </select1-6.1.3>
     })
 
@@ -956,7 +956,7 @@ test:do_test(
         return table.insert(v,msg) or v
     end, {
         -- <select1-6.1.4>
-        0, {"F1", 11, "F2", 22}
+        0, {"TEST1.F1", 11, "TEST1.F2", 22}
         -- </select1-6.1.4>
     })
 
@@ -1124,7 +1124,6 @@ test:do_test(
     "select1-6.9.3",
     function()
         test:execsql [[
-            PRAGMA short_column_names='OFF';
             PRAGMA full_column_names='OFF';
         ]]
         return test:execsql2 [[
@@ -1132,7 +1131,7 @@ test:do_test(
         ]]
     end, {
         -- <select1-6.9.3>
-        "test1 . f1", 11, "test1 . f2", 22
+        "F1", 11, "F2", 22
         -- </select1-6.9.3>
     })
 
@@ -1140,7 +1139,6 @@ test:do_test(
     "select1-6.9.4",
     function()
         test:execsql [[
-            PRAGMA short_column_names='OFF';
             PRAGMA full_column_names='ON';
         ]]
         return test:execsql2 [[
@@ -1156,7 +1154,6 @@ test:do_test(
     "select1-6.9.5",
     function()
         test:execsql [[
-            PRAGMA short_column_names='OFF';
             PRAGMA full_column_names='ON';
         ]]
         return test:execsql2 [[
@@ -1238,7 +1235,6 @@ test:do_test(
     "select1-6.9.11",
     function()
         test:execsql [[
-            PRAGMA short_column_names='ON';
             PRAGMA full_column_names='ON';
         ]]
         return test:execsql2 [[
@@ -1264,7 +1260,6 @@ test:do_test(
     "select1-6.9.13",
     function()
         test:execsql [[
-            PRAGMA short_column_names='ON';
             PRAGMA full_column_names='OFF';
         ]]
         return test:execsql2 [[
@@ -1290,7 +1285,6 @@ test:do_test(
     "select1-6.9.15",
     function()
         test:execsql [[
-            PRAGMA short_column_names='OFF';
             PRAGMA full_column_names='ON';
         ]]
         return test:execsql2 [[
@@ -1313,7 +1307,6 @@ test:do_execsql2_test(
     })
 
 test:execsql [[
-    PRAGMA short_column_names='ON';
     PRAGMA full_column_names='OFF';
 ]]
 test:do_catchsql2_test(
diff --git a/test/sql/sql-debug.result b/test/sql/sql-debug.result
index e52a13a..4102b1a 100644
--- a/test/sql/sql-debug.result
+++ b/test/sql/sql-debug.result
@@ -44,7 +44,6 @@ box.execute('PRAGMA')
   - ['recursive_triggers', 1]
   - ['reverse_unordered_selects', 0]
   - ['select_trace', 0]
-  - ['short_column_names', 1]
   - ['sql_trace', 0]
   - ['vdbe_addoptrace', 0]
   - ['vdbe_debug', 0]
-- 
2.7.4

  parent reply	other threads:[~2019-11-27 10:13 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-27 10:13 [Tarantool-patches] [PATCH 0/5] Introduce SQL SET statement imeevma
2019-11-27 10:13 ` [Tarantool-patches] [PATCH 1/5] sql: remove PRAGMA "count_changes" imeevma
2019-11-27 10:13 ` imeevma [this message]
2019-11-27 10:13 ` [Tarantool-patches] [PATCH 3/5] temporary: disable boolean.test.sql imeevma
2019-11-27 10:13 ` [Tarantool-patches] [PATCH 4/5] sql: replace control pragmas by SET imeevma
2019-11-27 10:45   ` Mergen Imeev
2019-11-27 10:51   ` Konstantin Osipov
2019-11-27 11:05     ` Mergen Imeev
2019-11-27 11:10       ` Konstantin Osipov
2019-11-27 11:24         ` Mergen Imeev
2019-11-27 11:39           ` Konstantin Osipov
2019-11-27 12:21             ` Mergen Imeev
2019-11-27 12:49               ` Konstantin Osipov
2019-11-27 13:01                 ` Mergen Imeev
2019-11-27 14:03                   ` Nikita Pettik
2019-11-27 21:50                     ` Konstantin Osipov
2019-11-27 23:22                   ` Vladislav Shpilevoy
2019-11-28 12:31                     ` Konstantin Osipov
2019-11-28 14:01                       ` Nikita Pettik
2019-11-28 15:52                         ` Konstantin Osipov
2019-11-27 23:18       ` Vladislav Shpilevoy
2019-11-27 10:13 ` [Tarantool-patches] [PATCH 5/5] sql: refactor PRAGMA-related code imeevma

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=8a50eca87b5b2e87426771ac8c6b2c498b7f4d97.1574849451.git.imeevma@gmail.com \
    --to=imeevma@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH 2/5] sql: remove PRAGMA "short_column_names"' \
    /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