Skip to content
Snippets Groups Projects

feat: unprepare statement references after sql execution

Merged Denis Smirnov requested to merge sd/execute into 2.11.2-picodata
All threads resolved!
2 files
+ 112
5
Compare changes
  • Side-by-side
  • Inline
Files
2
  • Picodata SQL now manages the Tarantool statement cache using a
    dedicated SQL fiber that handles preparation and unpreparation of
    statements based on an LRU eviction policy. Prepared statements
    can be executed across different sessions by SQL clients.
    
    Previously, when a client executed a prepared statement, it
    increased the reference count in the statement cache and linked
    the statement to the client's session. While this approach seemed
    fine, it caused issues during eviction, as references to these
    statements remained in client sessions, preventing proper eviction.
    
    This commit addresses the issue by ensuring that if a statement is
    added to the current session during execution, it is removed and
    the session state is restored once execution is complete.
    
    NO_DOC=internal
    NO_CHANGELOG=internal
+ 15
4
@@ -331,14 +331,25 @@ sql_execute_prepared_ext(uint32_t stmt_id, const char *mp_params,
goto cleanup;
}
/*
* If the statement was prepared in some other session,
* we borrow it and add to the current session.
* If the statement was prepared in some other session, we borrow
* it and add to the current session until execution is finished.
* It is required to prevent the statement from being removed out
* of the cache while the statement is being executed. Then the
* statement is removed out of the current session to restore the
* original session state.
*/
bool stmt_is_borrowed = false;
if (!session_check_stmt_id(current_session(), stmt_id)) {
session_add_stmt_id(current_session(), stmt_id);
stmt_is_borrowed = true;
}
if (sql_stmt_execute(stmt, bind, (uint32_t)bind_count, vdbe_max_steps,
&fiber()->gc, &port) != 0)
int rc = sql_stmt_execute(stmt, bind, (uint32_t)bind_count,
vdbe_max_steps, &fiber()->gc, &port);
if (stmt_is_borrowed) {
session_remove_stmt_id(current_session(), stmt_id);
sql_stmt_unref(stmt_id);
}
if (rc != 0)
goto cleanup;
struct obuf_svp out_svp = obuf_create_svp(out_buf);
Loading