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
75ff7d80
Commit
75ff7d80
authored
19 years ago
by
monty@mysql.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
After merge fixes
Better fix for ON DUPLICATE KEY UPDATE
parent
86d7b021
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
260 additions
and
266 deletions
+260
-266
mysql-test/r/group_by.result
mysql-test/r/group_by.result
+4
-2
mysql-test/r/select.result
mysql-test/r/select.result
+118
-118
mysql-test/t/group_by.test
mysql-test/t/group_by.test
+2
-2
mysql-test/t/select.test
mysql-test/t/select.test
+102
-103
sql/mysql_priv.h
sql/mysql_priv.h
+1
-2
sql/sql_base.cc
sql/sql_base.cc
+2
-1
sql/sql_insert.cc
sql/sql_insert.cc
+22
-29
sql/sql_prepare.cc
sql/sql_prepare.cc
+9
-9
No files found.
mysql-test/r/group_by.result
View file @
75ff7d80
...
...
@@ -721,13 +721,15 @@ SELECT hostname, COUNT(DISTINCT user_id) as no FROM t1
WHERE hostname LIKE '%aol%'
GROUP BY hostname;
hostname no
cache-dtc-af05.proxy.aol.com 1
DROP TABLE t1;
CREATE TABLE t1 (n int);
INSERT INTO t1 VALUES (1);
SELECT n+1 AS n FROM t1 GROUP BY n;
n
2
DROP TABLE t1;
cache-dtc-af05.proxy.aol.com 1
Warnings:
Warning 1052 Column 'n' in group statement is ambiguous
DROP TABLE t1;
CREATE TABLE t1 (a int, b int);
INSERT INTO t1 VALUES (1,2), (1,3);
...
...
This diff is collapsed.
Click to expand it.
mysql-test/r/select.result
View file @
75ff7d80
...
...
@@ -2423,12 +2423,130 @@ ERROR HY000: Incorrect usage of ALL and DISTINCT
select distinct all * from t1;
ERROR HY000: Incorrect usage of ALL and DISTINCT
drop table t1;
CREATE TABLE t1 (
kunde_intern_id int(10) unsigned NOT NULL default '0',
kunde_id int(10) unsigned NOT NULL default '0',
FK_firma_id int(10) unsigned NOT NULL default '0',
aktuell enum('Ja','Nein') NOT NULL default 'Ja',
vorname varchar(128) NOT NULL default '',
nachname varchar(128) NOT NULL default '',
geloescht enum('Ja','Nein') NOT NULL default 'Nein',
firma varchar(128) NOT NULL default ''
);
INSERT INTO t1 VALUES
(3964,3051,1,'Ja','Vorname1','1Nachname','Nein','Print Schau XXXX'),
(3965,3051111,1,'Ja','Vorname1111','1111Nachname','Nein','Print Schau XXXX');
SELECT kunde_id ,FK_firma_id ,aktuell, vorname, nachname, geloescht FROM t1
WHERE
(
(
( '' != '' AND firma LIKE CONCAT('%', '', '%'))
OR
(vorname LIKE CONCAT('%', 'Vorname1', '%') AND
nachname LIKE CONCAT('%', '1Nachname', '%') AND
'Vorname1' != '' AND 'xxxx' != '')
)
AND
(
aktuell = 'Ja' AND geloescht = 'Nein' AND FK_firma_id = 2
)
)
;
kunde_id FK_firma_id aktuell vorname nachname geloescht
SELECT kunde_id ,FK_firma_id ,aktuell, vorname, nachname,
geloescht FROM t1
WHERE
(
(
aktuell = 'Ja' AND geloescht = 'Nein' AND FK_firma_id = 2
)
AND
(
( '' != '' AND firma LIKE CONCAT('%', '', '%') )
OR
( vorname LIKE CONCAT('%', 'Vorname1', '%') AND
nachname LIKE CONCAT('%', '1Nachname', '%') AND 'Vorname1' != '' AND
'xxxx' != '')
)
)
;
kunde_id FK_firma_id aktuell vorname nachname geloescht
SELECT COUNT(*) FROM t1 WHERE
( 0 OR (vorname LIKE '%Vorname1%' AND nachname LIKE '%1Nachname%' AND 1))
AND FK_firma_id = 2;
COUNT(*)
0
drop table t1;
CREATE TABLE t1 (b BIGINT(20) UNSIGNED NOT NULL, PRIMARY KEY (b));
INSERT INTO t1 VALUES (0x8000000000000000);
SELECT b FROM t1 WHERE b=0x8000000000000000;
b
9223372036854775808
DROP TABLE t1;
CREATE TABLE `t1` ( `gid` int(11) default NULL, `uid` int(11) default NULL);
CREATE TABLE `t2` ( `ident` int(11) default NULL, `level` char(16) default NULL);
INSERT INTO `t2` VALUES (0,'READ');
CREATE TABLE `t3` ( `id` int(11) default NULL, `name` char(16) default NULL);
INSERT INTO `t3` VALUES (1,'fs');
select * from t3 left join t1 on t3.id = t1.uid, t2 where t2.ident in (0, t1.gid, t3.id, 0);
id name gid uid ident level
1 fs NULL NULL 0 READ
drop table t1,t2,t3;
CREATE TABLE t1 ( city char(30) );
INSERT INTO t1 VALUES ('London');
INSERT INTO t1 VALUES ('Paris');
SELECT * FROM t1 WHERE city='London';
city
London
SELECT * FROM t1 WHERE city='london';
city
London
EXPLAIN SELECT * FROM t1 WHERE city='London' AND city='london';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where
SELECT * FROM t1 WHERE city='London' AND city='london';
city
London
EXPLAIN SELECT * FROM t1 WHERE city LIKE '%london%' AND city='London';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where
SELECT * FROM t1 WHERE city LIKE '%london%' AND city='London';
city
London
DROP TABLE t1;
create table t1 (a int(11) unsigned, b int(11) unsigned);
insert into t1 values (1,0), (1,1), (1,2);
select a-b from t1 order by 1;
a-b
0
1
18446744073709551615
select a-b , (a-b < 0) from t1 order by 1;
a-b (a-b < 0)
0 0
1 0
18446744073709551615 0
select a-b as d, (a-b >= 0), b from t1 group by b having d >= 0;
d (a-b >= 0) b
1 1 0
0 1 1
18446744073709551615 1 2
select cast((a - b) as unsigned) from t1 order by 1;
cast((a - b) as unsigned)
0
1
18446744073709551615
drop table t1;
create table t1 (a int(11));
select all all * from t1;
a
select distinct distinct * from t1;
a
select all distinct * from t1;
ERROR HY000: Incorrect usage of ALL and DISTINCT
select distinct all * from t1;
ERROR HY000: Incorrect usage of ALL and DISTINCT
drop table t1;
CREATE TABLE t1 (
K2C4 varchar(4) character set latin1 collate latin1_bin NOT NULL default '',
K4N4 varchar(4) character set latin1 collate latin1_bin NOT NULL default '0000',
...
...
@@ -2573,124 +2691,6 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 5
1 SIMPLE t2 ref a a 23 test.t1.a 2
DROP TABLE t1, t2;
CREATE TABLE t1 ( city char(30) );
INSERT INTO t1 VALUES ('London');
INSERT INTO t1 VALUES ('Paris');
SELECT * FROM t1 WHERE city='London';
city
London
SELECT * FROM t1 WHERE city='london';
city
London
EXPLAIN SELECT * FROM t1 WHERE city='London' AND city='london';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where
SELECT * FROM t1 WHERE city='London' AND city='london';
city
London
EXPLAIN SELECT * FROM t1 WHERE city LIKE '%london%' AND city='London';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where
SELECT * FROM t1 WHERE city LIKE '%london%' AND city='London';
city
London
DROP TABLE t1;
create table t1 (a int(11) unsigned, b int(11) unsigned);
insert into t1 values (1,0), (1,1), (1,2);
select a-b from t1 order by 1;
a-b
0
1
18446744073709551615
select a-b , (a-b < 0) from t1 order by 1;
a-b (a-b < 0)
0 0
1 0
18446744073709551615 0
select a-b as d, (a-b >= 0), b from t1 group by b having d >= 0;
d (a-b >= 0) b
1 1 0
0 1 1
18446744073709551615 1 2
select cast((a - b) as unsigned) from t1 order by 1;
cast((a - b) as unsigned)
0
1
18446744073709551615
drop table t1;
create table t1 (a int(11));
select all all * from t1;
a
select distinct distinct * from t1;
a
select all distinct * from t1;
ERROR HY000: Incorrect usage of ALL and DISTINCT
select distinct all * from t1;
ERROR HY000: Incorrect usage of ALL and DISTINCT
drop table t1;
CREATE TABLE t1 (
kunde_intern_id int(10) unsigned NOT NULL default '0',
kunde_id int(10) unsigned NOT NULL default '0',
FK_firma_id int(10) unsigned NOT NULL default '0',
aktuell enum('Ja','Nein') NOT NULL default 'Ja',
vorname varchar(128) NOT NULL default '',
nachname varchar(128) NOT NULL default '',
geloescht enum('Ja','Nein') NOT NULL default 'Nein',
firma varchar(128) NOT NULL default ''
);
INSERT INTO t1 VALUES
(3964,3051,1,'Ja','Vorname1','1Nachname','Nein','Print Schau XXXX'),
(3965,3051111,1,'Ja','Vorname1111','1111Nachname','Nein','Print Schau XXXX');
SELECT kunde_id ,FK_firma_id ,aktuell, vorname, nachname, geloescht FROM t1
WHERE
(
(
( '' != '' AND firma LIKE CONCAT('%', '', '%'))
OR
(vorname LIKE CONCAT('%', 'Vorname1', '%') AND
nachname LIKE CONCAT('%', '1Nachname', '%') AND
'Vorname1' != '' AND 'xxxx' != '')
)
AND
(
aktuell = 'Ja' AND geloescht = 'Nein' AND FK_firma_id = 2
)
)
;
kunde_id FK_firma_id aktuell vorname nachname geloescht
SELECT kunde_id ,FK_firma_id ,aktuell, vorname, nachname,
geloescht FROM t1
WHERE
(
(
aktuell = 'Ja' AND geloescht = 'Nein' AND FK_firma_id = 2
)
AND
(
( '' != '' AND firma LIKE CONCAT('%', '', '%') )
OR
( vorname LIKE CONCAT('%', 'Vorname1', '%') AND
nachname LIKE CONCAT('%', '1Nachname', '%') AND 'Vorname1' != '' AND
'xxxx' != '')
)
)
;
kunde_id FK_firma_id aktuell vorname nachname geloescht
SELECT COUNT(*) FROM t1 WHERE
( 0 OR (vorname LIKE '%Vorname1%' AND nachname LIKE '%1Nachname%' AND 1))
AND FK_firma_id = 2;
COUNT(*)
0
CREATE TABLE `t1` ( `gid` int(11) default NULL, `uid` int(11) default NULL);
CREATE TABLE `t2` ( `ident` int(11) default NULL, `level` char(16) default NULL);
INSERT INTO `t2` VALUES (0,'READ');
CREATE TABLE `t3` ( `id` int(11) default NULL, `name` char(16) default NULL);
INSERT INTO `t3` VALUES (1,'fs');
select * from t3 left join t1 on t3.id = t1.uid, t2 where t2.ident in (0, t1.gid, t3.id, 0);
id name gid uid ident level
1 fs NULL NULL 0 READ
drop table t1,t2,t3;
drop table t1;
CREATE TABLE t1 (a int);
CREATE TABLE t2 (a int);
INSERT INTO t1 VALUES (1), (2), (3), (4), (5);
...
...
This diff is collapsed.
Click to expand it.
mysql-test/t/group_by.test
View file @
75ff7d80
...
...
@@ -550,9 +550,9 @@ DROP TABLE t1;
CREATE
TABLE
t1
(
n
int
);
INSERT
INTO
t1
VALUES
(
1
);
--
disable_ps_protocol
SELECT
n
+
1
AS
n
FROM
t1
GROUP
BY
n
;
--
enable_ps_protocol
DROP
TABLE
t1
;
# Test for bug #8614: GROUP BY 'const' with DISTINCT
...
...
This diff is collapsed.
Click to expand it.
mysql-test/t/select.test
View file @
75ff7d80
...
...
@@ -1954,7 +1954,6 @@ EXPLAIN SELECT * FROM t1 LEFT JOIN t2 FORCE INDEX (a) ON t1.a=t2.a;
DROP
TABLE
t1
,
t2
;
#
# Test case for bug 7098: substitution of a constant for a string field
#
...
...
@@ -1998,6 +1997,64 @@ select distinct all * from t1;
drop
table
t1
;
#
# Test for BUG#10095
#
CREATE
TABLE
t1
(
kunde_intern_id
int
(
10
)
unsigned
NOT
NULL
default
'0'
,
kunde_id
int
(
10
)
unsigned
NOT
NULL
default
'0'
,
FK_firma_id
int
(
10
)
unsigned
NOT
NULL
default
'0'
,
aktuell
enum
(
'Ja'
,
'Nein'
)
NOT
NULL
default
'Ja'
,
vorname
varchar
(
128
)
NOT
NULL
default
''
,
nachname
varchar
(
128
)
NOT
NULL
default
''
,
geloescht
enum
(
'Ja'
,
'Nein'
)
NOT
NULL
default
'Nein'
,
firma
varchar
(
128
)
NOT
NULL
default
''
);
INSERT
INTO
t1
VALUES
(
3964
,
3051
,
1
,
'Ja'
,
'Vorname1'
,
'1Nachname'
,
'Nein'
,
'Print Schau XXXX'
),
(
3965
,
3051111
,
1
,
'Ja'
,
'Vorname1111'
,
'1111Nachname'
,
'Nein'
,
'Print Schau XXXX'
);
SELECT
kunde_id
,
FK_firma_id
,
aktuell
,
vorname
,
nachname
,
geloescht
FROM
t1
WHERE
(
(
(
''
!=
''
AND
firma
LIKE
CONCAT
(
'%'
,
''
,
'%'
))
OR
(
vorname
LIKE
CONCAT
(
'%'
,
'Vorname1'
,
'%'
)
AND
nachname
LIKE
CONCAT
(
'%'
,
'1Nachname'
,
'%'
)
AND
'Vorname1'
!=
''
AND
'xxxx'
!=
''
)
)
AND
(
aktuell
=
'Ja'
AND
geloescht
=
'Nein'
AND
FK_firma_id
=
2
)
)
;
SELECT
kunde_id
,
FK_firma_id
,
aktuell
,
vorname
,
nachname
,
geloescht
FROM
t1
WHERE
(
(
aktuell
=
'Ja'
AND
geloescht
=
'Nein'
AND
FK_firma_id
=
2
)
AND
(
(
''
!=
''
AND
firma
LIKE
CONCAT
(
'%'
,
''
,
'%'
)
)
OR
(
vorname
LIKE
CONCAT
(
'%'
,
'Vorname1'
,
'%'
)
AND
nachname
LIKE
CONCAT
(
'%'
,
'1Nachname'
,
'%'
)
AND
'Vorname1'
!=
''
AND
'xxxx'
!=
''
)
)
)
;
SELECT
COUNT
(
*
)
FROM
t1
WHERE
(
0
OR
(
vorname
LIKE
'%Vorname1%'
AND
nachname
LIKE
'%1Nachname%'
AND
1
))
AND
FK_firma_id
=
2
;
drop
table
t1
;
#
# Test for Bug#8009, SELECT failed on bigint unsigned when using HEX
...
...
@@ -2022,6 +2079,50 @@ INSERT INTO `t3` VALUES (1,'fs');
select
*
from
t3
left
join
t1
on
t3
.
id
=
t1
.
uid
,
t2
where
t2
.
ident
in
(
0
,
t1
.
gid
,
t3
.
id
,
0
);
drop
table
t1
,
t2
,
t3
;
#
# Test case for bug 7098: substitution of a constant for a string field
#
CREATE
TABLE
t1
(
city
char
(
30
)
);
INSERT
INTO
t1
VALUES
(
'London'
);
INSERT
INTO
t1
VALUES
(
'Paris'
);
SELECT
*
FROM
t1
WHERE
city
=
'London'
;
SELECT
*
FROM
t1
WHERE
city
=
'london'
;
EXPLAIN
SELECT
*
FROM
t1
WHERE
city
=
'London'
AND
city
=
'london'
;
SELECT
*
FROM
t1
WHERE
city
=
'London'
AND
city
=
'london'
;
EXPLAIN
SELECT
*
FROM
t1
WHERE
city
LIKE
'%london%'
AND
city
=
'London'
;
SELECT
*
FROM
t1
WHERE
city
LIKE
'%london%'
AND
city
=
'London'
;
DROP
TABLE
t1
;
#
# Bug#7425 inconsistent sort order on unsigned columns result of substraction
#
create
table
t1
(
a
int
(
11
)
unsigned
,
b
int
(
11
)
unsigned
);
insert
into
t1
values
(
1
,
0
),
(
1
,
1
),
(
1
,
2
);
select
a
-
b
from
t1
order
by
1
;
select
a
-
b
,
(
a
-
b
<
0
)
from
t1
order
by
1
;
select
a
-
b
as
d
,
(
a
-
b
>=
0
),
b
from
t1
group
by
b
having
d
>=
0
;
select
cast
((
a
-
b
)
as
unsigned
)
from
t1
order
by
1
;
drop
table
t1
;
#
# Bug#8733 server accepts malformed query (multiply mentioned distinct)
#
create
table
t1
(
a
int
(
11
));
select
all
all
*
from
t1
;
select
distinct
distinct
*
from
t1
;
--
error
1221
select
all
distinct
*
from
t1
;
--
error
1221
select
distinct
all
*
from
t1
;
drop
table
t1
;
#
# Test for bug #6474
#
...
...
@@ -2168,108 +2269,6 @@ EXPLAIN SELECT * FROM t1 LEFT JOIN t2 FORCE INDEX (a) ON t1.a=t2.a;
DROP
TABLE
t1
,
t2
;
#
# Test case for bug 7098: substitution of a constant for a string field
#
CREATE
TABLE
t1
(
city
char
(
30
)
);
INSERT
INTO
t1
VALUES
(
'London'
);
INSERT
INTO
t1
VALUES
(
'Paris'
);
SELECT
*
FROM
t1
WHERE
city
=
'London'
;
SELECT
*
FROM
t1
WHERE
city
=
'london'
;
EXPLAIN
SELECT
*
FROM
t1
WHERE
city
=
'London'
AND
city
=
'london'
;
SELECT
*
FROM
t1
WHERE
city
=
'London'
AND
city
=
'london'
;
EXPLAIN
SELECT
*
FROM
t1
WHERE
city
LIKE
'%london%'
AND
city
=
'London'
;
SELECT
*
FROM
t1
WHERE
city
LIKE
'%london%'
AND
city
=
'London'
;
DROP
TABLE
t1
;
#
# Bug#7425 inconsistent sort order on unsigned columns result of substraction
#
create
table
t1
(
a
int
(
11
)
unsigned
,
b
int
(
11
)
unsigned
);
insert
into
t1
values
(
1
,
0
),
(
1
,
1
),
(
1
,
2
);
select
a
-
b
from
t1
order
by
1
;
select
a
-
b
,
(
a
-
b
<
0
)
from
t1
order
by
1
;
select
a
-
b
as
d
,
(
a
-
b
>=
0
),
b
from
t1
group
by
b
having
d
>=
0
;
select
cast
((
a
-
b
)
as
unsigned
)
from
t1
order
by
1
;
drop
table
t1
;
#
# Bug#8733 server accepts malformed query (multiply mentioned distinct)
#
create
table
t1
(
a
int
(
11
));
select
all
all
*
from
t1
;
select
distinct
distinct
*
from
t1
;
--
error
1221
select
all
distinct
*
from
t1
;
--
error
1221
select
distinct
all
*
from
t1
;
drop
table
t1
;
#
# Test for BUG#10095
#
CREATE
TABLE
t1
(
kunde_intern_id
int
(
10
)
unsigned
NOT
NULL
default
'0'
,
kunde_id
int
(
10
)
unsigned
NOT
NULL
default
'0'
,
FK_firma_id
int
(
10
)
unsigned
NOT
NULL
default
'0'
,
aktuell
enum
(
'Ja'
,
'Nein'
)
NOT
NULL
default
'Ja'
,
vorname
varchar
(
128
)
NOT
NULL
default
''
,
nachname
varchar
(
128
)
NOT
NULL
default
''
,
geloescht
enum
(
'Ja'
,
'Nein'
)
NOT
NULL
default
'Nein'
,
firma
varchar
(
128
)
NOT
NULL
default
''
);
INSERT
INTO
t1
VALUES
(
3964
,
3051
,
1
,
'Ja'
,
'Vorname1'
,
'1Nachname'
,
'Nein'
,
'Print Schau XXXX'
),
(
3965
,
3051111
,
1
,
'Ja'
,
'Vorname1111'
,
'1111Nachname'
,
'Nein'
,
'Print Schau XXXX'
);
SELECT
kunde_id
,
FK_firma_id
,
aktuell
,
vorname
,
nachname
,
geloescht
FROM
t1
WHERE
(
(
(
''
!=
''
AND
firma
LIKE
CONCAT
(
'%'
,
''
,
'%'
))
OR
(
vorname
LIKE
CONCAT
(
'%'
,
'Vorname1'
,
'%'
)
AND
nachname
LIKE
CONCAT
(
'%'
,
'1Nachname'
,
'%'
)
AND
'Vorname1'
!=
''
AND
'xxxx'
!=
''
)
)
AND
(
aktuell
=
'Ja'
AND
geloescht
=
'Nein'
AND
FK_firma_id
=
2
)
)
;
SELECT
kunde_id
,
FK_firma_id
,
aktuell
,
vorname
,
nachname
,
geloescht
FROM
t1
WHERE
(
(
aktuell
=
'Ja'
AND
geloescht
=
'Nein'
AND
FK_firma_id
=
2
)
AND
(
(
''
!=
''
AND
firma
LIKE
CONCAT
(
'%'
,
''
,
'%'
)
)
OR
(
vorname
LIKE
CONCAT
(
'%'
,
'Vorname1'
,
'%'
)
AND
nachname
LIKE
CONCAT
(
'%'
,
'1Nachname'
,
'%'
)
AND
'Vorname1'
!=
''
AND
'xxxx'
!=
''
)
)
)
;
SELECT
COUNT
(
*
)
FROM
t1
WHERE
(
0
OR
(
vorname
LIKE
'%Vorname1%'
AND
nachname
LIKE
'%1Nachname%'
AND
1
))
AND
FK_firma_id
=
2
;
drop
table
t1
;
#
# Test for bug #10084: STRAIGHT_JOIN with ON expression
#
...
...
This diff is collapsed.
Click to expand it.
sql/mysql_priv.h
View file @
75ff7d80
...
...
@@ -717,8 +717,7 @@ bool mysql_multi_update(THD *thd, TABLE_LIST *table_list,
COND
*
conds
,
ulong
options
,
enum
enum_duplicates
handle_duplicates
,
bool
ignore
,
SELECT_LEX_UNIT
*
unit
,
SELECT_LEX
*
select_lex
);
bool
mysql_prepare_insert
(
THD
*
thd
,
TABLE_LIST
*
table_list
,
TABLE_LIST
*
dup_table_list
,
TABLE
*
table
,
bool
mysql_prepare_insert
(
THD
*
thd
,
TABLE_LIST
*
table_list
,
TABLE
*
table
,
List
<
Item
>
&
fields
,
List_item
*
values
,
List
<
Item
>
&
update_fields
,
List
<
Item
>
&
update_values
,
enum_duplicates
duplic
,
...
...
This diff is collapsed.
Click to expand it.
sql/sql_base.cc
View file @
75ff7d80
...
...
@@ -2620,6 +2620,7 @@ find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables,
uint
length
=
(
uint
)
strlen
(
name
);
char
name_buff
[
NAME_LEN
+
1
];
bool
allow_rowid
;
if
(
item
->
cached_table
)
{
/*
...
...
@@ -2689,7 +2690,7 @@ find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables,
if
(
table_name
&&
table_name
[
0
])
{
/* Qualified field */
bool
found_table
=
0
;
for
(;
tables
;
tables
=
tables
->
next_local
)
,
for
(;
tables
;
tables
=
tables
->
next_local
)
{
/* TODO; Ensure that db and tables->db always points to something ! */
if
(
!
my_strcasecmp
(
table_alias_charset
,
tables
->
alias
,
table_name
)
&&
...
...
This diff is collapsed.
Click to expand it.
sql/sql_insert.cc
View file @
75ff7d80
...
...
@@ -327,7 +327,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
thd
->
used_tables
=
0
;
values
=
its
++
;
if
(
mysql_prepare_insert
(
thd
,
table_list
,
table
_list
,
table
,
fields
,
values
,
if
(
mysql_prepare_insert
(
thd
,
table_list
,
table
,
fields
,
values
,
update_fields
,
update_values
,
duplic
,
&
unused_conds
,
FALSE
))
goto
abort
;
...
...
@@ -734,10 +734,6 @@ static bool mysql_prepare_insert_check_table(THD *thd, TABLE_LIST *table_list,
mysql_prepare_insert()
thd Thread handler
table_list Global/local table list
dup_table_list Tables to be used in ON DUPLICATE KEY
It's either all global tables or only the table we
insert into, depending on if we are using GROUP BY
in the SELECT clause).
table Table to insert into (can be NULL if table should
be taken from table_list->table)
where Where clause (for insert ... select)
...
...
@@ -759,18 +755,17 @@ static bool mysql_prepare_insert_check_table(THD *thd, TABLE_LIST *table_list,
*/
bool
mysql_prepare_insert
(
THD
*
thd
,
TABLE_LIST
*
table_list
,
TABLE_LIST
*
dup_table_list
,
TABLE
*
table
,
List
<
Item
>
&
fields
,
List_item
*
values
,
TABLE
*
table
,
List
<
Item
>
&
fields
,
List_item
*
values
,
List
<
Item
>
&
update_fields
,
List
<
Item
>
&
update_values
,
enum_duplicates
duplic
,
COND
**
where
,
bool
select_insert
)
{
SELECT_LEX
=
&
thd
->
lex
->
select_lex
;
SELECT_LEX
*
select_lex
=
&
thd
->
lex
->
select_lex
;
TABLE_LIST
*
save_table_list
;
TABLE_LIST
*
save_next_local
;
bool
insert_into_view
=
(
table_list
->
view
!=
0
);
bool
save_resolve_in_select_list
;
bool
res
;
bool
res
=
0
;
DBUG_ENTER
(
"mysql_prepare_insert"
);
DBUG_PRINT
(
"enter"
,
(
"table_list 0x%lx, table 0x%lx, view %d"
,
(
ulong
)
table_list
,
(
ulong
)
table
,
...
...
@@ -815,15 +810,23 @@ bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list,
select_lex
->
context
.
resolve_in_table_list_only
(
table_list
);
if
((
values
&&
check_insert_fields
(
thd
,
table_list
,
fields
,
*
values
,
!
insert_into_view
))
||
(
values
&&
setup_fields
(
thd
,
0
,
*
values
,
0
,
0
,
0
))
||
setup_fields
(
thd
,
0
,
update_values
,
1
,
0
,
0
))
(
values
&&
setup_fields
(
thd
,
0
,
*
values
,
0
,
0
,
0
)))
res
=
TRUE
;
else
if
(
duplic
==
DUP_UPDATE
)
{
select_lex
->
context
.
resolve_in_table_list_only
(
dup_table_list
);
select_lex
->
no_wrap_view_item
=
TRUE
;
res
=
check_update_fields
(
thd
,
table_list
,
update_fields
);
select_lex
->
no_wrap_view_item
=
FALSE
;
if
(
select_lex
->
group_list
.
elements
==
0
)
{
/*
When we are not using GROUP BY we can refer to other tables in the
ON DUPLICATE KEY part
*/
table_list
->
next_local
=
save_next_local
;
}
if
(
!
res
)
res
=
setup_fields
(
thd
,
0
,
update_values
,
1
,
0
,
0
);
}
table_list
->
next_local
=
save_next_local
;
select_lex
->
context
.
table_list
=
save_table_list
;
...
...
@@ -2013,8 +2016,8 @@ bool delayed_insert::handle_inserts(void)
bool
mysql_insert_select_prepare
(
THD
*
thd
)
{
LEX
*
lex
=
thd
->
lex
;
SELECT_LEX
*
select_lex
=
&
lex
->
select_lex
;
TABLE_LIST
*
first_select_leaf_table
;
TABLE_LIST
dup_tables
;
DBUG_ENTER
(
"mysql_insert_select_prepare"
);
/*
...
...
@@ -2022,38 +2025,28 @@ bool mysql_insert_select_prepare(THD *thd)
clause if table is VIEW
*/
dup_tables
=
*
lex
->
query_tables
;
if
(
lex
->
select_lex
->
group_list
.
elements
!=
0
)
{
/*
When we are using GROUP BY we can't refere to other tables in the
ON DUPLICATE KEY part
*/
dup_tables
.
local_next
=
0
;
}
if
(
mysql_prepare_insert
(
thd
,
lex
->
query_tables
,
&
dup_tables
if
(
mysql_prepare_insert
(
thd
,
lex
->
query_tables
,
lex
->
query_tables
->
table
,
lex
->
field_list
,
0
,
lex
->
update_list
,
lex
->
value_list
,
lex
->
duplicates
,
&
lex
->
select_lex
.
where
,
TRUE
))
&
select_lex
->
where
,
TRUE
))
DBUG_RETURN
(
TRUE
);
/*
exclude first table from leaf tables list, because it belong to
INSERT
*/
DBUG_ASSERT
(
lex
->
select_lex
.
leaf_tables
!=
0
);
lex
->
leaf_tables_insert
=
lex
->
select_lex
.
leaf_tables
;
DBUG_ASSERT
(
select_lex
->
leaf_tables
!=
0
);
lex
->
leaf_tables_insert
=
select_lex
->
leaf_tables
;
/* skip all leaf tables belonged to view where we are insert */
for
(
first_select_leaf_table
=
lex
->
select_lex
.
leaf_tables
->
next_leaf
;
for
(
first_select_leaf_table
=
select_lex
->
leaf_tables
->
next_leaf
;
first_select_leaf_table
&&
first_select_leaf_table
->
belong_to_view
&&
first_select_leaf_table
->
belong_to_view
==
lex
->
leaf_tables_insert
->
belong_to_view
;
first_select_leaf_table
=
first_select_leaf_table
->
next_leaf
)
{}
lex
->
select_lex
.
leaf_tables
=
first_select_leaf_table
;
select_lex
->
leaf_tables
=
first_select_leaf_table
;
DBUG_RETURN
(
FALSE
);
}
...
...
This diff is collapsed.
Click to expand it.
sql/sql_prepare.cc
View file @
75ff7d80
...
...
@@ -939,9 +939,9 @@ static bool mysql_test_insert(Prepared_statement *stmt,
table_list
->
table
->
insert_values
=
(
byte
*
)
1
;
}
if
(
mysql_prepare_insert
(
thd
,
table_list
,
table_list
,
table_list
->
table
,
fields
,
values
,
update_fields
,
update_values
,
duplic
,
&
unused_conds
,
FALSE
))
if
(
mysql_prepare_insert
(
thd
,
table_list
,
table_list
->
table
,
fields
,
values
,
update_fields
,
update_values
,
duplic
,
&
unused_conds
,
FALSE
))
goto
error
;
value_count
=
values
->
elements
;
...
...
This diff is collapsed.
Click to expand it.
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