Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: Nikita Pettik <korablev@tarantool.org>,
	tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v2 4/6] sql: extend result set with nullability
Date: Wed, 18 Dec 2019 01:29:43 +0100	[thread overview]
Message-ID: <e09efa05-e9bf-3984-3dd4-13a8855ffaa4@tarantool.org> (raw)
In-Reply-To: <38fabdf9592d40d8f90920eb85ffbef72c564da9.1576071711.git.korablev@tarantool.org>

Thanks for the patch!

See 2 comments below.

> diff --git a/src/box/sql/delete.c b/src/box/sql/delete.c
> index 169814a2e..cc5891bb8 100644
> --- a/src/box/sql/delete.c
> +++ b/src/box/sql/delete.c
> @@ -420,6 +420,7 @@ sql_table_delete_from(struct Parse *parse, struct SrcList *tab_list,
>  		sqlVdbeSetNumCols(v, 1);
>  		vdbe_metadata_set_col_name(v, 0, "rows deleted");
>  		vdbe_metadata_set_col_type(v, 0, "integer");
> +		vdbe_metadata_set_col_nullability(v, 0, -1);

1. All these set_col_nullability(-1) look really doubtful. You
don't set collation NULL explicitly, but you set nullability -1
explicitly. Why?

I think it is much better to fill default values of newly allocated
sql_column_metadata in sqlVdbeSetNumCols. See my diff (not on the
branch):

==================================================================

diff --git a/src/box/sql/delete.c b/src/box/sql/delete.c
index cc5891bb8..169814a2e 100644
--- a/src/box/sql/delete.c
+++ b/src/box/sql/delete.c
@@ -420,7 +420,6 @@ sql_table_delete_from(struct Parse *parse, struct SrcList *tab_list,
 		sqlVdbeSetNumCols(v, 1);
 		vdbe_metadata_set_col_name(v, 0, "rows deleted");
 		vdbe_metadata_set_col_type(v, 0, "integer");
-		vdbe_metadata_set_col_nullability(v, 0, -1);
 	}
 
  delete_from_cleanup:
diff --git a/src/box/sql/insert.c b/src/box/sql/insert.c
index 159acec25..f1290e01c 100644
--- a/src/box/sql/insert.c
+++ b/src/box/sql/insert.c
@@ -787,7 +787,6 @@ sqlInsert(Parse * pParse,	/* Parser context */
 			column_name = "rows inserted";
 		vdbe_metadata_set_col_name(v, 0, column_name);
 		vdbe_metadata_set_col_type(v, 0, "integer");
-		vdbe_metadata_set_col_nullability(v, 0, -1);
 	}
 
  insert_cleanup:
diff --git a/src/box/sql/pragma.c b/src/box/sql/pragma.c
index a6a5f25ce..00ecde0a9 100644
--- a/src/box/sql/pragma.c
+++ b/src/box/sql/pragma.c
@@ -122,7 +122,6 @@ vdbe_set_pragma_result_columns(struct Vdbe *v, const struct PragmaName *pragma)
 	for (int i = 0, j = pragma->iPragCName; i < n; ++i) {
 		vdbe_metadata_set_col_name(v, i, pragCName[j++]);
 		vdbe_metadata_set_col_type(v, i, pragCName[j++]);
-		vdbe_metadata_set_col_nullability(v, i, -1);
 	}
 }
 
@@ -169,10 +168,8 @@ vdbe_emit_pragma_status(struct Parse *parse)
 	sqlVdbeSetNumCols(v, 2);
 	vdbe_metadata_set_col_name(v, 0, "pragma_name");
 	vdbe_metadata_set_col_type(v, 0, "text");
-	vdbe_metadata_set_col_nullability(v, 0, -1);
 	vdbe_metadata_set_col_name(v, 1, "pragma_value");
 	vdbe_metadata_set_col_type(v, 1, "integer");
-	vdbe_metadata_set_col_nullability(v, 1, -1);
 
 	parse->nMem = 2;
 	for (int i = 0; i < ArraySize(aPragmaName); ++i) {
diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c
index 5b5981c46..39e897ba3 100644
--- a/src/box/sql/prepare.c
+++ b/src/box/sql/prepare.c
@@ -150,7 +150,6 @@ sqlPrepare(sql * db,	/* Database handle. */
 						   azColName[name_index]);
 			vdbe_metadata_set_col_type(sParse.pVdbe, i,
 						   azColName[name_index + 1]);
-			vdbe_metadata_set_col_nullability(sParse.pVdbe, i, -1);
 		}
 	}
 
diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index 73ce95eba..63f517e62 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -1813,7 +1813,6 @@ generate_column_metadata(struct Parse *pParse, struct SrcList *pTabList,
 								coll_id->name_len);
 			}
 		}
