Is there a limit to the number of bind variables I can use in a query in MySQL 5? I assume that there is, but I can't find any information in the reference manual or by Googling.
The only thing that I could find that provides any information at all is in the C API reference: http://dev.mysql.com/doc/refman/5.0/en/mysql-stmt-bind-result.html
This seems to imply that memory is the only limit, but that seems a bit suspect.
Update: there is a limit!
runner.rb:47: 开发者_开发知识库data_replicator.rb:312:in `prepare': Prepared statement contains too many placeholders (Mysql::Error)
from data_replicator.rb:312:in `set_statement_handle_for'
from data_replicator.rb:287:in `log_query'
from data_replicator.rb:221:in `replicate_table'
from data_replicator.rb:93:in `replicate'
from data_replicator.rb:20:in `run'
This gives me something better to search on!
The maximum number of placeholders for values in a prepared statement is the maximum value of a 16-bit unsigned integer, or specfically: 65,536.
This can be seen in the MySQL code here: sql/sql_prepare.cc:
static bool init_param_array(Prepared_statement *stmt)
{
LEX *lex= stmt->lex;
if ((stmt->param_count= lex->param_list.elements))
{
if (stmt->param_count > (uint) UINT_MAX16)
{
/* Error code to be defined in 5.0 */
my_message(ER_PS_MANY_PARAM, ER(ER_PS_MANY_PARAM), MYF(0));
return TRUE;
}
There is limit 65,535 (2^16-1) place holders in MariaDB 5.5 which is supposed to have identical behaviour as MySQL 5.5.
Not sure if relevant, I tested it on PHP 5.5.12 using MySQLi / MySQLND.
The MariaDB documentation says the default limit is 16.382. And depending on the version there is a hard limit at 4.294.967.295 (>= MariaDB 10.3.6) or 1.048.576 (<= MariaDB 10.3.5).
From http://dev.mysql.com/doc/refman/5.0/en/sql-syntax-prepared-statements.html :
To guard against too many prepared statements being created simultaneously, set the max_prepared_stmt_count system variable.
According to the max_prepared_stmt_count documentation, the default is 16_382, and the permissible range is 0 (which disables prepared statements altogether), to 1_000_000.
精彩评论