Tarantool development patches archive
 help / color / mirror / Atom feed
From: "n.pettik" <korablev@tarantool.org>
To: tarantool-patches@freelists.org
Cc: Kirill Shcherbatov <kshcherbatov@tarantool.org>
Subject: [tarantool-patches] Re: [PATCH v7 7/7] sql: remove Checks to server
Date: Tue, 29 May 2018 14:49:09 +0300	[thread overview]
Message-ID: <90226C84-EE19-4DC3-BD50-147C7EAF5DB8@tarantool.org> (raw)
In-Reply-To: <2baee418a3799c91c5a8b92ac62e59de3456da0d.1527084287.git.kshcherbatov@tarantool.org>

>sql: remove Checks to server

I guess, it would be better to use word ‘move’...

> diff --git a/src/box/space_def.c b/src/box/space_def.c
> index 9e0e7e3..7bff86f 100644
> --- a/src/box/space_def.c
> +++ b/src/box/space_def.c
> @@ -33,17 +33,33 @@
> #include "diag.h"
> #include "error.h"
> #include "sql.h"
> +#include "msgpuck.h"
> +
> +/**
> + * Make checks from msgpack.
> + * @param str pointer to array of maps
> + *         e.g. [{"expr_str": "x < y", "name": "ONE"}, ..].
> + * @param len array items count.
> + * @param opt pointer to store parsing result.

You can specify that ‘opt’ is output param by [out] tag:
@param[out] opt ...

>+++ b/src/box/space_def.h
>@@ -40,6 +40,8 @@
> extern "C" {
> #endif /* defined(__cplusplus) */
> 
>+struct ExprList;
>+

Mb it would be better to rename this struct according to our codestyle?

>@@ -79,12 +81,8 @@ space_opts_create(struct space_opts *opts)
> /**
>  * Destroy space options
>  */
>-static inline void
>-space_opts_destroy(struct space_opts *opts)
>-{
>-       free(opts->sql);
>-       TRASH(opts);
>-}
>+void
>+space_opts_destroy(struct space_opts *opts);

Seems like this function lacks some meaningful comment.

