From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> To: Nikita Pettik <korablev@tarantool.org>, tarantool-patches@dev.tarantool.org Subject: Re: [Tarantool-patches] [PATCH v2 3/6] sql: extend result set with collation Date: Wed, 18 Dec 2019 01:29:48 +0100 [thread overview] Message-ID: <62bad716-6680-f1b4-f375-15a46b194a5a@tarantool.org> (raw) In-Reply-To: <a845ba0c6cdfa047ac4d921a5fd7bd82a39be8d2.1576071711.git.korablev@tarantool.org> Hi! Thanks for the patch! See 3 comments below. On 11/12/2019 14:44, Nikita Pettik wrote: > If resulting set column is of STRING type and features collation (no > matter explicit or implicit) different from "none", then metadata will > contain its name. > > This patch also introduces new pragma: full_metadata. By default it is > not set. If it is turned on, then optional metadata (like collation) is > pushed to Lua stack. Note that via IProto protocol always full metadata > is send, but its decoding depends on session SQL settings. > > Part of #4407 > diff --git a/src/box/execute.c b/src/box/execute.c > index e8b012e5b..72300235a 100644 > --- a/src/box/execute.c > +++ b/src/box/execute.c > @@ -268,6 +268,24 @@ error: > return -1; > } > > +static size_t > +metadata_map_sizeof(const char *name, const char *type, const char *coll) 1. Since you moved sizeof to a separate function, maybe it is worth doing the same with encoding part. > +{ > + uint32_t members_count = 2; > + size_t map_size = 0; > + if (coll != NULL) { > + members_count++; > + map_size += mp_sizeof_uint(IPROTO_FIELD_COLL); > + map_size += mp_sizeof_str(strlen(coll)); > + } > + map_size += mp_sizeof_uint(IPROTO_FIELD_NAME); > + map_size += mp_sizeof_uint(IPROTO_FIELD_TYPE); > + map_size += mp_sizeof_str(strlen(name)); > + map_size += mp_sizeof_str(strlen(type)); > + map_size += mp_sizeof_map(members_count); > + return map_size; > +} > diff --git a/src/box/sql/select.c b/src/box/sql/select.c > index e4768121e..506c1a7c7 100644 > --- a/src/box/sql/select.c > +++ b/src/box/sql/select.c > @@ -1794,6 +1795,24 @@ generate_column_metadata(struct Parse *pParse, struct SrcList *pTabList, > var_pos[var_count++] = i; > vdbe_metadata_set_col_type(v, i, > field_type_strs[sql_expr_type(p)]); > + if (is_full_meta && sql_expr_type(p) == FIELD_TYPE_STRING) { > + bool unused; > + uint32_t id; 2. I would initialize id with 0, because a compiler may complain about usage of not initialized id below. Now it does not, but it can start, after any change in the code or in the compiler version. > + struct coll *coll = NULL; > + /* > + * If sql_expr_coll fails then it fails somewhere > + * above the call stack. > + */ > + int rc = sql_expr_coll(pParse, p, &unused, &id, &coll); > + assert(rc == 0); > + (void) rc; > + if (id != COLL_NONE) { > + struct coll_id *coll_id = coll_by_id(id); > + vdbe_metadata_set_col_collation(v, i, > + coll_id->name, > + coll_id->name_len); > + } > + } > if (p->op == TK_COLUMN || p->op == TK_AGG_COLUMN) { > char *zCol; > int iCol = p->iColumn; > diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c > index f2cf386bb..02d9fc6ce 100644 > --- a/src/box/sql/vdbeaux.c > +++ b/src/box/sql/vdbeaux.c > @@ -1888,6 +1889,21 @@ vdbe_metadata_set_col_type(struct Vdbe *p, int idx, const char *type) > return 0; > } > > +int > +vdbe_metadata_set_col_collation(struct Vdbe *p, int idx, const char *coll, > + size_t coll_len) > +{ > + assert(idx < p->nResColumn); > + if (p->metadata[idx].collation != NULL) > + free((void *)p->metadata[idx].collation); 3. Please, remove (void *) cast. You don't need it since you dropped 'const' from sql_column_metadata members. In the next patches in similar places too. > + p->metadata[idx].collation = strndup(coll, coll_len); > + if (p->metadata[idx].collation == NULL) { > + diag_set(OutOfMemory, coll_len + 1, "strndup", "collation"); > + return -1; > + } > + return 0; > +}
next prev parent 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 [this message] 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 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=62bad716-6680-f1b4-f375-15a46b194a5a@tarantool.org \ --to=v.shpilevoy@tarantool.org \ --cc=korablev@tarantool.org \ --cc=tarantool-patches@dev.tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH v2 3/6] sql: extend result set with collation' \ /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