From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id C72D223BCF for ; Tue, 29 May 2018 07:49:17 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TRM8Tv7Iq5CX for ; Tue, 29 May 2018 07:49:17 -0400 (EDT) Received: from smtp59.i.mail.ru (smtp59.i.mail.ru [217.69.128.39]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 2230722ECE for ; Tue, 29 May 2018 07:49:16 -0400 (EDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: [tarantool-patches] Re: [PATCH v7 7/7] sql: remove Checks to server From: "n.pettik" In-Reply-To: <2baee418a3799c91c5a8b92ac62e59de3456da0d.1527084287.git.kshcherbatov@tarantool.org> Date: Tue, 29 May 2018 14:49:09 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: <90226C84-EE19-4DC3-BD50-147C7EAF5DB8@tarantool.org> References: <2baee418a3799c91c5a8b92ac62e59de3456da0d.1527084287.git.kshcherbatov@tarantool.org> Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: Kirill Shcherbatov >sql: remove Checks to server I guess, it would be better to use word =E2=80=98move=E2=80=99... > 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 =E2=80=98opt=E2=80=99 is output param by [out] tag: @param[out] opt ... >+++ b/src/box/space_def.h >@@ -40,6 +40,8 @@ > extern "C" { > #endif /* defined(__cplusplus) */ >=20 >+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 =3D get_enc(buf); >- char *base =3D buf, *p; >+ bool is_view =3D pTable !=3D NULL && pTable->def->opts.is_view; >+ bool has_checks =3D pTable !=3D NULL && = pTable->def->opts.checks !=3D 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 =E2=80=98A=E2=80=99, = =E2=80=98B=E2=80=99 and =E2=80=98C=E2=80=99. So you should add another one condition: && is_view. >+ if (a[i].zName !=3D NULL) { >+ p =3D enc->encode_str(p, "name", 4); >+ p =3D 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 =3D true; >+ >+ Table dummy_table; >+ memset(&dummy_table, 0, sizeof(dummy_table)); >+ dummy_table.def =3D def; >+ >+ sql_resolve_self_reference(&parser, &dummy_table, NC_IsCheck, = NULL, >+ expr_list); >+ >+ sql_parser_destroy(&parser); >+ if (parser.rc !=3D SQLITE_OK) { >+ /* Error is already set with diag. */ >+ if (parser.rc !=3D SQL_TARANTOOL_ERROR) >+ diag_set(ClientError, ER_SQL, parser.zErrMsg); Comment isn=E2=80=99t 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); >=20 >+/** >+ * 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 =3D true; >+ >+ Table dummy_table; >+ memset(&dummy_table, 0, sizeof(dummy_table)); >+ dummy_table.def =3D 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?