>+++ b/src/box/sql.c
>@@ -1500,22 +1500,47 @@ int tarantoolSqlite3MakeTableFormat(Table *pTable, void *buf)
>  *
>  * Ex: {"temporary": true, "sql": "CREATE TABLE student (name, grade)"}
>  */
>-int tarantoolSqlite3MakeTableOpts(Table *pTable, const char *zSql, void *buf)
>+int
>+tarantoolSqlite3MakeTableOpts(Table *pTable, const char *zSql, char *buf)
> {
>        const struct Enc *enc = get_enc(buf);
>-       char *base = buf, *p;
>+       bool is_view = pTable != NULL && pTable->def->opts.is_view;
>+       bool has_checks = pTable != NULL && pTable->def->opts.checks != NULL;

In fact, it is incorrect since opts.checks may also contain aliases for VIEW
columns: CREATE VIEW V1(a, b, c) AS SELECT * FROM t1;
In this case, checks contain NULL exprs with names ‘A’, ‘B’ and ‘C’.
So you should add another one condition: && is_view.

>+               if (a[i].zName != NULL) {
>+                       p = enc->encode_str(p, "name", 4);
>+                       p = enc->encode_str(p, a[i].zName, strlen(a[i].zName));
>+               }

The same is here: you add checks for VIEW which are really aliases.

>+int
>+sql_checks_resolve_space_def_reference(ExprList *expr_list,
>+                                      struct space_def *def)
>+{
>+       Parse parser;
>+       sql_parser_create(&parser, sql_get());
>+       parser.parse_only = true;
>+
>+       Table dummy_table;
>+       memset(&dummy_table, 0, sizeof(dummy_table));
>+       dummy_table.def = def;
>+
>+       sql_resolve_self_reference(&parser, &dummy_table, NC_IsCheck, NULL,
>+                                  expr_list);
>+
>+       sql_parser_destroy(&parser);
>+       if (parser.rc != SQLITE_OK) {
>+               /* Error is already set with diag. */
>+               if (parser.rc != SQL_TARANTOOL_ERROR)
>+                       diag_set(ClientError, ER_SQL, parser.zErrMsg);

Comment isn’t consistent with code: if error is already
set, why you set it again?

>@@ -232,6 +240,42 @@ void
> sql_resolve_self_reference(struct Parse *parser, struct Table *table, int type,
>                           struct Expr *expr, struct ExprList *expr_list);
> 
>+/**
>+ * Initialize check_list_item.
>+ * @param expr_list ExprList with item.
>+ * @param idx item index.

I would somehow rename this var, since it is easy to
confuse one with things related to database indexes.

>+int
>+sql_checks_resolve_space_def_reference(ExprList *expr_list,
>+                                      struct space_def *def)
>+{
>+       Parse parser;
>+       sql_parser_create(&parser, sql_get());
>+       parser.parse_only = true;
>+
>+       Table dummy_table;
>+       memset(&dummy_table, 0, sizeof(dummy_table));
>+       dummy_table.def = def;
>+
>+       sql_resolve_self_reference(&parser, &dummy_table, NC_IsCheck, NULL,
>+                                  expr_list);

Why do we still need to create table wrappers?
Is it possible to change signatures and use straight space_def instead of fake tables?

  parent reply	other threads:[~2018-05-29 11:49 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-23 14:05 [tarantool-patches] [PATCH v7 0/7] " Kirill Shcherbatov
2018-05-23 14:05 ` [tarantool-patches] [PATCH v7 1/7] sql: remove parser construct, destruct to sql.h Kirill Shcherbatov
2018-05-23 17:46   ` [tarantool-patches] " Konstantin Osipov
2018-05-24 19:26   ` Vladislav Shpilevoy
2018-05-25 12:05     ` Kirill Shcherbatov
2018-05-23 14:05 ` [tarantool-patches] [PATCH v7 2/7] box: introduce OPT_ARRAY opt_type to decode arrays Kirill Shcherbatov
2018-05-23 17:53   ` [tarantool-patches] " Konstantin Osipov
2018-05-24  7:32     ` Kirill Shcherbatov
2018-05-24 19:26   ` Vladislav Shpilevoy
2018-05-25 11:54     ` Kirill Shcherbatov
2018-05-23 14:05 ` [tarantool-patches] [PATCH v7 3/7] sql: introduce expr_len for sql_expr_compile Kirill Shcherbatov
2018-05-24 19:26   ` [tarantool-patches] " Vladislav Shpilevoy
2018-05-25 11:54     ` Kirill Shcherbatov
2018-05-23 14:05 ` [tarantool-patches] [PATCH v7 4/7] sql: rename sql_expr_free to sql_expr_delete Kirill Shcherbatov
2018-05-23 18:00   ` [tarantool-patches] " Konstantin Osipov
2018-05-24 19:26   ` Vladislav Shpilevoy
2018-05-25 11:54     ` Kirill Shcherbatov
2018-05-23 14:05 ` [tarantool-patches] [PATCH v7 5/7] sql: change sqlite3AddCheckConstraint signature Kirill Shcherbatov
2018-05-23 18:01   ` [tarantool-patches] " Konstantin Osipov
2018-05-24 19:26   ` Vladislav Shpilevoy
2018-05-25 11:53     ` Kirill Shcherbatov
2018-05-29 11:51   ` n.pettik
2018-05-30  8:32     ` Kirill Shcherbatov
2018-05-23 14:05 ` [tarantool-patches] [PATCH v7 6/7] sql: export funcs defined on Expr, ExprList to sql.h Kirill Shcherbatov
2018-05-23 18:15   ` [tarantool-patches] " Konstantin Osipov
2018-05-24  7:33     ` Kirill Shcherbatov
2018-05-24 19:26   ` Vladislav Shpilevoy
2018-05-25 11:53     ` Kirill Shcherbatov
2018-05-28 11:19       ` Vladislav Shpilevoy
2018-05-28 14:59         ` Kirill Shcherbatov
2018-05-23 14:05 ` [tarantool-patches] [PATCH v7 7/7] sql: remove Checks to server Kirill Shcherbatov
2018-05-24 19:26   ` [tarantool-patches] " Vladislav Shpilevoy
2018-05-25 11:53     ` Kirill Shcherbatov
2018-05-28 11:19       ` Vladislav Shpilevoy
2018-05-28 14:59         ` Kirill Shcherbatov
2018-05-28 18:50           ` Vladislav Shpilevoy
2018-05-29 11:49   ` n.pettik [this message]
2018-05-30  8:32     ` Kirill Shcherbatov
2018-05-30 10:42       ` n.pettik
2018-05-25 12:04 ` [tarantool-patches] Re: [PATCH v7 0/7] " Kirill Shcherbatov
2018-05-28 11:19   ` Vladislav Shpilevoy
2018-05-30 11:03 ` n.pettik
2018-05-31 17:44   ` 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=90226C84-EE19-4DC3-BD50-147C7EAF5DB8@tarantool.org \
    --to=korablev@tarantool.org \
    --cc=kshcherbatov@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='[tarantool-patches] Re: [PATCH v7 7/7] sql: remove Checks to server' \
    /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