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
08f8ab59
Commit
08f8ab59
authored
Jun 28, 2003
by
bell@sanja.is.com.ua
Browse files
Options
Browse Files
Download
Plain Diff
Merge
parents
a101fc9e
b171910b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
27 deletions
+66
-27
mysql-test/r/subselect.result
mysql-test/r/subselect.result
+5
-0
mysql-test/t/subselect.test
mysql-test/t/subselect.test
+10
-0
sql/item.cc
sql/item.cc
+51
-27
No files found.
mysql-test/r/subselect.result
View file @
08f8ab59
...
@@ -1153,6 +1153,11 @@ INSERT INTO t1 VALUES (1,0,NULL,NULL),(2,0,NULL,NULL);
...
@@ -1153,6 +1153,11 @@ INSERT INTO t1 VALUES (1,0,NULL,NULL),(2,0,NULL,NULL);
SELECT DISTINCT REF_ID FROM t1 WHERE ID= (SELECT DISTINCT REF_ID FROM t1 WHERE ID=2);
SELECT DISTINCT REF_ID FROM t1 WHERE ID= (SELECT DISTINCT REF_ID FROM t1 WHERE ID=2);
REF_ID
REF_ID
DROP TABLE t1;
DROP TABLE t1;
create table t1(City VARCHAR(30),Location geometry);
insert into t1 values("Paris",GeomFromText('POINT(2.33 48.87)'));
select City from t1 where (select intersects(GeomFromText(AsText(Location)),GeomFromText('Polygon((2 50, 2.5 50, 2.5 47, 2 47, 2 50))'))=0);
City
drop table t1;
CREATE TABLE `t1` (
CREATE TABLE `t1` (
`id` mediumint(8) unsigned NOT NULL auto_increment,
`id` mediumint(8) unsigned NOT NULL auto_increment,
`pseudo` varchar(35) NOT NULL default '',
`pseudo` varchar(35) NOT NULL default '',
...
...
mysql-test/t/subselect.test
View file @
08f8ab59
...
@@ -738,6 +738,16 @@ CREATE TABLE t1 (
...
@@ -738,6 +738,16 @@ CREATE TABLE t1 (
INSERT
INTO
t1
VALUES
(
1
,
0
,
NULL
,
NULL
),(
2
,
0
,
NULL
,
NULL
);
INSERT
INTO
t1
VALUES
(
1
,
0
,
NULL
,
NULL
),(
2
,
0
,
NULL
,
NULL
);
SELECT
DISTINCT
REF_ID
FROM
t1
WHERE
ID
=
(
SELECT
DISTINCT
REF_ID
FROM
t1
WHERE
ID
=
2
);
SELECT
DISTINCT
REF_ID
FROM
t1
WHERE
ID
=
(
SELECT
DISTINCT
REF_ID
FROM
t1
WHERE
ID
=
2
);
DROP
TABLE
t1
;
DROP
TABLE
t1
;
#
# correct behavoiur for function from reduced subselect
#
create
table
t1
(
City
VARCHAR
(
30
),
Location
geometry
);
insert
into
t1
values
(
"Paris"
,
GeomFromText
(
'POINT(2.33 48.87)'
));
select
City
from
t1
where
(
select
intersects
(
GeomFromText
(
AsText
(
Location
)),
GeomFromText
(
'Polygon((2 50, 2.5 50, 2.5 47, 2 47, 2 50))'
))
=
0
);
drop
table
t1
;
#
#
# reduced subselect in ORDER BY & GROUP BY clauses
# reduced subselect in ORDER BY & GROUP BY clauses
#
#
...
...
sql/item.cc
View file @
08f8ab59
...
@@ -23,6 +23,10 @@
...
@@ -23,6 +23,10 @@
#include <m_ctype.h>
#include <m_ctype.h>
#include "my_dir.h"
#include "my_dir.h"
static
void
mark_as_dependent
(
bool
outer_resolving
,
SELECT_LEX
*
last
,
SELECT_LEX_NODE
*
current
,
Item_ident
*
item
);
/*****************************************************************************
/*****************************************************************************
** Item functions
** Item functions
*****************************************************************************/
*****************************************************************************/
...
@@ -786,6 +790,37 @@ bool Item_ref_null_helper::get_date(TIME *ltime, bool fuzzydate)
...
@@ -786,6 +790,37 @@ bool Item_ref_null_helper::get_date(TIME *ltime, bool fuzzydate)
return
(
owner
->
was_null
|=
null_value
=
(
*
ref
)
->
get_date
(
ltime
,
fuzzydate
));
return
(
owner
->
was_null
|=
null_value
=
(
*
ref
)
->
get_date
(
ltime
,
fuzzydate
));
}
}
/*
Mark item and SELECT_LEXs as dependent if it is not outer resolving
SYNOPSIS
mark_as_dependent()
outer_resolving - flag of outer resolving
last - select from which current item depend
current - current select
item - item which should be marked
*/
static
void
mark_as_dependent
(
bool
outer_resolving
,
SELECT_LEX
*
last
,
SELECT_LEX_NODE
*
current
,
Item_ident
*
item
)
{
/*
only last check is need, i.e.
"last != current"
first check added for speed up (check boolean should be faster
then comparing pointers and this condition usually true)
*/
if
(
!
outer_resolving
||
((
SELECT_LEX_NODE
*
)
last
)
!=
current
)
{
// store pointer on SELECT_LEX from wich item is dependent
item
->
depended_from
=
last
;
current
->
mark_as_dependent
(
last
);
}
}
bool
Item_field
::
fix_fields
(
THD
*
thd
,
TABLE_LIST
*
tables
,
Item
**
ref
)
bool
Item_field
::
fix_fields
(
THD
*
thd
,
TABLE_LIST
*
tables
,
Item
**
ref
)
{
{
if
(
!
field
)
// If field is not checked
if
(
!
field
)
// If field is not checked
...
@@ -857,29 +892,22 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
...
@@ -857,29 +892,22 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
return
-
1
;
return
-
1
;
}
}
Item_ref
*
r
;
Item_ref
*
r
f
;
*
ref
=
r
=
new
Item_ref
(
last
->
ref_pointer_array
+
counter
*
ref
=
r
f
=
new
Item_ref
(
last
->
ref_pointer_array
+
counter
,
,
(
char
*
)
table_name
,
(
char
*
)
table_name
,
(
char
*
)
field_name
);
(
char
*
)
field_name
);
if
(
!
r
)
if
(
!
r
f
)
return
1
;
return
1
;
if
(
r
->
fix_fields
(
thd
,
tables
,
ref
)
||
r
->
check_cols
(
1
))
if
(
r
f
->
fix_fields
(
thd
,
tables
,
ref
)
||
rf
->
check_cols
(
1
))
return
1
;
return
1
;
// store pointer on SELECT_LEX from which item is dependent
r
->
depended_from
=
last
;
mark_as_dependent
(
outer_resolving
,
last
,
cursel
,
rf
);
cursel
->
mark_as_dependent
(
last
);
return
0
;
return
0
;
}
}
else
else
{
{
// store pointer on SELECT_LEX from wich item is dependent
mark_as_dependent
(
outer_resolving
,
last
,
cursel
,
this
);
depended_from
=
last
;
if
(
last
->
having_fix_field
)
/*
Mark all selects from resolved to 1 before select where was
found table as depended (of select where was found table)
*/
thd
->
lex
.
current_select
->
mark_as_dependent
(
last
);
if
(
depended_from
->
having_fix_field
)
{
{
Item_ref
*
rf
;
Item_ref
*
rf
;
*
ref
=
rf
=
new
Item_ref
((
where
->
db
[
0
]
?
where
->
db
:
0
),
*
ref
=
rf
=
new
Item_ref
((
where
->
db
[
0
]
?
where
->
db
:
0
),
...
@@ -1351,12 +1379,10 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference)
...
@@ -1351,12 +1379,10 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference)
else
if
(
tmp
!=
not_found_field
)
else
if
(
tmp
!=
not_found_field
)
{
{
ref
=
0
;
// To prevent "delete *ref;" on ~Item_erf() of this item
ref
=
0
;
// To prevent "delete *ref;" on ~Item_erf() of this item
Item_field
*
f
;
Item_field
*
f
ld
;
if
(
!
((
*
reference
)
=
f
=
new
Item_field
(
tmp
)))
if
(
!
((
*
reference
)
=
f
ld
=
new
Item_field
(
tmp
)))
return
1
;
return
1
;
// store pointer on SELECT_LEX from wich item is dependent
mark_as_dependent
(
outer_resolving
,
last
,
thd
->
lex
.
current_select
,
fld
);
f
->
depended_from
=
last
;
thd
->
lex
.
current_select
->
mark_as_dependent
(
last
);
return
0
;
return
0
;
}
}
else
else
...
@@ -1367,11 +1393,9 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference)
...
@@ -1367,11 +1393,9 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference)
"forward reference in item list"
);
"forward reference in item list"
);
return
-
1
;
return
-
1
;
}
}
/*
mark_as_dependent
(
outer_resolving
,
last
,
thd
->
lex
.
current_select
,
depended_from: pointer on SELECT_LEX from wich item is dependent
this
);
*/
ref
=
last
->
ref_pointer_array
+
counter
;
ref
=
(
depended_from
=
last
)
->
ref_pointer_array
+
counter
;
thd
->
lex
.
current_select
->
mark_as_dependent
(
last
);
}
}
}
}
else
if
(
!
ref
)
else
if
(
!
ref
)
...
...
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