Description:
MySQL manual says:
http://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html#sysvar_sql_select_limi...
"sql_select_limit does not apply to SELECT statements executed within stored routines."
This works in stored procedures.
See also Bug #24489.
How to repeat:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.25 MySQL Community Server (GPL)
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use mydatabase;
Database changed
mysql> /*Table structure for table `bug_sql_select_limit_table` */
mysql> DROP TABLE IF EXISTS `bug_sql_select_limit_table`;
Query OK, 0 rows affected (0.00 sec)
mysql> create table `bug_sql_select_limit_table` (
-> `id` int(10) unsigned not null auto_increment,
-> `date` timestamp not null default current_timestamp on update current_timestamp,
-> primary key (`id`)
-> ) engine=innodb;
Query OK, 0 rows affected (0.02 sec)
mysql> /*Data for the table `bug_sql_select_limit_table` */
mysql> insert into `bug_sql_select_limit_table`(`date`)
-> values
-> ('2012-06-18 15:49:02'),('2012-06-18 15:49:03'),
-> ('2012-06-18 15:49:04'),('2012-06-18 15:49:05'),
-> ('2012-06-18 15:49:06'),('2012-06-18 15:49:07'),
-> ('2012-06-18 15:49:08'),('2012-06-18 15:49:09');
Query OK, 8 rows affected (0.01 sec)
Records: 8 Duplicates: 0 Warnings: 0
mysql> /* procedure structure for procedure `bug_sql_select_limit_procedure` */
mysql> /*!50003 drop procedure if exists `bug_sql_select_limit_procedure` */;
Query OK, 0 rows affected (0.00 sec)
mysql> delimiter $$
mysql> /*!50003 create procedure `bug_sql_select_limit_procedure`(`p_limit` int)
-> begin
-> if not (`p_limit` < 0) then
-> set @@session.sql_select_limit := `p_limit`;
-> end if;
-> select `id`, `date` from `bug_sql_select_limit_table`;
-> end */$$
Query OK, 0 rows affected (0.00 sec)
mysql> delimiter ;
mysql> call `bug_sql_select_limit_procedure`(2);
+----+---------------------+
| id | date |
+----+---------------------+
| 1 | 2012-06-18 15:49:02 |
| 2 | 2012-06-18 15:49:03 |
+----+---------------------+
2 rows in set (0.00 sec)
Query OK, 0 rows affected (0.01 sec)