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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
fbabd085
Commit
fbabd085
authored
Oct 27, 2004
by
unknown
Browse files
Options
Browse Files
Download
Plain Diff
Merge sanja.is.com.ua:/home/bell/mysql/bk/mysql-4.1
into sanja.is.com.ua:/home/bell/mysql/bk/work-ps-4.1
parents
447fef48
a94c7639
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
91 additions
and
24 deletions
+91
-24
mysql-test/r/subselect.result
mysql-test/r/subselect.result
+9
-6
mysql-test/t/subselect.test
mysql-test/t/subselect.test
+2
-3
sql/item_subselect.cc
sql/item_subselect.cc
+76
-15
sql/item_subselect.h
sql/item_subselect.h
+4
-0
No files found.
mysql-test/r/subselect.result
View file @
fbabd085
...
@@ -55,7 +55,7 @@ SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
...
@@ -55,7 +55,7 @@ SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
1
1
1
1
SELECT (SELECT 1), a;
SELECT (SELECT 1), a;
ERROR 42S22: Unknown column 'a' in '
checking transformed subquery
'
ERROR 42S22: Unknown column 'a' in '
field list
'
SELECT 1 as a FROM (SELECT 1) as b HAVING (SELECT a)=1;
SELECT 1 as a FROM (SELECT 1) as b HAVING (SELECT a)=1;
a
a
1
1
...
@@ -999,7 +999,9 @@ drop table t1, t2;
...
@@ -999,7 +999,9 @@ drop table t1, t2;
CREATE TABLE `t1` (`i` int(11) NOT NULL default '0',PRIMARY KEY (`i`)) ENGINE=MyISAM CHARSET=latin1;
CREATE TABLE `t1` (`i` int(11) NOT NULL default '0',PRIMARY KEY (`i`)) ENGINE=MyISAM CHARSET=latin1;
INSERT INTO t1 VALUES (1);
INSERT INTO t1 VALUES (1);
UPDATE t1 SET i=i+1 WHERE i=(SELECT MAX(i));
UPDATE t1 SET i=i+1 WHERE i=(SELECT MAX(i));
ERROR HY000: Invalid use of group function
select * from t1;
i
1
drop table t1;
drop table t1;
CREATE TABLE t1 (a int(1));
CREATE TABLE t1 (a int(1));
EXPLAIN EXTENDED SELECT (SELECT RAND() FROM t1) FROM t1;
EXPLAIN EXTENDED SELECT (SELECT RAND() FROM t1) FROM t1;
...
@@ -1084,7 +1086,7 @@ SHOW CREATE TABLE t1;
...
@@ -1084,7 +1086,7 @@ SHOW CREATE TABLE t1;
Table Create Table
Table Create Table
t1 CREATE TABLE `t1` (
t1 CREATE TABLE `t1` (
`a` bigint(20) NOT NULL default '0',
`a` bigint(20) NOT NULL default '0',
`(SELECT a)` bigint(20)
default NULL
`(SELECT a)` bigint(20)
NOT NULL default '0'
) ENGINE=MyISAM DEFAULT CHARSET=latin1
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
drop table t1;
CREATE TABLE t1 SELECT * FROM (SELECT 1 as a,(SELECT a+0)) a;
CREATE TABLE t1 SELECT * FROM (SELECT 1 as a,(SELECT a+0)) a;
...
@@ -1102,7 +1104,7 @@ a
...
@@ -1102,7 +1104,7 @@ a
SHOW CREATE TABLE t1;
SHOW CREATE TABLE t1;
Table Create Table
Table Create Table
t1 CREATE TABLE `t1` (
t1 CREATE TABLE `t1` (
`a` bigint(20)
default NULL
`a` bigint(20)
NOT NULL default '0'
) ENGINE=MyISAM DEFAULT CHARSET=latin1
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
drop table t1;
create table t1 (a int);
create table t1 (a int);
...
@@ -1186,11 +1188,12 @@ PRIMARY KEY (`i`)
...
@@ -1186,11 +1188,12 @@ PRIMARY KEY (`i`)
) ENGINE=MyISAM CHARSET=latin1;
) ENGINE=MyISAM CHARSET=latin1;
INSERT INTO t1 VALUES (1);
INSERT INTO t1 VALUES (1);
UPDATE t1 SET i=i+(SELECT MAX(i) FROM (SELECT 1) t) WHERE i=(SELECT MAX(i));
UPDATE t1 SET i=i+(SELECT MAX(i) FROM (SELECT 1) t) WHERE i=(SELECT MAX(i));
ERROR HY000: Invalid use of group function
UPDATE t1 SET i=i+1 WHERE i=(SELECT MAX(i));
UPDATE t1 SET i=i+1 WHERE i=(SELECT MAX(i));
ERROR HY000: Invalid use of group function
UPDATE t1 SET t.i=i+(SELECT MAX(i) FROM (SELECT 1) t);
UPDATE t1 SET t.i=i+(SELECT MAX(i) FROM (SELECT 1) t);
ERROR 42S02: Unknown table 't' in field list
ERROR 42S02: Unknown table 't' in field list
select * from t1;
i
1
drop table t1;
drop table t1;
CREATE TABLE t1 (
CREATE TABLE t1 (
id int(11) default NULL
id int(11) default NULL
...
...
mysql-test/t/subselect.test
View file @
fbabd085
...
@@ -543,8 +543,8 @@ drop table t1, t2;
...
@@ -543,8 +543,8 @@ drop table t1, t2;
CREATE
TABLE
`t1`
(
`i`
int
(
11
)
NOT
NULL
default
'0'
,
PRIMARY
KEY
(
`i`
))
ENGINE
=
MyISAM
CHARSET
=
latin1
;
CREATE
TABLE
`t1`
(
`i`
int
(
11
)
NOT
NULL
default
'0'
,
PRIMARY
KEY
(
`i`
))
ENGINE
=
MyISAM
CHARSET
=
latin1
;
INSERT
INTO
t1
VALUES
(
1
);
INSERT
INTO
t1
VALUES
(
1
);
--
error
1111
UPDATE
t1
SET
i
=
i
+
1
WHERE
i
=
(
SELECT
MAX
(
i
));
UPDATE
t1
SET
i
=
i
+
1
WHERE
i
=
(
SELECT
MAX
(
i
));
select
*
from
t1
;
drop
table
t1
;
drop
table
t1
;
#test of uncacheable subqueries
#test of uncacheable subqueries
...
@@ -689,12 +689,11 @@ CREATE TABLE `t1` (
...
@@ -689,12 +689,11 @@ CREATE TABLE `t1` (
)
ENGINE
=
MyISAM
CHARSET
=
latin1
;
)
ENGINE
=
MyISAM
CHARSET
=
latin1
;
INSERT
INTO
t1
VALUES
(
1
);
INSERT
INTO
t1
VALUES
(
1
);
--
error
1111
UPDATE
t1
SET
i
=
i
+
(
SELECT
MAX
(
i
)
FROM
(
SELECT
1
)
t
)
WHERE
i
=
(
SELECT
MAX
(
i
));
UPDATE
t1
SET
i
=
i
+
(
SELECT
MAX
(
i
)
FROM
(
SELECT
1
)
t
)
WHERE
i
=
(
SELECT
MAX
(
i
));
--
error
1111
UPDATE
t1
SET
i
=
i
+
1
WHERE
i
=
(
SELECT
MAX
(
i
));
UPDATE
t1
SET
i
=
i
+
1
WHERE
i
=
(
SELECT
MAX
(
i
));
--
error
1109
--
error
1109
UPDATE
t1
SET
t
.
i
=
i
+
(
SELECT
MAX
(
i
)
FROM
(
SELECT
1
)
t
);
UPDATE
t1
SET
t
.
i
=
i
+
(
SELECT
MAX
(
i
)
FROM
(
SELECT
1
)
t
);
select
*
from
t1
;
drop
table
t1
;
drop
table
t1
;
#
#
...
...
sql/item_subselect.cc
View file @
fbabd085
...
@@ -164,12 +164,7 @@ bool Item_subselect::fix_fields(THD *thd_param, TABLE_LIST *tables, Item **ref)
...
@@ -164,12 +164,7 @@ bool Item_subselect::fix_fields(THD *thd_param, TABLE_LIST *tables, Item **ref)
thd
->
where
=
"checking transformed subquery"
;
thd
->
where
=
"checking transformed subquery"
;
if
(
!
(
*
ref
)
->
fixed
)
if
(
!
(
*
ref
)
->
fixed
)
ret
=
(
*
ref
)
->
fix_fields
(
thd
,
tables
,
ref
);
ret
=
(
*
ref
)
->
fix_fields
(
thd
,
tables
,
ref
);
// We can't substitute aggregate functions like "SELECT (max(i))"
thd
->
where
=
save_where
;
if
(
substype
()
==
SINGLEROW_SUBS
&&
(
*
ref
)
->
with_sum_func
)
{
my_error
(
ER_INVALID_GROUP_FUNC_USE
,
MYF
(
0
));
return
1
;
}
return
ret
;
return
ret
;
}
}
// Is it one field subselect?
// Is it one field subselect?
...
@@ -322,6 +317,7 @@ Item_singlerow_subselect::select_transformer(JOIN *join)
...
@@ -322,6 +317,7 @@ Item_singlerow_subselect::select_transformer(JOIN *join)
if
(
!
select_lex
->
master_unit
()
->
first_select
()
->
next_select
()
&&
if
(
!
select_lex
->
master_unit
()
->
first_select
()
->
next_select
()
&&
!
select_lex
->
table_list
.
elements
&&
!
select_lex
->
table_list
.
elements
&&
select_lex
->
item_list
.
elements
==
1
&&
select_lex
->
item_list
.
elements
==
1
&&
!
select_lex
->
item_list
.
head
()
->
with_sum_func
&&
/*
/*
We cant change name of Item_field or Item_ref, because it will
We cant change name of Item_field or Item_ref, because it will
prevent it's correct resolving, but we should save name of
prevent it's correct resolving, but we should save name of
...
@@ -330,7 +326,13 @@ Item_singlerow_subselect::select_transformer(JOIN *join)
...
@@ -330,7 +326,13 @@ Item_singlerow_subselect::select_transformer(JOIN *join)
TODO: solve above problem
TODO: solve above problem
*/
*/
!
(
select_lex
->
item_list
.
head
()
->
type
()
==
FIELD_ITEM
||
!
(
select_lex
->
item_list
.
head
()
->
type
()
==
FIELD_ITEM
||
select_lex
->
item_list
.
head
()
->
type
()
==
REF_ITEM
)
select_lex
->
item_list
.
head
()
->
type
()
==
REF_ITEM
)
&&
/*
switch off this optimisation for prepare statement,
because we do not rollback this changes
TODO: make rollback for it, or special name resolving mode in 5.0.
*/
!
arena
->
is_stmt_prepare
()
)
)
{
{
...
@@ -352,9 +354,6 @@ Item_singlerow_subselect::select_transformer(JOIN *join)
...
@@ -352,9 +354,6 @@ Item_singlerow_subselect::select_transformer(JOIN *join)
if
(
join
->
conds
||
join
->
having
)
if
(
join
->
conds
||
join
->
having
)
{
{
Item
*
cond
;
Item
*
cond
;
if
(
arena
->
is_stmt_prepare
())
thd
->
set_n_backup_item_arena
(
arena
,
&
backup
);
if
(
!
join
->
having
)
if
(
!
join
->
having
)
cond
=
join
->
conds
;
cond
=
join
->
conds
;
else
if
(
!
join
->
conds
)
else
if
(
!
join
->
conds
)
...
@@ -365,16 +364,12 @@ Item_singlerow_subselect::select_transformer(JOIN *join)
...
@@ -365,16 +364,12 @@ Item_singlerow_subselect::select_transformer(JOIN *join)
if
(
!
(
substitution
=
new
Item_func_if
(
cond
,
substitution
,
if
(
!
(
substitution
=
new
Item_func_if
(
cond
,
substitution
,
new
Item_null
())))
new
Item_null
())))
goto
err
;
goto
err
;
if
(
arena
->
is_stmt_prepare
())
}
thd
->
restore_backup_item_arena
(
arena
,
&
backup
);
}
return
RES_REDUCE
;
return
RES_REDUCE
;
}
}
return
RES_OK
;
return
RES_OK
;
err:
err:
if
(
arena
->
is_stmt_prepare
())
thd
->
restore_backup_item_arena
(
arena
,
&
backup
);
return
RES_ERROR
;
return
RES_ERROR
;
}
}
...
@@ -401,6 +396,13 @@ void Item_singlerow_subselect::fix_length_and_dec()
...
@@ -401,6 +396,13 @@ void Item_singlerow_subselect::fix_length_and_dec()
engine
->
fix_length_and_dec
(
row
);
engine
->
fix_length_and_dec
(
row
);
value
=
*
row
;
value
=
*
row
;
}
}
/*
If there are not tables in subquery then ability to have NULL value
depends on SELECT list (if single row subquery have tables then it
always can be NULL if there are not records fetched).
*/
if
(
engine
->
no_tables
())
maybe_null
=
engine
->
may_be_null
();
}
}
uint
Item_singlerow_subselect
::
cols
()
uint
Item_singlerow_subselect
::
cols
()
...
@@ -644,6 +646,7 @@ Item_subselect::trans_res
...
@@ -644,6 +646,7 @@ Item_subselect::trans_res
Item_in_subselect
::
single_value_transformer
(
JOIN
*
join
,
Item_in_subselect
::
single_value_transformer
(
JOIN
*
join
,
Comp_creator
*
func
)
Comp_creator
*
func
)
{
{
const
char
*
save_where
=
thd
->
where
;
DBUG_ENTER
(
"Item_in_subselect::single_value_transformer"
);
DBUG_ENTER
(
"Item_in_subselect::single_value_transformer"
);
if
(
changed
)
if
(
changed
)
...
@@ -899,6 +902,7 @@ Item_in_subselect::single_value_transformer(JOIN *join,
...
@@ -899,6 +902,7 @@ Item_in_subselect::single_value_transformer(JOIN *join,
ok:
ok:
if
(
arena
->
is_stmt_prepare
())
if
(
arena
->
is_stmt_prepare
())
thd
->
restore_backup_item_arena
(
arena
,
&
backup
);
thd
->
restore_backup_item_arena
(
arena
,
&
backup
);
thd
->
where
=
save_where
;
DBUG_RETURN
(
RES_OK
);
DBUG_RETURN
(
RES_OK
);
err:
err:
...
@@ -911,6 +915,7 @@ Item_in_subselect::single_value_transformer(JOIN *join,
...
@@ -911,6 +915,7 @@ Item_in_subselect::single_value_transformer(JOIN *join,
Item_subselect
::
trans_res
Item_subselect
::
trans_res
Item_in_subselect
::
row_value_transformer
(
JOIN
*
join
)
Item_in_subselect
::
row_value_transformer
(
JOIN
*
join
)
{
{
const
char
*
save_where
=
thd
->
where
;
DBUG_ENTER
(
"Item_in_subselect::row_value_transformer"
);
DBUG_ENTER
(
"Item_in_subselect::row_value_transformer"
);
if
(
changed
)
if
(
changed
)
...
@@ -1003,6 +1008,7 @@ Item_in_subselect::row_value_transformer(JOIN *join)
...
@@ -1003,6 +1008,7 @@ Item_in_subselect::row_value_transformer(JOIN *join)
}
}
if
(
arena
->
is_stmt_prepare
())
if
(
arena
->
is_stmt_prepare
())
thd
->
restore_backup_item_arena
(
arena
,
&
backup
);
thd
->
restore_backup_item_arena
(
arena
,
&
backup
);
thd
->
where
=
save_where
;
DBUG_RETURN
(
RES_OK
);
DBUG_RETURN
(
RES_OK
);
err:
err:
...
@@ -1562,3 +1568,58 @@ int subselect_uniquesubquery_engine::change_item(Item_subselect *si,
...
@@ -1562,3 +1568,58 @@ int subselect_uniquesubquery_engine::change_item(Item_subselect *si,
DBUG_ASSERT
(
0
);
DBUG_ASSERT
(
0
);
return
-
1
;
return
-
1
;
}
}
/*
Report about presence of tables in subquery
SINOPSYS
subselect_single_select_engine::no_tables()
RETURN
TRUE there are not tables used in subquery
FALSE there are some tables in subquery
*/
bool
subselect_single_select_engine
::
no_tables
()
{
return
(
select_lex
->
table_list
.
elements
==
0
);
}
/*
Report about presence of tables in subquery
SINOPSYS
subselect_union_engine::no_tables()
RETURN
TRUE there are not tables used in subquery
FALSE there are some tables in subquery
*/
bool
subselect_union_engine
::
no_tables
()
{
for
(
SELECT_LEX
*
sl
=
unit
->
first_select
();
sl
;
sl
=
sl
->
next_select
())
{
if
(
sl
->
table_list
.
elements
)
return
FALSE
;
}
return
TRUE
;
}
/*
Report about presence of tables in subquery
SINOPSYS
subselect_uniquesubquery_engine::no_tables()
RETURN
TRUE there are not tables used in subquery
FALSE there are some tables in subquery
*/
bool
subselect_uniquesubquery_engine
::
no_tables
()
{
/* returning value is correct, but this method should never be called */
return
0
;
}
sql/item_subselect.h
View file @
fbabd085
...
@@ -291,6 +291,7 @@ class subselect_engine: public Sql_alloc
...
@@ -291,6 +291,7 @@ class subselect_engine: public Sql_alloc
static
table_map
calc_const_tables
(
TABLE_LIST
*
);
static
table_map
calc_const_tables
(
TABLE_LIST
*
);
virtual
void
print
(
String
*
str
)
=
0
;
virtual
void
print
(
String
*
str
)
=
0
;
virtual
int
change_item
(
Item_subselect
*
si
,
select_subselect
*
result
)
=
0
;
virtual
int
change_item
(
Item_subselect
*
si
,
select_subselect
*
result
)
=
0
;
virtual
bool
no_tables
()
=
0
;
};
};
...
@@ -315,6 +316,7 @@ class subselect_single_select_engine: public subselect_engine
...
@@ -315,6 +316,7 @@ class subselect_single_select_engine: public subselect_engine
table_map
upper_select_const_tables
();
table_map
upper_select_const_tables
();
void
print
(
String
*
str
);
void
print
(
String
*
str
);
int
change_item
(
Item_subselect
*
si
,
select_subselect
*
result
);
int
change_item
(
Item_subselect
*
si
,
select_subselect
*
result
);
bool
no_tables
();
};
};
...
@@ -335,6 +337,7 @@ class subselect_union_engine: public subselect_engine
...
@@ -335,6 +337,7 @@ class subselect_union_engine: public subselect_engine
table_map
upper_select_const_tables
();
table_map
upper_select_const_tables
();
void
print
(
String
*
str
);
void
print
(
String
*
str
);
int
change_item
(
Item_subselect
*
si
,
select_subselect
*
result
);
int
change_item
(
Item_subselect
*
si
,
select_subselect
*
result
);
bool
no_tables
();
};
};
...
@@ -364,6 +367,7 @@ class subselect_uniquesubquery_engine: public subselect_engine
...
@@ -364,6 +367,7 @@ class subselect_uniquesubquery_engine: public subselect_engine
table_map
upper_select_const_tables
()
{
return
0
;
}
table_map
upper_select_const_tables
()
{
return
0
;
}
void
print
(
String
*
str
);
void
print
(
String
*
str
);
int
change_item
(
Item_subselect
*
si
,
select_subselect
*
result
);
int
change_item
(
Item_subselect
*
si
,
select_subselect
*
result
);
bool
no_tables
();
};
};
...
...
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