box: introduce prepared statements
This patch introduces local prepared statements. Support of prepared statements in IProto protocol and netbox is added in the next patch. Prepared statement is an opaque instance of SQL Virtual Machine. It can be executed several times without necessity of query recompilation. To achieve this one can use box.prepare(...) function. It takes string of SQL query to be prepared; returns extended set of meta-information including statement's ID, parameter's types and names, types and names of columns of the resulting set, count of parameters to be bound. Lua object representing result of :prepare() invocation also features two methods - :execute() and :unprepare(). They correspond to box.execute(stmt.stmt_id) and box.unprepare(stmt.stmt_id), i.e. automatically substitute string of prepared statement to be executed. Statements are held in prepared statement cache - for details see previous commit. After schema changes all prepared statement located in cache are considered to be expired - they must be re-prepared by separate :prepare() call (or be invalidated with :unrepare()). Two sessions can share one prepared statements. But in the current implementation if statement is executed by one session, another is not able to use it and will compile it from scratch and than execute. SQL cache memory limit is regulated by box{sql_cache_size} which can be set dynamically. However, it can be set to the value which is less than the size of current free space in cache (since otherwise some statements can disappear from cache). Part of #2592
Showing
- src/box/errcode.h 1 addition, 0 deletionssrc/box/errcode.h
- src/box/execute.c 115 additions, 0 deletionssrc/box/execute.c
- src/box/execute.h 11 additions, 5 deletionssrc/box/execute.h
- src/box/lua/execute.c 206 additions, 7 deletionssrc/box/lua/execute.c
- src/box/lua/execute.h 1 addition, 1 deletionsrc/box/lua/execute.h
- src/box/lua/init.c 1 addition, 1 deletionsrc/box/lua/init.c
- src/box/sql/prepare.c 0 additions, 9 deletionssrc/box/sql/prepare.c
- test/box/misc.result 3 additions, 0 deletionstest/box/misc.result
- test/sql/engine.cfg 3 additions, 1 deletiontest/sql/engine.cfg
- test/sql/prepared.result 728 additions, 0 deletionstest/sql/prepared.result
- test/sql/prepared.test.lua 266 additions, 0 deletionstest/sql/prepared.test.lua
Loading
Please register or sign in to comment