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
d7ae5de8
Commit
d7ae5de8
authored
Aug 12, 2004
by
bell@sanja.is.com.ua
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
in case of compound index fill all parts in optimized IN (BUG#4435)
parent
83efb948
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
101 additions
and
61 deletions
+101
-61
mysql-test/r/subselect.result
mysql-test/r/subselect.result
+21
-0
mysql-test/t/subselect.test
mysql-test/t/subselect.test
+16
-0
sql/item_subselect.cc
sql/item_subselect.cc
+64
-61
No files found.
mysql-test/r/subselect.result
View file @
d7ae5de8
...
...
@@ -1899,3 +1899,24 @@ select t000.a, count(*) `C` FROM t1 t000 GROUP BY t000.a HAVING count(*) > ALL (
a C
1 1
drop table t1,t2;
CREATE TABLE `t1` ( `aid` int(11) NOT NULL default '0', `bid` int(11) NOT NULL default '0', PRIMARY KEY (`aid`,`bid`));
CREATE TABLE `t2` ( `aid` int(11) NOT NULL default '0', `bid` int(11) NOT NULL default '0', PRIMARY KEY (`aid`,`bid`));
insert into t1 values (1,1),(1,2),(2,1),(2,2);
insert into t2 values (1,2),(2,2);
select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid);
aid bid
1 1
2 1
alter table t2 drop primary key;
alter table t2 add key KEY1 (aid, bid);
select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid);
aid bid
1 1
2 1
alter table t2 drop key KEY1;
alter table t2 add primary key (bid, aid);
select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid);
aid bid
1 1
2 1
drop table t1,t2;
mysql-test/t/subselect.test
View file @
d7ae5de8
...
...
@@ -1222,3 +1222,19 @@ CREATE TABLE `t2` ( `b` int(11) default NULL, `a` int(11) default NULL) ENGINE=M
insert
into
t2
values
(
1
,
2
);
select
t000
.
a
,
count
(
*
)
`C`
FROM
t1
t000
GROUP
BY
t000
.
a
HAVING
count
(
*
)
>
ALL
(
SELECT
count
(
*
)
FROM
t2
t001
WHERE
t001
.
a
=
1
);
drop
table
t1
,
t2
;
#
# Optimized IN with compound index
#
CREATE
TABLE
`t1`
(
`aid`
int
(
11
)
NOT
NULL
default
'0'
,
`bid`
int
(
11
)
NOT
NULL
default
'0'
,
PRIMARY
KEY
(
`aid`
,
`bid`
));
CREATE
TABLE
`t2`
(
`aid`
int
(
11
)
NOT
NULL
default
'0'
,
`bid`
int
(
11
)
NOT
NULL
default
'0'
,
PRIMARY
KEY
(
`aid`
,
`bid`
));
insert
into
t1
values
(
1
,
1
),(
1
,
2
),(
2
,
1
),(
2
,
2
);
insert
into
t2
values
(
1
,
2
),(
2
,
2
);
select
*
from
t1
where
t1
.
aid
not
in
(
select
aid
from
t2
where
bid
=
t1
.
bid
);
alter
table
t2
drop
primary
key
;
alter
table
t2
add
key
KEY1
(
aid
,
bid
);
select
*
from
t1
where
t1
.
aid
not
in
(
select
aid
from
t2
where
bid
=
t1
.
bid
);
alter
table
t2
drop
key
KEY1
;
alter
table
t2
add
primary
key
(
bid
,
aid
);
select
*
from
t1
where
t1
.
aid
not
in
(
select
aid
from
t2
where
bid
=
t1
.
bid
);
drop
table
t1
,
t2
;
sql/item_subselect.cc
View file @
d7ae5de8
...
...
@@ -1243,29 +1243,31 @@ int subselect_uniquesubquery_engine::exec()
DBUG_ENTER
(
"subselect_uniquesubquery_engine::exec"
);
int
error
;
TABLE
*
table
=
tab
->
table
;
if
((
tab
->
ref
.
key_err
=
(
*
tab
->
ref
.
key_copy
)
->
copy
())
)
for
(
store_key
**
copy
=
tab
->
ref
.
key_copy
;
*
copy
;
copy
++
)
{
table
->
status
=
STATUS_NOT_FOUND
;
error
=
-
1
;
if
(
tab
->
ref
.
key_err
=
(
*
copy
)
->
copy
())
{
table
->
status
=
STATUS_NOT_FOUND
;
DBUG_RETURN
(
1
);
}
}
if
(
!
table
->
file
->
inited
)
table
->
file
->
ha_index_init
(
tab
->
ref
.
key
);
error
=
table
->
file
->
index_read
(
table
->
record
[
0
],
tab
->
ref
.
key_buff
,
tab
->
ref
.
key_length
,
HA_READ_KEY_EXACT
);
if
(
error
&&
error
!=
HA_ERR_KEY_NOT_FOUND
)
error
=
report_error
(
table
,
error
);
else
{
if
(
!
table
->
file
->
inited
)
table
->
file
->
ha_index_init
(
tab
->
ref
.
key
);
error
=
table
->
file
->
index_read
(
table
->
record
[
0
],
tab
->
ref
.
key_buff
,
tab
->
ref
.
key_length
,
HA_READ_KEY_EXACT
);
if
(
error
&&
error
!=
HA_ERR_KEY_NOT_FOUND
)
error
=
report_error
(
table
,
error
);
else
{
error
=
0
;
table
->
null_row
=
0
;
((
Item_in_subselect
*
)
item
)
->
value
=
(
!
table
->
status
&&
(
!
cond
||
cond
->
val_int
())
?
1
:
0
);
}
error
=
0
;
table
->
null_row
=
0
;
((
Item_in_subselect
*
)
item
)
->
value
=
(
!
table
->
status
&&
(
!
cond
||
cond
->
val_int
())
?
1
:
0
);
}
DBUG_RETURN
(
error
!=
0
);
}
...
...
@@ -1293,55 +1295,56 @@ int subselect_indexsubquery_engine::exec()
((
Item_in_subselect
*
)
item
)
->
was_null
=
0
;
}
if
((
*
tab
->
ref
.
key_copy
)
&&
(
tab
->
ref
.
key_err
=
(
*
tab
->
ref
.
key_copy
)
->
copy
())
)
for
(
store_key
**
copy
=
tab
->
ref
.
key_copy
;
*
copy
;
copy
++
)
{
table
->
status
=
STATUS_NOT_FOUND
;
error
=
-
1
;
if
(
tab
->
ref
.
key_err
=
(
*
copy
)
->
copy
())
{
table
->
status
=
STATUS_NOT_FOUND
;
DBUG_RETURN
(
1
);
}
}
if
(
!
table
->
file
->
inited
)
table
->
file
->
ha_index_init
(
tab
->
ref
.
key
);
error
=
table
->
file
->
index_read
(
table
->
record
[
0
],
tab
->
ref
.
key_buff
,
tab
->
ref
.
key_length
,
HA_READ_KEY_EXACT
);
if
(
error
&&
error
!=
HA_ERR_KEY_NOT_FOUND
)
error
=
report_error
(
table
,
error
);
else
{
if
(
!
table
->
file
->
inited
)
table
->
file
->
ha_index_init
(
tab
->
ref
.
key
);
error
=
table
->
file
->
index_read
(
table
->
record
[
0
],
tab
->
ref
.
key_buff
,
tab
->
ref
.
key_length
,
HA_READ_KEY_EXACT
);
if
(
error
&&
error
!=
HA_ERR_KEY_NOT_FOUND
)
error
=
report_error
(
table
,
error
);
else
for
(;;)
{
for
(;;)
error
=
0
;
table
->
null_row
=
0
;
if
(
!
table
->
status
)
{
error
=
0
;
table
->
null_row
=
0
;
if
(
!
table
->
status
)
{
if
(
!
cond
||
cond
->
val_int
())
{
if
(
null_finding
)
((
Item_in_subselect
*
)
item
)
->
was_null
=
1
;
else
((
Item_in_subselect
*
)
item
)
->
value
=
1
;
break
;
}
error
=
table
->
file
->
index_next_same
(
table
->
record
[
0
],
tab
->
ref
.
key_buff
,
tab
->
ref
.
key_length
);
if
(
error
&&
error
!=
HA_ERR_END_OF_FILE
)
{
error
=
report_error
(
table
,
error
);
break
;
}
}
else
{
if
(
!
check_null
||
null_finding
)
break
;
/* We don't need to check nulls */
*
tab
->
ref
.
null_ref_key
=
1
;
null_finding
=
1
;
/* Check if there exists a row with a null value in the index */
if
((
error
=
(
safe_index_read
(
tab
)
==
1
)))
break
;
}
if
(
!
cond
||
cond
->
val_int
())
{
if
(
null_finding
)
((
Item_in_subselect
*
)
item
)
->
was_null
=
1
;
else
((
Item_in_subselect
*
)
item
)
->
value
=
1
;
break
;
}
error
=
table
->
file
->
index_next_same
(
table
->
record
[
0
],
tab
->
ref
.
key_buff
,
tab
->
ref
.
key_length
);
if
(
error
&&
error
!=
HA_ERR_END_OF_FILE
)
{
error
=
report_error
(
table
,
error
);
break
;
}
}
else
{
if
(
!
check_null
||
null_finding
)
break
;
/* We don't need to check nulls */
*
tab
->
ref
.
null_ref_key
=
1
;
null_finding
=
1
;
/* Check if there exists a row with a null value in the index */
if
((
error
=
(
safe_index_read
(
tab
)
==
1
)))
break
;
}
}
}
...
...
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