From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 8BA1F6EC60; Fri, 9 Apr 2021 20:57:45 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8BA1F6EC60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1617991065; bh=IdJ21I0S3KkAJDGro6fOrsxUTcxa8d3H8u7NEDo+boo=; h=To:Cc:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=i7+LieV3rYkt5dcBYCxFiNt3hR82Nxvc7JFAwN+RDvOTP5XQAw6b6CvzgaH5JLXn+ Jn3L289P/jynv88Ilbd3zOtgonUbfQWLiaMVbAZWv3R5016XcrtPXyU1cAcPaIEBjp fn/GtJgYnMtUcrXhhcOcSud+dBRMWIdqiYl8NGT0= Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id EC2106EC60 for ; Fri, 9 Apr 2021 20:57:21 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org EC2106EC60 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1lUvNg-0006qX-QY; Fri, 09 Apr 2021 20:57:21 +0300 To: v.shpilevoy@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Fri, 9 Apr 2021 20:57:20 +0300 Message-Id: <8e694c5dbed5b36828d97729d4d6c4dac0d6a440.1617984948.git.imeevma@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD92FFCB8E6708E7480257C85EA0BB7A95D5E28B957962BB550182A05F538085040205FF0BDF1420586AA0E50BBC093FB883A1B3042E84DD8AAC1BAB73038457209 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7FBB2043146276655EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006372094AD700861FA748638F802B75D45FF914D58D5BE9E6BC1A93B80C6DEB9DEE97C6FB206A91F05B283D1E092B956CC4F0B06ECB1D9021C6450D7F87C0C4C56F2D2E47CDBA5A96583C09775C1D3CA48CFCA5A41EBD8A3A0199FA2833FD35BB23D2EF20D2F80756B5F868A13BD56FB6657A471835C12D1D977725E5C173C3A84C327ED053E960B195E117882F4460429728AD0CFFFB425014E868A13BD56FB6657E2021AF6380DFAD18AA50765F790063735872C767BF85DA227C277FBC8AE2E8B716A69B0CBCFD959EFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CD0035DD76F8A8A4FD12B8F6B586810FB8356BC35EBFF79879C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF0417BEADF48D1460699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D347D10A9FCB2A62DFEED894CC4995343F200869C2A60D0680400333BCF71A8ECC5291A4FFC2D85E34C1D7E09C32AA3244C147E15CD3E5BA8649776CF4DF1778EAB9CA7333006C390A0FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojyO2lHpuZu4RuXJnAXLQtWQ== X-Mailru-Sender: 689FA8AB762F73936BC43F508A06382272B1A8A78097F36E4D080A22B6D8595683D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v5 17/52] sql: remove sql_column_to_messagepack() X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Mergen Imeev via Tarantool-patches Reply-To: imeevma@tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Function sql_column_to_messagepack() has almost the same functionality as sql_vdbe_mem_encode_tuple(). Due to this it is not necessary to have sql_column_to_messagepack(), so it is removed in this commit. Part of #5818 --- src/box/execute.c | 130 ++---------------------------------------- src/box/sql/mem.c | 6 -- src/box/sql/mem.h | 3 - src/box/sql/sqlInt.h | 15 +---- src/box/sql/vdbeapi.c | 15 ++--- 5 files changed, 13 insertions(+), 156 deletions(-) diff --git a/src/box/execute.c b/src/box/execute.c index e14da20be..f9c161ce4 100644 --- a/src/box/execute.c +++ b/src/box/execute.c @@ -131,113 +131,10 @@ port_sql_create(struct port *port, struct sql_stmt *stmt, port_sql->do_finalize = do_finalize; } -/** - * Serialize a single column of a result set row. - * @param stmt Prepared and started statement. At least one - * sql_step must be called. - * @param i Column number. - * @param region Allocator for column value. - * - * @retval 0 Success. - * @retval -1 Out of memory when resizing the output buffer. - */ -static inline int -sql_column_to_messagepack(struct sql_stmt *stmt, int i, - struct region *region) -{ - size_t size; - enum mp_type type = sql_column_type(stmt, i); - switch (type) { - case MP_INT: { - int64_t n = sql_column_int64(stmt, i); - size = mp_sizeof_int(n); - char *pos = (char *) region_alloc(region, size); - if (pos == NULL) - goto oom; - mp_encode_int(pos, n); - break; - } - case MP_UINT: { - uint64_t n = sql_column_uint64(stmt, i); - size = mp_sizeof_uint(n); - char *pos = (char *) region_alloc(region, size); - if (pos == NULL) - goto oom; - mp_encode_uint(pos, n); - break; - } - case MP_DOUBLE: { - double d = sql_column_double(stmt, i); - size = mp_sizeof_double(d); - char *pos = (char *) region_alloc(region, size); - if (pos == NULL) - goto oom; - mp_encode_double(pos, d); - break; - } - case MP_STR: { - uint32_t len = sql_column_bytes(stmt, i); - size = mp_sizeof_str(len); - char *pos = (char *) region_alloc(region, size); - if (pos == NULL) - goto oom; - const char *s; - s = (const char *)sql_column_text(stmt, i); - mp_encode_str(pos, s, len); - break; - } - case MP_BIN: - case MP_MAP: - case MP_ARRAY: { - uint32_t len = sql_column_bytes(stmt, i); - const char *s = - (const char *)sql_column_blob(stmt, i); - if (sql_column_subtype(stmt, i) == SQL_SUBTYPE_MSGPACK) { - size = len; - char *pos = (char *)region_alloc(region, size); - if (pos == NULL) - goto oom; - memcpy(pos, s, len); - } else { - size = mp_sizeof_bin(len); - char *pos = (char *)region_alloc(region, size); - if (pos == NULL) - goto oom; - mp_encode_bin(pos, s, len); - } - break; - } - case MP_BOOL: { - bool b = sql_column_boolean(stmt, i); - size = mp_sizeof_bool(b); - char *pos = (char *) region_alloc(region, size); - if (pos == NULL) - goto oom; - mp_encode_bool(pos, b); - break; - } - case MP_NIL: { - size = mp_sizeof_nil(); - char *pos = (char *) region_alloc(region, size); - if (pos == NULL) - goto oom; - mp_encode_nil(pos); - break; - } - default: - unreachable(); - } - return 0; -oom: - diag_set(OutOfMemory, size, "region_alloc", "SQL value"); - return -1; -} - /** * Convert sql row into a tuple and append to a port. * @param stmt Started prepared statement. At least one * sql_step must be done. - * @param column_count Statement's column count. * @param region Runtime allocator for temporary objects. * @param port Port to store tuples. * @@ -245,29 +142,11 @@ oom: * @retval -1 Memory error. */ static inline int -sql_row_to_port(struct sql_stmt *stmt, int column_count, - struct region *region, struct port *port) +sql_row_to_port(struct sql_stmt *stmt, struct region *region, struct port *port) { - assert(column_count > 0); - size_t size = mp_sizeof_array(column_count); + uint32_t size; size_t svp = region_used(region); - char *pos = (char *) region_alloc(region, size); - if (pos == NULL) { - diag_set(OutOfMemory, size, "region_alloc", "SQL row"); - return -1; - } - mp_encode_array(pos, column_count); - - for (int i = 0; i < column_count; ++i) { - if (sql_column_to_messagepack(stmt, i, region) != 0) - goto error; - } - size = region_used(region) - svp; - pos = (char *) region_join(region, size); - if (pos == NULL) { - diag_set(OutOfMemory, size, "region_join", "pos"); - goto error; - } + char *pos = sql_result_to_msgpack(stmt, &size, region); struct tuple *tuple = tuple_new(box_tuple_format_default(), pos, pos + size); if (tuple == NULL) @@ -677,8 +556,7 @@ sql_execute(struct sql_stmt *stmt, struct port *port, struct region *region) if (column_count > 0) { /* Either ROW or DONE or ERROR. */ while ((rc = sql_step(stmt)) == SQL_ROW) { - if (sql_row_to_port(stmt, column_count, region, - port) != 0) + if (sql_row_to_port(stmt, region, port) != 0) return -1; } assert(rc == SQL_DONE || rc != 0); diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index 7d06e256c..b417c1007 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -1752,12 +1752,6 @@ sqlValueText(sql_value * pVal) return valueToText(pVal); } -enum sql_subtype -sql_value_subtype(sql_value * pVal) -{ - return (pVal->flags & MEM_Subtype) != 0 ? pVal->subtype : SQL_SUBTYPE_NO; -} - /* * Return a pointer to static memory containing an SQL NULL value. */ diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h index 55f8f0c9f..0faf223ef 100644 --- a/src/box/sql/mem.h +++ b/src/box/sql/mem.h @@ -449,9 +449,6 @@ const void *sqlValueText(struct Mem *); #define VdbeFrameMem(p) ((Mem *)&((u8 *)p)[ROUND8(sizeof(VdbeFrame))]) -enum sql_subtype -sql_value_subtype(sql_value * pVal); - const Mem * columnNullValue(void); diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h index e075224c6..259ba3833 100644 --- a/src/box/sql/sqlInt.h +++ b/src/box/sql/sqlInt.h @@ -351,16 +351,6 @@ sql_stricmp(const char *, const char *); int sql_strnicmp(const char *, const char *, int); - -/** - * Get row column subtype. - * @param stmt row data to process. - * @param i column index. - * @retval SQL subtype if any, 0 else. - */ -enum sql_subtype -sql_column_subtype(struct sql_stmt *stmt, int i); - sql * sql_context_db_handle(sql_context *); @@ -471,8 +461,9 @@ const unsigned char * sql_column_text(sql_stmt *, int iCol); -enum mp_type -sql_column_type(sql_stmt *stmt, int field_no); +char * +sql_result_to_msgpack(struct sql_stmt *stmt, uint32_t *tuple_size, + struct region *region); /* * Terminate the current execution of an SQL statement and reset diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c index 8e69e3c38..3e9f1ff6f 100644 --- a/src/box/sql/vdbeapi.c +++ b/src/box/sql/vdbeapi.c @@ -515,16 +515,13 @@ sql_column_text(sql_stmt * pStmt, int i) return sql_value_text(columnMem(pStmt, i)); } -enum mp_type -sql_column_type(sql_stmt * pStmt, int i) -{ - return sql_value_type(columnMem(pStmt, i)); -} - -enum sql_subtype -sql_column_subtype(struct sql_stmt *stmt, int i) +char * +sql_result_to_msgpack(struct sql_stmt *stmt, uint32_t *tuple_size, + struct region *region) { - return sql_value_subtype(columnMem(stmt, i)); + struct Vdbe *vdbe = (struct Vdbe *)stmt; + return sql_vdbe_mem_encode_tuple(vdbe->pResultSet, vdbe->nResColumn, + tuple_size, region); } /* -- 2.25.1