From: Stanislav Zudin <szudin@tarantool.org>
To: tarantool-patches@freelists.org, vdavydov.dev@gmail.com
Cc: Stanislav Zudin <szudin@tarantool.org>
Subject: [PATCH 02/13] sql: make VDBE recognize big integers
Date: Fri, 15 Mar 2019 18:45:31 +0300 [thread overview]
Message-ID: <250778a6f016d3be9eb288255cea0e4a7c7b22c5.1552663061.git.szudin@tarantool.org> (raw)
In-Reply-To: <cover.1552663061.git.szudin@tarantool.org>
In-Reply-To: <cover.1552663061.git.szudin@tarantool.org>
VDBE distinguishes signed and unsigned integers.
SELECT query correctly returns values greater
than INT64_MAX.
---
src/box/lua/sql.c | 5 ++++-
src/box/sql/build.c | 4 ++--
src/box/sql/expr.c | 3 +++
src/box/sql/sqlInt.h | 3 +++
src/box/sql/vdbe.c | 2 ++
src/box/sql/vdbe.h | 3 ++-
src/box/sql/vdbeInt.h | 3 +++
src/box/sql/vdbeapi.c | 8 ++++++++
src/box/sql/vdbeaux.c | 12 +++++++-----
src/box/sql/vdbemem.c | 2 +-
10 files changed, 35 insertions(+), 10 deletions(-)
diff --git a/src/box/lua/sql.c b/src/box/lua/sql.c
index ee20faab7..cb2927144 100644
--- a/src/box/lua/sql.c
+++ b/src/box/lua/sql.c
@@ -32,7 +32,10 @@ lua_push_row(struct lua_State *L, struct sql_stmt *stmt)
int type = sql_column_type(stmt, i);
switch (type) {
case SQL_INTEGER:
- luaL_pushint64(L, sql_column_int64(stmt, i));
+ if (sql_column_is_unsigned(stmt, i))
+ luaL_pushuint64(L, sql_column_int64(stmt, i));
+ else
+ luaL_pushint64(L, sql_column_int64(stmt, i));
break;
case SQL_FLOAT:
lua_pushnumber(L, sql_column_double(stmt, i));
diff --git a/src/box/sql/build.c b/src/box/sql/build.c
index e9851d9a1..34fd03862 100644
--- a/src/box/sql/build.c
+++ b/src/box/sql/build.c
@@ -939,10 +939,10 @@ emitNewSysSequenceRecord(Parse *pParse, int reg_seq_id, const char *seq_name)
/* 5. Minimum */
sqlVdbeAddOp4Dup8(v, OP_Int64, 0, first_col + 5, 0,
- (unsigned char*)&min_usigned_long_long, P4_INT64);
+ (unsigned char*)&min_usigned_long_long, P4_UINT64);
/* 6. Maximum */
sqlVdbeAddOp4Dup8(v, OP_Int64, 0, first_col + 6, 0,
- (unsigned char*)&max_usigned_long_long, P4_INT64);
+ (unsigned char*)&max_usigned_long_long, P4_UINT64);
/* 7. Start */
sqlVdbeAddOp2(v, OP_Integer, 1, first_col + 7);
diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c
index 3fbfab7a0..fcc673436 100644
--- a/src/box/sql/expr.c
+++ b/src/box/sql/expr.c
@@ -3349,6 +3349,9 @@ expr_code_int(struct Parse *parse, struct Expr *expr, bool is_neg,
}
break;
case ATOI_UNSIGNED:
+ sqlVdbeAddOp4Dup8(v, OP_Int64, 0, mem, 0,
+ (u8 *)&value, P4_UINT64);
+ break;
case ATOI_SIGNED:
sqlVdbeAddOp4Dup8(v, OP_Int64, 0, mem, 0,
(u8 *)&value, P4_INT64);
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 0ef373c24..92e2f282f 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -586,6 +586,9 @@ sql_column_text(sql_stmt *,
int
sql_column_type(sql_stmt *, int iCol);
+bool
+sql_column_is_unsigned(sql_stmt *, int iCol);
+
sql_value *
sql_column_value(sql_stmt *,
int iCol);
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index c87b10757..ea398e7d6 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -1141,6 +1141,8 @@ case OP_Int64: { /* out2 */
pOut = out2Prerelease(p, pOp);
assert(pOp->p4.pI64!=0);
pOut->u.i = *pOp->p4.pI64;
+ if (pOp->p4type == P4_UINT64)
+ pOut->flags = MEM_Int | MEM_Unsigned;
break;
}
diff --git a/src/box/sql/vdbe.h b/src/box/sql/vdbe.h
index f9bb96f09..d4383901c 100644
--- a/src/box/sql/vdbe.h
+++ b/src/box/sql/vdbe.h
@@ -70,7 +70,7 @@ struct VdbeOp {
int i; /* Integer value if p4type==P4_INT32 */
void *p; /* Generic pointer */
char *z; /* Pointer to data for string (char array) types */
- i64 *pI64; /* Used when p4type is P4_INT64 */
+ i64 *pI64; /* Used when p4type is P4_INT64 or P4_UINT64 */
double *pReal; /* Used when p4type is P4_REAL */
FuncDef *pFunc; /* Used when p4type is P4_FUNCDEF */
sql_context *pCtx; /* Used when p4type is P4_FUNCCTX */
@@ -131,6 +131,7 @@ struct SubProgram {
#define P4_INTARRAY (-12) /* P4 is a vector of 32-bit integers */
#define P4_SUBPROGRAM (-13) /* P4 is a pointer to a SubProgram structure */
#define P4_ADVANCE (-14) /* P4 is a pointer to BtreeNext() or BtreePrev() */
+#define P4_UINT64 (-15) /* P4 is a 64-bit unsigned integer */
#define P4_FUNCCTX (-16) /* P4 is a pointer to an sql_context object */
#define P4_BOOL (-17) /* P4 is a bool value */
#define P4_PTR (-18) /* P4 is a generic pointer */
diff --git a/src/box/sql/vdbeInt.h b/src/box/sql/vdbeInt.h
index 61b7d58b2..66b21299a 100644
--- a/src/box/sql/vdbeInt.h
+++ b/src/box/sql/vdbeInt.h
@@ -248,6 +248,9 @@ struct Mem {
#define MEM_Agg 0x4000 /* Mem.z points to an agg function context */
#define MEM_Zero 0x8000 /* Mem.i contains count of 0s appended to blob */
#define MEM_Subtype 0x10000 /* Mem.eSubtype is valid */
+#define MEM_Unsigned 0x20000 /* Value is unsigned integer.
+ * Combine this flag with MEM_Int
+ * if necessary */
#ifdef SQL_OMIT_INCRBLOB
#undef MEM_Zero
#define MEM_Zero 0x0000
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index d7e89073e..02a1b2e0f 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -1044,6 +1044,14 @@ sql_column_type(sql_stmt * pStmt, int i)
return iType;
}
+bool sql_column_is_unsigned(sql_stmt * pStmt, int i)
+{
+ const struct Mem* pMem = columnMem(pStmt, i);
+ if (!pMem)
+ return false;
+ return (pMem->flags & MEM_Unsigned);
+}
+
enum sql_subtype
sql_column_subtype(struct sql_stmt *stmt, int i)
{
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index 0cc3c1487..37cfe0431 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -862,6 +862,7 @@ freeP4(sql * db, int p4type, void *p4)
}
case P4_REAL:
case P4_INT64:
+ case P4_UINT64:
case P4_DYNAMIC:
case P4_INTARRAY:{
sqlDbFree(db, p4);
@@ -1354,6 +1355,10 @@ displayP4(Op * pOp, char *zTemp, int nTemp)
sqlXPrintf(&x, "%lld", *pOp->p4.pI64);
break;
}
+ case P4_UINT64:{
+ sqlXPrintf(&x, "%ull", *pOp->p4.pI64);
+ break;
+ }
case P4_INT32:{
sqlXPrintf(&x, "%d", pOp->p4.i);
break;
@@ -3724,13 +3729,10 @@ vdbe_decode_msgpack_into_mem(const char *buf, struct Mem *mem, uint32_t *len)
}
case MP_UINT: {
uint64_t v = mp_decode_uint(&buf);
- if (v > INT64_MAX) {
- diag_set(ClientError, ER_SQL_EXECUTE,
- "integer is overflowed");
- return -1;
- }
mem->u.i = v;
mem->flags = MEM_Int;
+ if (v > INT64_MAX)
+ mem->flags |= MEM_Unsigned;
break;
}
case MP_INT: {
diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c
index 074ff8c96..0b5ba965e 100644
--- a/src/box/sql/vdbemem.c
+++ b/src/box/sql/vdbemem.c
@@ -1723,7 +1723,7 @@ mpstream_encode_vdbe_mem(struct mpstream *stream, struct Mem *var)
} else if (var->flags & MEM_Int) {
i = var->u.i;
encode_int:
- if (var->u.i >= 0)
+ if (var->u.i >= 0 || var->flags & MEM_Unsigned)
mpstream_encode_uint(stream, i);
else
mpstream_encode_int(stream, i);
--
2.17.1
next prev parent reply other threads:[~2019-03-15 15:45 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-15 15:45 [PATCH 00/13] sql: support -2^63 .. 2^64-1 integer type Stanislav Zudin
2019-03-15 15:45 ` [PATCH 01/13] sql: Convert big integers from string Stanislav Zudin
2019-03-25 15:10 ` [tarantool-patches] " n.pettik
2019-04-01 20:39 ` Stanislav Zudin
2019-04-02 7:27 ` Konstantin Osipov
2019-03-15 15:45 ` Stanislav Zudin [this message]
2019-03-25 15:11 ` [tarantool-patches] Re: [PATCH 02/13] sql: make VDBE recognize big integers n.pettik
2019-04-01 20:42 ` Stanislav Zudin
2019-04-02 7:38 ` [tarantool-patches] " Konstantin Osipov
2019-03-15 15:45 ` [PATCH 03/13] sql: removes unused function Stanislav Zudin
2019-03-25 15:11 ` [tarantool-patches] " n.pettik
2019-04-01 20:39 ` Stanislav Zudin
2019-03-15 15:45 ` [PATCH 04/13] sql: support big integers within sql binding Stanislav Zudin
2019-03-25 15:12 ` [tarantool-patches] " n.pettik
2019-04-01 20:42 ` Stanislav Zudin
2019-04-02 7:46 ` Konstantin Osipov
2019-04-02 7:44 ` [tarantool-patches] " Konstantin Osipov
2019-03-15 15:45 ` [PATCH 05/13] sql: removes redundant function Stanislav Zudin
2019-03-25 15:12 ` [tarantool-patches] " n.pettik
2019-03-15 15:45 ` [PATCH 06/13] sql: aux functions to support big integers Stanislav Zudin
2019-03-25 15:13 ` [tarantool-patches] " n.pettik
2019-03-15 15:45 ` [PATCH 07/13] sql: arithmetic functions " Stanislav Zudin
2019-03-25 15:13 ` [tarantool-patches] " n.pettik
2019-04-01 20:43 ` Stanislav Zudin
2019-04-02 7:54 ` Konstantin Osipov
2019-04-02 7:52 ` Konstantin Osipov
2019-03-15 15:45 ` [PATCH 08/13] sql: aggregate sql functions support big int Stanislav Zudin
2019-03-25 15:13 ` [tarantool-patches] " n.pettik
2019-04-01 20:43 ` Stanislav Zudin
2019-04-02 7:57 ` [tarantool-patches] " Konstantin Osipov
2019-03-15 15:45 ` [PATCH 09/13] sql: fixes errors Stanislav Zudin
2019-03-25 15:14 ` [tarantool-patches] " n.pettik
2019-03-15 15:45 ` [PATCH 10/13] sql: fixes an error in sqlSubInt64 Stanislav Zudin
2019-03-25 15:14 ` [tarantool-patches] " n.pettik
2019-03-15 15:45 ` [PATCH 11/13] sql: fixes an error in string to int64 conversion Stanislav Zudin
2019-03-25 15:14 ` [tarantool-patches] " n.pettik
2019-03-15 15:45 ` [PATCH 12/13] sql: fixes an error in uint64 to double casting Stanislav Zudin
2019-03-25 15:15 ` [tarantool-patches] " n.pettik
2019-03-15 15:45 ` [PATCH 13/13] sql: support -2^63 .. 2^64-1 integer type Stanislav Zudin
2019-03-25 15:25 ` [tarantool-patches] " n.pettik
2019-04-01 20:44 ` Stanislav Zudin
2019-03-25 15:10 ` [tarantool-patches] Re: [PATCH 00/13] " n.pettik
2019-04-01 20:38 ` Stanislav Zudin
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=250778a6f016d3be9eb288255cea0e4a7c7b22c5.1552663061.git.szudin@tarantool.org \
--to=szudin@tarantool.org \
--cc=tarantool-patches@freelists.org \
--cc=vdavydov.dev@gmail.com \
--subject='Re: [PATCH 02/13] sql: make VDBE recognize big integers' \
/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