Skip to content
Snippets Groups Projects
Commit 5b97eaa0 authored by Arseniy Volynets's avatar Arseniy Volynets Committed by Dmitry Ivanov
Browse files

fix: wrong sql cache byte counter

- If you prepare and execute statement with params
in the projection and then unprepare the
statement, byte counter may show the wrong value
or even overflow.
- The problem is that when we compile sql
statement, we set parameter type to 'any'.
But when we execute the statement we set parameter
type to actual type. Then we use this type in
calculation of estimated of sql cache entry size.
This leads to different estimated sizes of cache
entry during prepare and during unprepare after
statement was executed
- Fix this by resetting type to 'any' after
executing the statement

NO_DOC=picodata internal patch
NO_CHANGELOG=picodata internal patch
parent 66297e1a
No related branches found
No related tags found
No related merge requests found
...@@ -289,9 +289,11 @@ sql_stmt_execute(struct sql_stmt *stmt, const struct sql_bind *bind, ...@@ -289,9 +289,11 @@ sql_stmt_execute(struct sql_stmt *stmt, const struct sql_bind *bind,
if (sql_stmt_run_vdbe(stmt, vdbe_max_steps, region, port) != 0) { if (sql_stmt_run_vdbe(stmt, vdbe_max_steps, region, port) != 0) {
port_destroy(port); port_destroy(port);
sql_stmt_reset(stmt); sql_stmt_reset(stmt);
sql_unbind(stmt);
return -1; return -1;
} }
sql_stmt_reset(stmt); sql_stmt_reset(stmt);
sql_unbind(stmt);
return 0; return 0;
} }
......
...@@ -431,11 +431,12 @@ sql_unbind(struct sql_stmt *stmt) ...@@ -431,11 +431,12 @@ sql_unbind(struct sql_stmt *stmt)
assert(rc == 0); assert(rc == 0);
(void) rc; (void) rc;
/* /*
* We should re-set boolean type - unassigned * We should re-set any type - parameters
* binding slots are assumed to contain NULL * are assigned type any during compilation.
* value, which has boolean type. * During execution actual types are assigned,
* so reset back to any.
*/ */
sql_bind_type(v, i, "boolean"); sql_bind_type(v, i, "any");
} }
} }
......
...@@ -163,6 +163,9 @@ g.test_stmt_prepare = function() ...@@ -163,6 +163,9 @@ g.test_stmt_prepare = function()
local stmt_id = ffi.new('uint32_t[1]') local stmt_id = ffi.new('uint32_t[1]')
local session_id = ffi.new('uint64_t[1]') local session_id = ffi.new('uint64_t[1]')
local initial_stmt_count = box.info.sql().cache.stmt_count
local initial_cache_size = box.info.sql().cache.size
-- Prepare the statement. -- Prepare the statement.
res = ffi.C.sql_prepare_ext('VALUES (?)', 10, stmt_id, session_id) res = ffi.C.sql_prepare_ext('VALUES (?)', 10, stmt_id, session_id)
t.assert_equals(res, 0) t.assert_equals(res, 0)
...@@ -176,6 +179,9 @@ g.test_stmt_prepare = function() ...@@ -176,6 +179,9 @@ g.test_stmt_prepare = function()
tonumber(stmt_id[0]), tonumber(session_id[0])) tonumber(stmt_id[0]), tonumber(session_id[0]))
t.assert_equals(res, 0) t.assert_equals(res, 0)
t.assert_equals(box.info.sql().cache.stmt_count, initial_stmt_count)
t.assert_equals(box.info.sql().cache.size, initial_cache_size)
-- Calling unprepare again returns error -- Calling unprepare again returns error
res = ffi.C.sql_unprepare_ext( res = ffi.C.sql_unprepare_ext(
tonumber(stmt_id[0]), tonumber(session_id[0])) tonumber(stmt_id[0]), tonumber(session_id[0]))
......
...@@ -809,7 +809,7 @@ s:execute({42}) ...@@ -809,7 +809,7 @@ s:execute({42})
--- ---
- metadata: - metadata:
- name: COLUMN_1 - name: COLUMN_1
type: integer type: any
rows: rows:
- [42] - [42]
... ...
......
...@@ -855,11 +855,11 @@ execute(s.stmt_id, {{[':a'] = 1}, {[':b'] = 2}, {[':c'] = 3}}); ...@@ -855,11 +855,11 @@ execute(s.stmt_id, {{[':a'] = 1}, {[':b'] = 2}, {[':c'] = 3}});
| --- | ---
| - metadata: | - metadata:
| - name: COLUMN_1 | - name: COLUMN_1
| type: integer | type: any
| - name: COLUMN_2 | - name: COLUMN_2
| type: integer | type: any
| - name: COLUMN_3 | - name: COLUMN_3
| type: integer | type: any
| rows: | rows:
| - [1, 2, 3] | - [1, 2, 3]
| ... | ...
...@@ -867,11 +867,11 @@ execute(s.stmt_id, {{[':a'] = 1}, {[':b'] = 2}}); ...@@ -867,11 +867,11 @@ execute(s.stmt_id, {{[':a'] = 1}, {[':b'] = 2}});
| --- | ---
| - metadata: | - metadata:
| - name: COLUMN_1 | - name: COLUMN_1
| type: integer | type: any
| - name: COLUMN_2 | - name: COLUMN_2
| type: integer | type: any
| - name: COLUMN_3 | - name: COLUMN_3
| type: boolean | type: any
| rows: | rows:
| - [1, 2, null] | - [1, 2, null]
| ... | ...
...@@ -879,11 +879,11 @@ execute(s.stmt_id); ...@@ -879,11 +879,11 @@ execute(s.stmt_id);
| --- | ---
| - metadata: | - metadata:
| - name: COLUMN_1 | - name: COLUMN_1
| type: boolean | type: any
| - name: COLUMN_2 | - name: COLUMN_2
| type: boolean | type: any
| - name: COLUMN_3 | - name: COLUMN_3
| type: boolean | type: any
| rows: | rows:
| - [null, null, null] | - [null, null, null]
| ... | ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment