mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
fixed subquery in the FROM clause with parameter (BUG#3020)
This commit is contained in:
@ -148,36 +148,42 @@ static int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit,
|
|||||||
}
|
}
|
||||||
derived_result->set_table(table);
|
derived_result->set_table(table);
|
||||||
|
|
||||||
|
/*
|
||||||
if (is_union)
|
if it is preparation PS only then we do not need real data and we
|
||||||
|
can skip execution (and parameters is not defined, too)
|
||||||
|
*/
|
||||||
|
if (!thd->current_statement)
|
||||||
{
|
{
|
||||||
// execute union without clean up
|
if (is_union)
|
||||||
if (!(res= unit->prepare(thd, derived_result, SELECT_NO_UNLOCK)))
|
{
|
||||||
res= unit->exec();
|
// execute union without clean up
|
||||||
}
|
if (!(res= unit->prepare(thd, derived_result, SELECT_NO_UNLOCK)))
|
||||||
else
|
res= unit->exec();
|
||||||
{
|
}
|
||||||
unit->offset_limit_cnt= first_select->offset_limit;
|
else
|
||||||
unit->select_limit_cnt= first_select->select_limit+
|
{
|
||||||
first_select->offset_limit;
|
unit->offset_limit_cnt= first_select->offset_limit;
|
||||||
if (unit->select_limit_cnt < first_select->select_limit)
|
unit->select_limit_cnt= first_select->select_limit+
|
||||||
unit->select_limit_cnt= HA_POS_ERROR;
|
first_select->offset_limit;
|
||||||
if (unit->select_limit_cnt == HA_POS_ERROR)
|
if (unit->select_limit_cnt < first_select->select_limit)
|
||||||
first_select->options&= ~OPTION_FOUND_ROWS;
|
unit->select_limit_cnt= HA_POS_ERROR;
|
||||||
|
if (unit->select_limit_cnt == HA_POS_ERROR)
|
||||||
|
first_select->options&= ~OPTION_FOUND_ROWS;
|
||||||
|
|
||||||
lex->current_select= first_select;
|
lex->current_select= first_select;
|
||||||
res= mysql_select(thd, &first_select->ref_pointer_array,
|
res= mysql_select(thd, &first_select->ref_pointer_array,
|
||||||
(TABLE_LIST*) first_select->table_list.first,
|
(TABLE_LIST*) first_select->table_list.first,
|
||||||
first_select->with_wild,
|
first_select->with_wild,
|
||||||
first_select->item_list, first_select->where,
|
first_select->item_list, first_select->where,
|
||||||
(first_select->order_list.elements+
|
(first_select->order_list.elements+
|
||||||
first_select->group_list.elements),
|
first_select->group_list.elements),
|
||||||
(ORDER *) first_select->order_list.first,
|
(ORDER *) first_select->order_list.first,
|
||||||
(ORDER *) first_select->group_list.first,
|
(ORDER *) first_select->group_list.first,
|
||||||
first_select->having, (ORDER*) NULL,
|
first_select->having, (ORDER*) NULL,
|
||||||
(first_select->options | thd->options |
|
(first_select->options | thd->options |
|
||||||
SELECT_NO_UNLOCK),
|
SELECT_NO_UNLOCK),
|
||||||
derived_result, unit, first_select);
|
derived_result, unit, first_select);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!res)
|
if (!res)
|
||||||
|
@ -8905,6 +8905,53 @@ static void test_bind_nagative()
|
|||||||
myquery(rc);
|
myquery(rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_derived()
|
||||||
|
{
|
||||||
|
MYSQL_STMT *stmt;
|
||||||
|
int rc, i;
|
||||||
|
MYSQL_BIND bind[1];
|
||||||
|
long my_val = 0L;
|
||||||
|
long my_length = 0L;
|
||||||
|
long my_null = 0L;
|
||||||
|
const char *query=
|
||||||
|
"select count(1) from (select f.id from t1 f where f.id=?) as x";
|
||||||
|
|
||||||
|
myheader("test_derived");
|
||||||
|
|
||||||
|
rc = mysql_query(mysql, "DROP TABLE IF EXISTS t1");
|
||||||
|
myquery(rc);
|
||||||
|
|
||||||
|
rc= mysql_query(mysql,"create table t1 (id int(8), primary key (id)) \
|
||||||
|
TYPE=InnoDB DEFAULT CHARSET=utf8");
|
||||||
|
myquery(rc);
|
||||||
|
|
||||||
|
rc= mysql_query(mysql, "insert into t1 values (1)");
|
||||||
|
myquery(rc);
|
||||||
|
|
||||||
|
stmt= mysql_prepare(mysql, query, strlen(query));
|
||||||
|
mystmt_init(stmt);
|
||||||
|
|
||||||
|
bind[0].buffer_type = FIELD_TYPE_LONG;
|
||||||
|
bind[0].buffer = (char *)&my_val;
|
||||||
|
bind[0].length = &my_length;
|
||||||
|
bind[0].is_null = (char*)&my_null;
|
||||||
|
my_val= 1;
|
||||||
|
rc= mysql_bind_param(stmt, bind);
|
||||||
|
mystmt(stmt,rc);
|
||||||
|
|
||||||
|
for (i= 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
rc= mysql_execute(stmt);
|
||||||
|
mystmt(stmt, rc);
|
||||||
|
assert(1 == my_process_stmt_result(stmt));
|
||||||
|
}
|
||||||
|
mysql_stmt_close(stmt);
|
||||||
|
|
||||||
|
rc= mysql_query(mysql, "DROP TABLE t1");
|
||||||
|
myquery(rc);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Read and parse arguments and MySQL options from my.cnf
|
Read and parse arguments and MySQL options from my.cnf
|
||||||
*/
|
*/
|
||||||
@ -9172,6 +9219,7 @@ int main(int argc, char **argv)
|
|||||||
test_multi(); /* test of multi delete & update */
|
test_multi(); /* test of multi delete & update */
|
||||||
test_insert_select(); /* test INSERT ... SELECT */
|
test_insert_select(); /* test INSERT ... SELECT */
|
||||||
test_bind_nagative(); /* bind negative to unsigned BUG#3223 */
|
test_bind_nagative(); /* bind negative to unsigned BUG#3223 */
|
||||||
|
test_derived(); /* derived table with parameter BUG#3020 */
|
||||||
|
|
||||||
end_time= time((time_t *)0);
|
end_time= time((time_t *)0);
|
||||||
total_time+= difftime(end_time, start_time);
|
total_time+= difftime(end_time, start_time);
|
||||||
|
Reference in New Issue
Block a user