[Tarantool-patches] [PATCH v1 1/1] sql: do not reset region on select
v.shpilevoy at tarantool.org
Thu Nov 5 01:14:38 MSK 2020
Hi! Thanks for the patch!
See 2 comments below.
On 02.11.2020 10:49, imeevma at tarantool.org wrote:
> Prior to this patch, region on fiber was reset during select(), get(),
> count(), max(), or min(). This would result in an error if one of these
> operations was used in a user-defined function in SQL. After this patch,
> these functions truncate region instead of resetting it.
> Closes #5427
> - Region truncated instead of resetting on select() (gh-5427).
1. I suggest to make the message more understandable for users. They have
no idea what a region is. For instance, consider
Memory corruption when SQL called Lua functions with box calls inside
> src/box/box.cc | 5 +-
> src/box/index.cc | 20 +++
> src/box/txn.h | 6 +-
> .../gh-5427-lua-func-changes-result.result | 153 ++++++++++++++++++
> .../gh-5427-lua-func-changes-result.test.lua | 86 ++++++++++
> 5 files changed, 264 insertions(+), 6 deletions(-)
> create mode 100644 test/sql/gh-5427-lua-func-changes-result.result
> create mode 100644 test/sql/gh-5427-lua-func-changes-result.test.lua
> diff --git a/src/box/box.cc b/src/box/box.cc
> index 18568df3b..473ef52ad 100644
> --- a/src/box/box.cc
> +++ b/src/box/box.cc
> @@ -1388,7 +1388,8 @@ box_select(uint32_t space_id, uint32_t index_id,
> struct port *port)
> + struct region *region = &fiber()->gc;
> + size_t used = region_used(region);
> rmean_collect(rmean_box, IPROTO_SELECT, 1);
2. I must say I couldn't come up with a better idea so far. I remember I
also proposed to start a transaction for each VDBE statement, but not sure
it is a right thing to do.
It means, we probably should go for this one, but a bit polished.
In the current solution I don't like, that you basically just inlined
txn_commit_ro_stmt(), but instead I would rather want you to patch it to
make it work.
So for example txn_begin_ro_stmt inside remembers the current region size,
and returns it via an out parameter struct txn_ro_savepoint *svp. Which
you create on the stack.
Then, after you are done with the statement, you call txn_commit_ro_stmt,
which takes const struct txn_ro_savepoint *svp, and does the region_truncate
More information about the Tarantool-patches