Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mariadb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
51ce56e6
Commit
51ce56e6
authored
Jul 13, 2005
by
unknown
Browse files
Options
Browse Files
Download
Plain Diff
Merge bk-internal.mysql.com:/home/bk/mysql-5.0
into mysql.com:/opt/local/work/mysql-5.0-root
parents
859ccd3b
91c97a76
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
135 additions
and
30 deletions
+135
-30
mysql-test/r/ps.result
mysql-test/r/ps.result
+57
-0
mysql-test/t/ps.test
mysql-test/t/ps.test
+68
-0
sql/item.cc
sql/item.cc
+1
-27
sql/item.h
sql/item.h
+0
-1
sql/item_subselect.h
sql/item_subselect.h
+0
-1
sql/sql_parse.cc
sql/sql_parse.cc
+5
-0
sql/sql_prepare.cc
sql/sql_prepare.cc
+4
-1
No files found.
mysql-test/r/ps.result
View file @
51ce56e6
...
...
@@ -681,3 +681,60 @@ execute stmt;
execute stmt;
deallocate prepare stmt;
drop table t1;
create table t1 (
id int(11) unsigned not null primary key auto_increment,
partner_id varchar(35) not null,
t1_status_id int(10) unsigned
);
insert into t1 values ("1", "partner1", "10"), ("2", "partner2", "10"),
("3", "partner3", "10"), ("4", "partner4", "10");
create table t2 (
id int(11) unsigned not null default '0',
t1_line_id int(11) unsigned not null default '0',
article_id varchar(20),
sequence int(11) not null default '0',
primary key (id,t1_line_id)
);
insert into t2 values ("1", "1", "sup", "0"), ("2", "1", "sup", "1"),
("2", "2", "sup", "2"), ("2", "3", "sup", "3"),
("2", "4", "imp", "4"), ("3", "1", "sup", "0"),
("4", "1", "sup", "0");
create table t3 (
id int(11) not null default '0',
preceeding_id int(11) not null default '0',
primary key (id,preceeding_id)
);
create table t4 (
user_id varchar(50) not null,
article_id varchar(20) not null,
primary key (user_id,article_id)
);
insert into t4 values("nicke", "imp");
prepare stmt from
'select distinct t1.partner_id
from t1 left join t3 on t1.id = t3.id
left join t1 pp on pp.id = t3.preceeding_id
where
exists (
select *
from t2 as pl_inner
where pl_inner.id = t1.id
and pl_inner.sequence <= (
select min(sequence) from t2 pl_seqnr
where pl_seqnr.id = t1.id
)
and exists (
select * from t4
where t4.article_id = pl_inner.article_id
and t4.user_id = ?
)
)
and t1.id = ?
group by t1.id
having count(pp.id) = 0';
set @user_id = 'nicke';
set @id = '2';
execute stmt using @user_id, @id;
partner_id
execute stmt using @user_id, @id;
partner_id
mysql-test/t/ps.test
View file @
51ce56e6
...
...
@@ -705,3 +705,71 @@ execute stmt;
execute
stmt
;
deallocate
prepare
stmt
;
drop
table
t1
;
#
# Bug#11458 "Prepared statement with subselects return random data":
# drop PARAM_TABLE_BIT from the list of tables used by a subquery
#
create
table
t1
(
id
int
(
11
)
unsigned
not
null
primary
key
auto_increment
,
partner_id
varchar
(
35
)
not
null
,
t1_status_id
int
(
10
)
unsigned
);
insert
into
t1
values
(
"1"
,
"partner1"
,
"10"
),
(
"2"
,
"partner2"
,
"10"
),
(
"3"
,
"partner3"
,
"10"
),
(
"4"
,
"partner4"
,
"10"
);
create
table
t2
(
id
int
(
11
)
unsigned
not
null
default
'0'
,
t1_line_id
int
(
11
)
unsigned
not
null
default
'0'
,
article_id
varchar
(
20
),
sequence
int
(
11
)
not
null
default
'0'
,
primary
key
(
id
,
t1_line_id
)
);
insert
into
t2
values
(
"1"
,
"1"
,
"sup"
,
"0"
),
(
"2"
,
"1"
,
"sup"
,
"1"
),
(
"2"
,
"2"
,
"sup"
,
"2"
),
(
"2"
,
"3"
,
"sup"
,
"3"
),
(
"2"
,
"4"
,
"imp"
,
"4"
),
(
"3"
,
"1"
,
"sup"
,
"0"
),
(
"4"
,
"1"
,
"sup"
,
"0"
);
create
table
t3
(
id
int
(
11
)
not
null
default
'0'
,
preceeding_id
int
(
11
)
not
null
default
'0'
,
primary
key
(
id
,
preceeding_id
)
);
create
table
t4
(
user_id
varchar
(
50
)
not
null
,
article_id
varchar
(
20
)
not
null
,
primary
key
(
user_id
,
article_id
)
);
insert
into
t4
values
(
"nicke"
,
"imp"
);
prepare
stmt
from
'select distinct t1.partner_id
from t1 left join t3 on t1.id = t3.id
left join t1 pp on pp.id = t3.preceeding_id
where
exists (
select *
from t2 as pl_inner
where pl_inner.id = t1.id
and pl_inner.sequence <= (
select min(sequence) from t2 pl_seqnr
where pl_seqnr.id = t1.id
)
and exists (
select * from t4
where t4.article_id = pl_inner.article_id
and t4.user_id = ?
)
)
and t1.id = ?
group by t1.id
having count(pp.id) = 0'
;
set
@
user_id
=
'nicke'
;
set
@
id
=
'2'
;
execute
stmt
using
@
user_id
,
@
id
;
execute
stmt
using
@
user_id
,
@
id
;
deallocate
prepare
stmt
;
drop
table
t1
,
t2
,
t3
,
t4
;
sql/item.cc
View file @
51ce56e6
...
...
@@ -1701,6 +1701,7 @@ void Item_param::set_null()
max_length
=
0
;
decimals
=
0
;
state
=
NULL_VALUE
;
item_type
=
Item
::
NULL_ITEM
;
DBUG_VOID_RETURN
;
}
...
...
@@ -2246,33 +2247,6 @@ bool Item_param::convert_str_value(THD *thd)
return
rc
;
}
bool
Item_param
::
fix_fields
(
THD
*
thd
,
Item
**
ref
)
{
DBUG_ASSERT
(
fixed
==
0
);
SELECT_LEX
*
cursel
=
(
SELECT_LEX
*
)
thd
->
lex
->
current_select
;
/*
Parameters in a subselect should mark the subselect as not constant
during prepare
*/
if
(
state
==
NO_VALUE
)
{
/*
SELECT_LEX_UNIT::item set only for subqueries, so test of it presence
can be barrier to stop before derived table SELECT or very outer SELECT
*/
for
(;
cursel
->
master_unit
()
->
item
;
cursel
=
cursel
->
outer_select
())
{
Item_subselect
*
subselect_item
=
cursel
->
master_unit
()
->
item
;
subselect_item
->
used_tables_cache
|=
OUTER_REF_TABLE_BIT
;
subselect_item
->
const_item_cache
=
0
;
}
}
fixed
=
1
;
return
0
;
}
bool
Item_param
::
basic_const_item
()
const
{
...
...
sql/item.h
View file @
51ce56e6
...
...
@@ -1039,7 +1039,6 @@ public:
bool
get_time
(
TIME
*
tm
);
bool
get_date
(
TIME
*
tm
,
uint
fuzzydate
);
int
save_in_field
(
Field
*
field
,
bool
no_conversions
);
bool
fix_fields
(
THD
*
,
Item
**
);
void
set_null
();
void
set_int
(
longlong
i
,
uint32
max_length_arg
);
...
...
sql/item_subselect.h
View file @
51ce56e6
...
...
@@ -121,7 +121,6 @@ public:
friend
class
Item_in_optimizer
;
friend
bool
Item_field
::
fix_fields
(
THD
*
,
Item
**
);
friend
bool
Item_ref
::
fix_fields
(
THD
*
,
Item
**
);
friend
bool
Item_param
::
fix_fields
(
THD
*
,
Item
**
);
friend
void
mark_select_range_as_dependent
(
THD
*
,
st_select_lex
*
,
st_select_lex
*
,
Field
*
,
Item
*
,
Item_ident
*
);
...
...
sql/sql_parse.cc
View file @
51ce56e6
...
...
@@ -5212,6 +5212,11 @@ mysql_new_select(LEX *lex, bool move_down)
select_lex
->
init_query
();
select_lex
->
init_select
();
select_lex
->
parent_lex
=
lex
;
/*
Don't evaluate this subquery during statement prepare even if
it's a constant one. The flag is switched off in the end of
mysql_stmt_prepare.
*/
if
(
thd
->
current_arena
->
is_stmt_prepare
())
select_lex
->
uncacheable
|=
UNCACHEABLE_PREPARE
;
if
(
move_down
)
...
...
sql/sql_prepare.cc
View file @
51ce56e6
...
...
@@ -1825,7 +1825,10 @@ bool mysql_stmt_prepare(THD *thd, char *packet, uint packet_length,
void
init_stmt_after_parse
(
THD
*
thd
,
LEX
*
lex
)
{
SELECT_LEX
*
sl
=
lex
->
all_selects_list
;
/*
Switch off a temporary flag that prevents evaluation of
subqueries in statement prepare.
*/
for
(;
sl
;
sl
=
sl
->
next_select_in_list
())
sl
->
uncacheable
&=
~
UNCACHEABLE_PREPARE
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment