Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
3.2.2, 3.2.3
-
None
-
Arch Linux x86_64 running MariaDB 11.5.2 or 11.4.2
Description
When using prepared statements with SQLPrepare, the Prepared_stmt_count increases on MariaDB (when shown with SHOW GLOBAL STATUS LIKE 'Prepared_stmt_count'). It does not decrease when calling SQLFreeHandle(SQL_HANDLE_STMT, stmt) on the statement handle that was made as a prepared statement. Disconnecting and reconnecting, however, does lower the Prepared_stmt_count.
On long-lived connections or connections with many prepared statements, this can have the effect of throwing errors like:
STATE 42000: ODBC ECode 1461: EMsg [ma-3.2.2][11.4.2-MariaDB-log]Can't create more than max_prepared_stmt_count statements (current value: 16382)
Attached is a test program that demonstrates this.
Expected Output:
Initial - 0
After SQLExecDirect - 0
After SQLPrepare - 1
After SQLExecute - 1
After SQLCloseCursor - 1
After SQLFreeHandle - 0
After Reconnect - 0
Actual Output:
Initial - 0
After SQLExecDirect - 0
After SQLPrepare - 1
After SQLExecute - 1
After SQLCloseCursor - 1
After SQLFreeHandle - 1
After Reconnect - 0
Attachments
Activity
Field | Original Value | New Value |
---|---|---|
Description |
When using prepared statements with {{SQLPrepare}}, the {{Prepared_stmt_count}} increases on MariaDB (when shown with {{SHOW GLOBAL STATUS LIKE 'Prepared_stmt_count'}}). It does not decrease when calling {{SQLFreeHandle(SQL_HANDLE_STMT, stmt)}} on the statement handle that was made as a prepared statement. Disconnecting and reconnecting, however, does lower the {{Prepared_stmt_count}}.
On long-lived connections or connections with many prepared statements, this can have the effect of throwing errors like: {{STATE 42000: ODBC ECode 1461: EMsg [ma-3.2.2][11.4.2-MariaDB-log]Can't create more than max_prepared_stmt_count statements (current value: 16382)}} Attached is a test program that demonstrates this. Expected Output: {{Initial - 0 After SQLExecDirect - 0 After SQLPrepare - 1 After SQLExecute - 1 After SQLCloseCursor - 1 After SQLFreeHandle - 0 After Reconnect - 0}} Actual Output: {{Initial - 0 After SQLExecDirect - 0 After SQLPrepare - 1 After SQLExecute - 1 After SQLCloseCursor - 1 After SQLFreeHandle - 1 After Reconnect - 0}} |
When using prepared statements with {{SQLPrepare}}, the {{Prepared_stmt_count}} increases on MariaDB (when shown with {{SHOW GLOBAL STATUS LIKE 'Prepared_stmt_count'}}). It does not decrease when calling {{SQLFreeHandle(SQL_HANDLE_STMT, stmt)}} on the statement handle that was made as a prepared statement. Disconnecting and reconnecting, however, does lower the {{Prepared_stmt_count}}.
On long-lived connections or connections with many prepared statements, this can have the effect of throwing errors like: {{STATE 42000: ODBC ECode 1461: EMsg [ma-3.2.2][11.4.2-MariaDB-log]Can't create more than max_prepared_stmt_count statements (current value: 16382)}} Attached is a test program that demonstrates this. Expected Output: Initial - 0 After SQLExecDirect - 0 After SQLPrepare - 1 After SQLExecute - 1 After SQLCloseCursor - 1 *After SQLFreeHandle - 0* After Reconnect - 0 Actual Output: Initial - 0 After SQLExecDirect - 0 After SQLPrepare - 1 After SQLExecute - 1 After SQLCloseCursor - 1 *After SQLFreeHandle - 1* After Reconnect - 0 |
Attachment | Prepared_stmt_count2.c [ 74028 ] |
Fix Version/s | 3.2.4 [ 29919 ] | |
Resolution | Fixed [ 1 ] | |
Status | Open [ 1 ] | Closed [ 6 ] |
The driver has features prepared statements cache that is on by default. Thus it can be expected that prepares statements count doesn't decrement on statement handle freeing. You can turn it off by setting PSCACHESIZE to 0.
So, I think there is no bug here, especially since the testsuite has tests controlling closing of server side prepared statement.
Possibly the default size of the cache 250 is too high though.
I will live the ticket open until you verify that you can solve your problem using smaller cache size or completely turning it off.