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 8E2D56B469; Tue, 23 Mar 2021 12:42:47 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8E2D56B469 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1616492567; bh=DfZaVHZKO4rgq0nrKJA9G7dbEvPeWtHJQ3CZAvoS1jE=; 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=BWF7c0IrkLTkdY1TcrImqOsKEfD22whXAZ4GGS8yET0JKVfaxBZlyh+UEcsstQ7SU dIDIZ0pCuzCJNMA2KKF5mzUA3TVfVwJKa+twJb+jg+hJz82EKIdGPUQBhqo1W8cY5j uUpOYX6P3LV643eLmM0gTMRCNDXs9XFi1WtwwEzo= Received: from smtp45.i.mail.ru (smtp45.i.mail.ru [94.100.177.105]) (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 5020768F44 for ; Tue, 23 Mar 2021 12:35:29 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 5020768F44 Received: by smtp45.i.mail.ru with esmtpa (envelope-from ) id 1lOdRg-0004mB-Dt; Tue, 23 Mar 2021 12:35:28 +0300 To: v.shpilevoy@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Tue, 23 Mar 2021 12:35:28 +0300 Message-Id: <60e432f26824eddbc035ae0ad6bc7b9b5c7b7173.1616491731.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: 4F1203BC0FB41BD95D6E7CC48CB1F5F10D3016C09B407F8B1E2E766A3410B623182A05F5380850406A75085C8E3F89EB0CE3B42771282B427922E9F66928CE76C49FCCDB0A6EABFB X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7FBB2043146276655EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637F0D8FAB78312C5B48638F802B75D45FF914D58D5BE9E6BC131B5C99E7648C95C686AF563A045C75EC1DBB1CEDDE00827AF98625DF3E375DAA471835C12D1D9774AD6D5ED66289B5259CC434672EE6371117882F4460429724CE54428C33FAD30A8DF7F3B2552694AC26CFBAC0749D213D2E47CDBA5A9658378DA827A17800CE77A825AB47F0FC8649FA2833FD35BB23DF004C90652538430302FCEF25BFAB3454AD6D5ED66289B5278DA827A17800CE7D5318778C64E2C63D32BA5DBAC0009BE395957E7521B51C20BC6067A898B09E4090A508E0FED629923F8577A6DFFEA7C8D6C7A5C1D38D1AECD04E86FAF290E2D7E9C4E3C761E06A71DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF5012EF20D2F80756B5F868A13BD56FB6657A7F4EDE966BC389F9E8FC8737B5C2249F4E2BF26F32B5870089D37D7C0E48F6CCF19DD082D7633A0E7DDDDC251EA7DABAAAE862A0553A3920E30A4C9C8E338DA2DC2C6C1EEA0118B43847C11F186F3C5E7DDDDC251EA7DABCC89B49CDF41148FBC2A4A7A8370ED8B3C9F3DD0FB1AF5EB4E70A05D1297E1BBCB5012B2E24CD356 X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A24A6D60772A99906F8E1CD14B953EB46DC59FA031D49983D2355D89D7DBCDD132 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C686AF563A045C75EC1DBB1CEDDE00827AF98625DF3E375DA9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF0417BEADF48D1460699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34697E0FA301E28215F884AA2195676D845ABECD08CB9D5CCD3F6651A62C553E89756897966AAFB2CB1D7E09C32AA3244CEFFFFFF86DF24505140DE568593B32A5BBA718C7E6A9E042FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojWJZv20R+6UhgzjOV0BkWEw== X-Mailru-Sender: 5C3750E245F362008BC1685FEC6306ED5FBB9AA23E2A67460CE3B42771282B424AF810104A35EE5E5105BD0848736F9966FEC6BF5C9C28D97E07721503EA2E00ED97202A5A4E92BF7402F9BA4338D657ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH v4 16/53] 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 a2316cc90..775474f69 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -1791,12 +1791,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 5edb0d80a..aead71df2 100644 --- a/src/box/sql/mem.h +++ b/src/box/sql/mem.h @@ -467,9 +467,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 b4293d961..01c0cc5a1 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 2625a9115..04016ea54 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