-		vdbe_metadata_set_col_nullability(v, i, -1);
 		if (p->op == TK_COLUMN || p->op == TK_AGG_COLUMN) {
 			char *zCol;
 			int iCol = p->iColumn;
diff --git a/src/box/sql/update.c b/src/box/sql/update.c
index 489328960..c08777a2d 100644
--- a/src/box/sql/update.c
+++ b/src/box/sql/update.c
@@ -500,7 +500,6 @@ sqlUpdate(Parse * pParse,		/* The parser context */
 		sqlVdbeSetNumCols(v, 1);
 		vdbe_metadata_set_col_name(v, 0, "rows updated");
 		vdbe_metadata_set_col_type(v, 0, "integer");
-		vdbe_metadata_set_col_nullability(v, 0, -1);
 	}
 
  update_cleanup:
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index 2de41a70a..ef542efc3 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -1849,6 +1849,7 @@ vdbe_metadata_delete(struct Vdbe *v)
 void
 sqlVdbeSetNumCols(Vdbe * p, int nResColumn)
 {
+	int old_n = p->nResColumn;
 	vdbe_metadata_delete(p);
 	p->nResColumn = (u16) nResColumn;
 	p->metadata = (struct sql_column_metadata *)
@@ -1859,6 +1860,9 @@ sqlVdbeSetNumCols(Vdbe * p, int nResColumn)
 			 "calloc", "metadata");
 		return;
 	}
+	for (int i = old_n; i < nResColumn; ++i)
+		p->metadata[i].nullable = -1;
+
 }

==================================================================

> diff --git a/src/box/sql/vdbeInt.h b/src/box/sql/vdbeInt.h
> index d3de5770b..92a50dd7b 100644
> --- a/src/box/sql/vdbeInt.h
> +++ b/src/box/sql/vdbeInt.h
> @@ -350,6 +350,11 @@ struct sql_column_metadata {
>  	char *name;
>  	char *type;
>  	char *collation;
> +	/**
> +	 * -1 is for any member of result set except for pure
> +	 * columns: all other expressions are nullable by default.
> +	 */
> +	int8_t nullable : 2;

2. What is a point of having it :2 bits, if you don't
have other flags in the same byte? Due to alignment
this member anyway will become 1 byte.

  reply	other threads:[~2019-12-18  0:29 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-11 13:44 [Tarantool-patches] [PATCH v2 0/6] sql: extended metadata Nikita Pettik
     [not found] ` <cover.1576071711.git.korablev@tarantool.org>
2019-12-11 13:44   ` [Tarantool-patches] [PATCH v2 1/6] sql: refactor resulting set metadata Nikita Pettik
2019-12-11 13:44   ` [Tarantool-patches] [PATCH v2 2/6] sql: fix possible null dereference in sql_expr_coll() Nikita Pettik
2019-12-11 13:44   ` [Tarantool-patches] [PATCH v2 3/6] sql: extend result set with collation Nikita Pettik
2019-12-18  0:29     ` Vladislav Shpilevoy
2019-12-24  0:26       ` Nikita Pettik
2019-12-24 15:30         ` Vladislav Shpilevoy
2019-12-11 13:44   ` [Tarantool-patches] [PATCH v2 4/6] sql: extend result set with nullability Nikita Pettik
2019-12-18  0:29     ` Vladislav Shpilevoy [this message]
2019-12-24  0:26       ` Nikita Pettik
2019-12-11 13:44   ` [Tarantool-patches] [PATCH v2 5/6] sql: extend result set with autoincrement Nikita Pettik
2019-12-18  0:29     ` Vladislav Shpilevoy
2019-12-24  0:26       ` Nikita Pettik
2019-12-24 15:30         ` Vladislav Shpilevoy
2019-12-25 12:17           ` Nikita Pettik
2019-12-25 15:40             ` Vladislav Shpilevoy
2019-12-25 23:18               ` Nikita Pettik
2019-12-11 13:44   ` [Tarantool-patches] [PATCH v2 6/6] sql: extend result set with alias Nikita Pettik
2019-12-18  0:29     ` Vladislav Shpilevoy
2019-12-24  0:26       ` Nikita Pettik
2019-12-24 15:34         ` Vladislav Shpilevoy
2019-12-26 11:24           ` Nikita Pettik
2019-12-27 11:53             ` Vladislav Shpilevoy
2019-12-27 23:44             ` Nikita Pettik
2019-12-28  9:29               ` Vladislav Shpilevoy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e09efa05-e9bf-3984-3dd4-13a8855ffaa4@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=korablev@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v2 4/6] sql: extend result set with nullability' \
    /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