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 9FF376C7D7; Tue, 27 Apr 2021 19:56:23 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 9FF376C7D7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1619542583; bh=lz/YAkZtw+fV36b9FfHrI/O3zPqIOX0TmA+YWTuLA4o=; 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=wsmGfyGNwPz0rzdXYu/HYu/v+I9ZnUgcMCl/sKNdfEMfNF2k2DJVTbzb0X/s2OPV8 wd/B1K/IA9Ee19/L96NSQP1al0lvLDybciDmFl4NEeSOZ66GI3OEQH62tnXEA/z8dR 9KTUrjZ5v9+h68Fm0a7aGu1aOs3U3qeJPIC8FHfA= 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 55E3974CEC for ; Tue, 27 Apr 2021 19:55:25 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 55E3974CEC Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1lbQzc-00032i-Mg; Tue, 27 Apr 2021 19:55:25 +0300 To: v.shpilevoy@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Tue, 27 Apr 2021 19:55:24 +0300 Message-Id: <73769b1c3a358ebdbdb603592bda2353c0e6b800.1619542456.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: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9ECFD8CE5F0594010C798B26A9CF6FD3F2B2BC7AAFDCADAFC182A05F538085040C9EB4424E970194A6143EBEDABB9A7F8D5158CBA3B16413F56C1EA062C7C560B X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7E30E47A50CB819D6C2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE7E99F7FC786761FD88F08D7030A58E5ADC58D69EE07B14084F39EFFDF887939037866D6147AF826D8E7DB5EFA98CC3E16942274AC39F00E21117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCF1175FABE1C0F9B6A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18CB629EEF1311BF91D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B62CFFCC7B69C47339089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C8E0B2E50BE5001ACB45F13CBC09687EBA8997CA622F0845C9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF0417BEADF48D1460699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34FACF503ACC83041BD9FCEF7E6CF6D70538786828E7D1C056B64EAE6D12560FA102158CF54399C2DB1D7E09C32AA3244C8C2EF08B737AC283427D7522B16449377C0C08F7987826B9729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojmGF4M/OAxzeV4Hx0jQuVcQ== X-Mailru-Sender: 689FA8AB762F73936BC43F508A063822E968717032C77D3823A127704B52AB2A83D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v2 2/3] sql: make mem_is_bin() to check only for VARBINARY 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" After this patch, the mem_is_bin() function will return 'true' only if the value that the MEM contains is of type VARBINARY. This patch also adds the mem_is_bin_ext() function, which is used to check if a MEM contains value of type VARBINARY or value of types that are currently considered VARBINARY extensions - MAP and ARRAY. Part of #4906 --- src/box/sql/func.c | 10 +++++----- src/box/sql/mem.h | 8 +++++++- src/box/sql/vdbe.c | 16 ++++++++-------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/box/sql/func.c b/src/box/sql/func.c index d282b2cea..bed7e8488 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -553,7 +553,7 @@ roundFunc(sql_context * context, int argc, sql_value ** argv) } if (mem_is_null(argv[0])) return; - if (mem_is_bin(argv[0])) { + if (mem_is_bin_ext(argv[0])) { diag_set(ClientError, ER_SQL_TYPE_MISMATCH, mem_str(argv[0]), "numeric"); context->is_aborted = true; @@ -613,7 +613,7 @@ case_type##ICUFunc(sql_context *context, int argc, sql_value **argv) \ const char *z2; \ int n; \ UNUSED_PARAMETER(argc); \ - if (mem_is_bin(argv[0])) { \ + if (mem_is_bin_ext(argv[0])) { \ diag_set(ClientError, ER_INCONSISTENT_TYPES, "text", \ "varbinary"); \ context->is_aborted = true; \ @@ -694,7 +694,7 @@ randomBlob(sql_context * context, int argc, sql_value ** argv) unsigned char *p; assert(argc == 1); UNUSED_PARAMETER(argc); - if (mem_is_bin(argv[0])) { + if (mem_is_bin_ext(argv[0])) { diag_set(ClientError, ER_SQL_TYPE_MISMATCH, mem_str(argv[0]), "numeric"); context->is_aborted = true; @@ -1455,7 +1455,7 @@ trim_func_one_arg(struct sql_context *context, sql_value *arg) const unsigned char *default_trim; if (mem_is_null(arg)) return; - if (mem_is_bin(arg)) + if (mem_is_bin_ext(arg)) default_trim = (const unsigned char *) "\0"; else default_trim = (const unsigned char *) " "; @@ -1584,7 +1584,7 @@ soundexFunc(sql_context * context, int argc, sql_value ** argv) 1, 2, 6, 2, 3, 0, 1, 0, 2, 0, 2, 0, 0, 0, 0, 0, }; assert(argc == 1); - if (mem_is_bin(argv[0])) { + if (mem_is_bin_ext(argv[0])) { diag_set(ClientError, ER_SQL_TYPE_MISMATCH, mem_str(argv[0]), "text"); context->is_aborted = true; diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h index 1db7f4deb..6fc15617d 100644 --- a/src/box/sql/mem.h +++ b/src/box/sql/mem.h @@ -184,7 +184,7 @@ mem_is_bool(const struct Mem *mem) static inline bool mem_is_bin(const struct Mem *mem) { - return (mem->flags & MEM_Blob) != 0; + return (mem->flags & MEM_Blob) != 0 && (mem->flags & MEM_Subtype) == 0; } static inline bool @@ -206,6 +206,12 @@ mem_is_array(const struct Mem *mem) mp_typeof(*mem->z) == MP_ARRAY; } +static inline bool +mem_is_bin_ext(const struct Mem *mem) +{ + return (mem->flags & MEM_Blob) != 0; +} + static inline bool mem_is_agg(const struct Mem *mem) { diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c index 2308587e7..bedfa87af 100644 --- a/src/box/sql/vdbe.c +++ b/src/box/sql/vdbe.c @@ -1634,9 +1634,9 @@ case OP_Ge: { /* same as TK_GE, jump, in1, in3 */ "boolean"); goto abort_due_to_error; } - } else if (mem_is_bin(pIn3) || mem_is_bin(pIn1)) { + } else if (mem_is_bin_ext(pIn3) || mem_is_bin_ext(pIn1)) { if (mem_cmp_bin(pIn3, pIn1, &res) != 0) { - char *str = !mem_is_bin(pIn3) ? + char *str = !mem_is_bin_ext(pIn3) ? mem_type_to_str(pIn3) : mem_type_to_str(pIn1); diag_set(ClientError, ER_SQL_TYPE_MISMATCH, str, @@ -2991,7 +2991,7 @@ case OP_Found: { /* jump, in3 */ } else { pFree = pIdxKey = sqlVdbeAllocUnpackedRecord(db, pC->key_def); if (pIdxKey==0) goto no_mem; - assert(mem_is_bin(pIn3)); + assert(mem_is_bin_ext(pIn3)); (void)ExpandBlob(pIn3); sqlVdbeRecordUnpackMsgpack(pC->key_def, pIn3->z, pIdxKey); @@ -3253,7 +3253,7 @@ case OP_SorterData: { assert(isSorter(pC)); if (sqlVdbeSorterRowkey(pC, pOut) != 0) goto abort_due_to_error; - assert(mem_is_bin(pOut)); + assert(mem_is_bin_ext(pOut)); assert(pOp->p1>=0 && pOp->p1nCursor); p->apCsr[pOp->p3]->cacheStatus = CACHE_STALE; break; @@ -3616,7 +3616,7 @@ case OP_SorterInsert: { /* in2 */ assert(cursor != NULL); assert(isSorter(cursor)); pIn2 = &aMem[pOp->p2]; - assert(mem_is_bin(pIn2)); + assert(mem_is_bin_ext(pIn2)); if (ExpandBlob(pIn2) != 0 || sqlVdbeSorterWrite(cursor, pIn2) != 0) goto abort_due_to_error; @@ -3650,7 +3650,7 @@ case OP_SorterInsert: { /* in2 */ case OP_IdxReplace: case OP_IdxInsert: { pIn2 = &aMem[pOp->p1]; - assert(mem_is_bin(pIn2)); + assert(mem_is_bin_ext(pIn2)); if (ExpandBlob(pIn2) != 0) goto abort_due_to_error; struct space *space; @@ -3741,10 +3741,10 @@ case OP_Update: { assert(pOp->p4type == P4_SPACEPTR); struct Mem *key_mem = &aMem[pOp->p2]; - assert(mem_is_bin(key_mem)); + assert(mem_is_bin_ext(key_mem)); struct Mem *upd_fields_mem = &aMem[pOp->p3]; - assert(mem_is_bin(upd_fields_mem)); + assert(mem_is_bin_ext(upd_fields_mem)); uint32_t *upd_fields = (uint32_t *)upd_fields_mem->z; uint32_t upd_fields_cnt = upd_fields_mem->n / sizeof(uint32_t); -- 2.25.1