Merge bk-internal.mysql.com:/home/bk/mysql-5.0

into  mysql.com:/home/my/mysql-5.0
This commit is contained in:
monty@mysql.com 2005-08-15 18:35:48 +03:00
commit 1a6f16edd9
108 changed files with 4317 additions and 2182 deletions

View File

@ -1121,3 +1121,5 @@ vio/test-ssl
vio/test-sslclient
vio/test-sslserver
vio/viotest-ssl
support-files/MacOSX/postflight
support-files/MacOSX/preflight

View File

@ -624,7 +624,7 @@ static struct my_option my_long_options[] =
NO_ARG, 0, 0, 0, 0, 0, 0},
#endif
{"port", 'P', "Port number to use for connection.", (gptr*) &opt_mysql_port,
(gptr*) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, MYSQL_PORT, 0, 0, 0, 0,
(gptr*) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
0},
{"prompt", OPT_PROMPT, "Set the mysql prompt to this value.",
(gptr*) &current_prompt, (gptr*) &current_prompt, 0, GET_STR_ALLOC,

View File

@ -575,8 +575,13 @@ static void print_result()
if (status)
{
/*
if there was an error with the table, we have --auto-repair set,
and this isn't a repair op, then add the table to the tables4repair
list
*/
if (found_error && opt_auto_repair && what_to_do != DO_REPAIR &&
(!opt_fast || strcmp(row[3],"OK")))
strcmp(row[3],"OK"))
insert_dynamic(&tables4repair, prev);
found_error=0;
if (opt_silent)
@ -595,8 +600,8 @@ static void print_result()
strmov(prev, row[0]);
putchar('\n');
}
if (found_error && opt_auto_repair && what_to_do != DO_REPAIR &&
!opt_fast)
/* add the last table to be repaired to the list */
if (found_error && opt_auto_repair && what_to_do != DO_REPAIR)
insert_dynamic(&tables4repair, prev);
mysql_free_result(res);
}

View File

@ -5,12 +5,9 @@ extra/yassl/src/Makefile)
AC_DEFUN([MYSQL_CHECK_YASSL], [
AC_MSG_CHECKING(for yaSSL)
AC_ARG_WITH([yassl],
[ --with-yassl Include the yaSSL support],
[yassl=yes],
[yassl=no])
AC_ARG_WITH([yassl], [ --with-yassl Include the yaSSL support],,)
if test "$yassl" = "yes"
if test "$with_yassl" = "yes"
then
if test "$openssl" != "no"
then
@ -30,5 +27,5 @@ AC_DEFUN([MYSQL_CHECK_YASSL], [
AC_SUBST(openssl_libs)
AC_SUBST(openssl_includes)
AC_SUBST(yassl_dir)
AM_CONDITIONAL([HAVE_YASSL], [ test "$yassl" = "yes" ])
AM_CONDITIONAL([HAVE_YASSL], [ test "with_yassl" = "yes" ])
])

View File

@ -1,7 +1,7 @@
dnl -*- ksh -*-
dnl Process this file with autoconf to produce a configure script.
AC_PREREQ(2.57)dnl Minimum Autoconf version required.
AC_PREREQ(2.52)dnl Minimum Autoconf version required.
AC_INIT(sql/mysqld.cc)
AC_CANONICAL_SYSTEM
@ -130,6 +130,7 @@ AC_PROG_MAKE_SET
# Hack for OS X/Darwin and Metrowerks CodeWarrior
AC_ARG_WITH(darwin-mwcc,
[ --with-darwin-mwcc Use Metrowerks CodeWarrior wrappers on OS X/Darwin],[
if [ "with_darwin_mwcc" = yes ] ; then
builddir=`pwd`
ccwrapper="$builddir/support-files/MacOSX/mwcc-wrapper"
arwrapper="$builddir/support-files/MacOSX/mwar-wrapper"
@ -141,7 +142,7 @@ AC_ARG_WITH(darwin-mwcc,
export CC CXX LD AR RANLIB
AC_SUBST(AR)
AC_SUBST(RANLIB)
with_darwin_mwcc=yes
fi
])
AM_CONDITIONAL(DARWIN_MWCC, test x$with_darwin_mwcc = xyes)

View File

@ -210,7 +210,7 @@ btr_pcur_restore_position(
&& cursor->pos_state != BTR_PCUR_IS_POSITIONED)) {
ut_print_buf(stderr, (const byte*)cursor, sizeof(btr_pcur_t));
if (cursor->trx_if_known) {
trx_print(stderr, cursor->trx_if_known);
trx_print(stderr, cursor->trx_if_known, 0);
}
ut_error;

View File

@ -329,17 +329,20 @@ trx_commit_step(
/*============*/
/* out: query thread to run next, or NULL */
que_thr_t* thr); /* in: query thread */
/**************************************************************************
Prints info about a transaction to the standard output. The caller must
own the kernel mutex and must have called
innobase_mysql_prepare_print_arbitrary_thd(), unless he knows that MySQL or
InnoDB cannot meanwhile change the info printed here. */
Prints info about a transaction to the given file. The caller must own the
kernel mutex and must have called
innobase_mysql_prepare_print_arbitrary_thd(), unless he knows that MySQL
or InnoDB cannot meanwhile change the info printed here. */
void
trx_print(
/*======*/
FILE* f, /* in: output stream */
trx_t* trx); /* in: transaction */
FILE* f, /* in: output stream */
trx_t* trx, /* in: transaction */
uint max_query_len); /* in: max query length to print, or 0 to
use the default max length */
#ifndef UNIV_HOTBACKUP
/**************************************************************************

View File

@ -3297,7 +3297,7 @@ lock_deadlock_recursive(
fputs("\n*** (1) TRANSACTION:\n", ef);
trx_print(ef, wait_lock->trx);
trx_print(ef, wait_lock->trx, 3000);
fputs(
"*** (1) WAITING FOR THIS LOCK TO BE GRANTED:\n", ef);
@ -3310,7 +3310,7 @@ lock_deadlock_recursive(
fputs("*** (2) TRANSACTION:\n", ef);
trx_print(ef, lock->trx);
trx_print(ef, lock->trx, 3000);
fputs("*** (2) HOLDS THE LOCK(S):\n", ef);
@ -4207,7 +4207,7 @@ lock_print_info_all_transactions(
while (trx) {
if (trx->conc_state == TRX_NOT_STARTED) {
fputs("---", file);
trx_print(file, trx);
trx_print(file, trx, 600);
}
trx = UT_LIST_GET_NEXT(mysql_trx_list, trx);
@ -4239,7 +4239,7 @@ loop:
if (nth_lock == 0) {
fputs("---", file);
trx_print(file, trx);
trx_print(file, trx, 600);
if (trx->read_view) {
fprintf(file,

View File

@ -602,7 +602,7 @@ row_ins_foreign_report_err(
rewind(ef);
ut_print_timestamp(ef);
fputs(" Transaction:\n", ef);
trx_print(ef, trx);
trx_print(ef, trx, 600);
fputs("Foreign key constraint fails for table ", ef);
ut_print_name(ef, trx, foreign->foreign_table_name);
@ -653,7 +653,7 @@ row_ins_foreign_report_add_err(
rewind(ef);
ut_print_timestamp(ef);
fputs(" Transaction:\n", ef);
trx_print(ef, trx);
trx_print(ef, trx, 600);
fputs("Foreign key constraint fails for table ", ef);
ut_print_name(ef, trx, foreign->foreign_table_name);
fputs(":\n", ef);
@ -1228,7 +1228,7 @@ run_again:
rewind(ef);
ut_print_timestamp(ef);
fputs(" Transaction:\n", ef);
trx_print(ef, trx);
trx_print(ef, trx, 600);
fputs("Foreign key constraint fails for table ", ef);
ut_print_name(ef, trx, foreign->foreign_table_name);
fputs(":\n", ef);

View File

@ -2685,7 +2685,7 @@ row_sel_get_clust_rec_for_mysql(
"InnoDB: clust index record ", stderr);
rec_print(stderr, clust_rec, clust_index);
putc('\n', stderr);
trx_print(stderr, trx);
trx_print(stderr, trx, 600);
fputs("\n"
"InnoDB: Submit a detailed bug report to http://bugs.mysql.com\n", stderr);
@ -3128,7 +3128,7 @@ row_search_for_mysql(
"InnoDB: Error: MySQL is trying to perform a SELECT\n"
"InnoDB: but it has not locked any tables in ::external_lock()!\n",
stderr);
trx_print(stderr, trx);
trx_print(stderr, trx, 600);
fputc('\n', stderr);
}
@ -3455,7 +3455,7 @@ shortcut_fails_too_big_rec:
fputs(
"InnoDB: Error: MySQL is trying to perform a consistent read\n"
"InnoDB: but the read view is not assigned!\n", stderr);
trx_print(stderr, trx);
trx_print(stderr, trx, 600);
fputc('\n', stderr);
ut_a(0);
}

View File

@ -431,7 +431,7 @@ row_undo_mod_del_unmark_sec_and_undo_update(
"InnoDB: record ", stderr);
rec_print(stderr, btr_pcur_get_rec(&pcur), index);
putc('\n', stderr);
trx_print(stderr, trx);
trx_print(stderr, trx, 0);
fputs("\n"
"InnoDB: Submit a detailed bug report to http://bugs.mysql.com\n", stderr);
} else {

View File

@ -1279,7 +1279,7 @@ row_upd_sec_index_entry(
rec_print(stderr, rec, index);
putc('\n', stderr);
trx_print(stderr, trx);
trx_print(stderr, trx, 0);
fputs("\n"
"InnoDB: Submit a detailed bug report to http://bugs.mysql.com\n", stderr);

View File

@ -1000,7 +1000,7 @@ retry:
fputs(
" InnoDB: Error: trying to declare trx to enter InnoDB, but\n"
"InnoDB: it already is declared.\n", stderr);
trx_print(stderr, trx);
trx_print(stderr, trx, 0);
putc('\n', stderr);
os_fast_mutex_unlock(&srv_conc_mutex);

View File

@ -30,8 +30,9 @@ Created 3/26/1996 Heikki Tuuri
copy MUST be equal to the one in mysql/sql/ha_innodb.cc ! */
void innobase_mysql_print_thd(
FILE* f,
void* thd);
FILE* f,
void* thd,
uint max_query_len);
/* Dummy session used currently in MySQL interface */
sess_t* trx_dummy_sess = NULL;
@ -262,7 +263,7 @@ trx_free(
fputs(
" InnoDB: Error: Freeing a trx which is declared to be processing\n"
"InnoDB: inside InnoDB.\n", stderr);
trx_print(stderr, trx);
trx_print(stderr, trx, 600);
putc('\n', stderr);
}
@ -277,7 +278,7 @@ trx_free(
(ulong)trx->n_mysql_tables_in_use,
(ulong)trx->mysql_n_tables_locked);
trx_print(stderr, trx);
trx_print(stderr, trx, 600);
ut_print_buf(stderr, (byte*)trx, sizeof(trx_t));
}
@ -1651,16 +1652,18 @@ trx_mark_sql_stat_end(
}
/**************************************************************************
Prints info about a transaction to the standard output. The caller must
own the kernel mutex and must have called
innobase_mysql_prepare_print_arbitrary_thd(), unless he knows that MySQL or
InnoDB cannot meanwhile change the info printed here. */
Prints info about a transaction to the given file. The caller must own the
kernel mutex and must have called
innobase_mysql_prepare_print_arbitrary_thd(), unless he knows that MySQL
or InnoDB cannot meanwhile change the info printed here. */
void
trx_print(
/*======*/
FILE* f, /* in: output stream */
trx_t* trx) /* in: transaction */
FILE* f, /* in: output stream */
trx_t* trx, /* in: transaction */
uint max_query_len) /* in: max query length to print, or 0 to
use the default max length */
{
ibool newline;
@ -1755,7 +1758,7 @@ trx_print(
}
if (trx->mysql_thd != NULL) {
innobase_mysql_print_thd(f, trx->mysql_thd);
innobase_mysql_print_thd(f, trx->mysql_thd, max_query_len);
}
}

View File

@ -349,14 +349,14 @@ drop table if exists t2 ;
--enable_warnings
create table t2 as select * from t1 ;
set @query1= 'SELECT * FROM t2 join t1 on (t1.a=t2.a) order by t2.a ' ;
set @query2= 'SELECT * FROM t2 natural join t1 order by t2.a ' ;
set @query3= 'SELECT * FROM t2 join t1 using(a) order by t2.a ' ;
set @query2= 'SELECT * FROM t2 natural join t1 order by a ' ;
set @query3= 'SELECT * FROM t2 join t1 using(a) order by a ' ;
set @query4= 'SELECT * FROM t2 left join t1 on(t1.a=t2.a) order by t2.a ' ;
set @query5= 'SELECT * FROM t2 natural left join t1 order by t2.a ' ;
set @query6= 'SELECT * FROM t2 left join t1 using(a) order by t2.a ' ;
set @query5= 'SELECT * FROM t2 natural left join t1 order by a ' ;
set @query6= 'SELECT * FROM t2 left join t1 using(a) order by a ' ;
set @query7= 'SELECT * FROM t2 right join t1 on(t1.a=t2.a) order by t2.a ' ;
set @query8= 'SELECT * FROM t2 natural right join t1 order by t2.a ' ;
set @query9= 'SELECT * FROM t2 right join t1 using(a) order by t2.a ' ;
set @query8= 'SELECT * FROM t2 natural right join t1 order by a ' ;
set @query9= 'SELECT * FROM t2 right join t1 using(a) order by a ' ;
let $1= 9 ;
while ($1)
{

View File

@ -229,6 +229,7 @@ drop table t1;
#
# Bug #9489: problem with hash indexes
# Bug #10802: Index is not used if table using BDB engine on HP-UX
#
create table t1(a int, b varchar(12), key ba(b, a));

View File

@ -732,7 +732,7 @@ drop table t1;
set @a:=now();
CREATE TABLE t1 (a int not null, b timestamp not null, primary key (a)) engine=bdb;
insert into t1 (a) values(1),(2),(3);
select t1.a from t1 natural join t1 as t2 where t1.b >= @a order by t1.a;
select a from t1 natural join t1 as t2 where b >= @a order by a;
a
1
2
@ -906,7 +906,7 @@ create temporary table tmp1
select branch_id, target_id, platform_id, product_id
from t1, t2, t3, t4 ;
create temporary table tmp2
select tmp1.branch_id, tmp1.target_id, tmp1.platform_id, tmp1.product_id
select branch_id, target_id, platform_id, product_id
from tmp1 left join t8
using (branch_id,target_id,platform_id,product_id)
where t8.archive_id is null ;

View File

@ -111,7 +111,7 @@ a b
1 a
2 b
3 c
explain select * from (select * from t1,t2 where t1.a=t2.a) t1;
explain select * from (select t1.*, t2.a as t2a from t1,t2 where t1.a=t2.a) t1;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> system NULL NULL NULL NULL 1
2 DERIVED t2 system NULL NULL NULL NULL 1
@ -149,8 +149,8 @@ SELECT * FROM (SELECT (SELECT * FROM (SELECT 1 as a) as a )) as b;
(SELECT * FROM (SELECT 1 as a) as a )
1
select * from (select 1 as a) b left join (select 2 as a) c using(a);
a a
1 NULL
a
1
SELECT * FROM (SELECT 1 UNION SELECT a) b;
ERROR 42S22: Unknown column 'a' in 'field list'
SELECT 1 as a FROM (SELECT a UNION SELECT 1) b;
@ -363,3 +363,8 @@ a
3
3
drop table t1, t2, t3;
create table t1 (a int);
create table t2 (a int);
select * from (select * from t1,t2) foo;
ERROR 42S21: Duplicate column name 'a'
drop table t1,t2;

View File

@ -9,9 +9,9 @@ create table t1 (a int);
select count(test.t1.b) from t1;
ERROR 42S22: Unknown column 'test.t1.b' in 'field list'
select count(not_existing_database.t1) from t1;
ERROR 42S02: Unknown table 'not_existing_database' in field list
ERROR 42S22: Unknown column 'not_existing_database.t1' in 'field list'
select count(not_existing_database.t1.a) from t1;
ERROR 42S02: Unknown table 'not_existing_database.t1' in field list
ERROR 42S22: Unknown column 'not_existing_database.t1.a' in 'field list'
select count(not_existing_database.t1.a) from not_existing_database.t1;
Got one of the listed errors
select 1 from t1 order by 2;

View File

@ -221,14 +221,14 @@ select t1.id FROM t2 as ttxt,t1,t1 as ticket2
WHERE ticket2.id = ttxt.ticket AND t1.id = ticket2.ticket and
match(ttxt.inhalt) against ('foobar');
id
select t1.id FROM t2 as ttxt,t1 INNER JOIN t1 as ticket2 ON
ticket2.id = ttxt.ticket
WHERE t1.id = ticket2.ticket and match(ttxt.inhalt) against ('foobar');
select ticket2.id FROM t2 as ttxt,t2 INNER JOIN t1 as ticket2 ON
ticket2.id = t2.ticket
WHERE ticket2.id = ticket2.ticket and match(ttxt.inhalt) against ('foobar');
id
INSERT INTO t1 VALUES (3,3);
select t1.id FROM t2 as ttxt,t1
INNER JOIN t1 as ticket2 ON ticket2.id = ttxt.ticket
WHERE t1.id = ticket2.ticket and
select ticket2.id FROM t2 as ttxt,t2
INNER JOIN t1 as ticket2 ON ticket2.id = t2.ticket
WHERE ticket2.id = ticket2.ticket and
match(ttxt.inhalt) against ('foobar');
id
3
@ -337,8 +337,8 @@ insert into t2 values (1, 1, 'xxfoo');
insert into t2 values (2, 1, 'xxbar');
insert into t2 values (3, 1, 'xxbuz');
select * from t1 join t2 using(`t1_id`) where match (t1.name, t2.name) against('xxfoo' in boolean mode);
t1_id name t2_id t1_id name
1 data1 1 1 xxfoo
t1_id name t2_id name
1 data1 1 xxfoo
select * from t2 where match name against ('*a*b*c*d*e*f*' in boolean mode);
t2_id t1_id name
drop table t1,t2;

View File

@ -126,7 +126,7 @@ group by
a.text, b.id, b.betreff
order by
match(b.betreff) against ('+abc' in boolean mode) desc;
ERROR 42S02: Unknown table 'b' in order clause
ERROR 42S22: Unknown column 'b.betreff' in 'order clause'
select a.text, b.id, b.betreff
from
t2 a inner join t3 b on a.id = b.forum inner join
@ -142,7 +142,7 @@ where
match(c.beitrag) against ('+abc' in boolean mode)
order by
match(b.betreff) against ('+abc' in boolean mode) desc;
ERROR 42S02: Unknown table 'b' in order clause
ERROR 42S22: Unknown column 'b.betreff' in 'order clause'
select a.text, b.id, b.betreff
from
t2 a inner join t3 b on a.id = b.forum inner join

View File

@ -68,6 +68,21 @@ drop table t1;
select TRUE,FALSE,NULL;
TRUE FALSE NULL
1 0 NULL
create table t1 (c1 char(5)) character set=latin1;
insert into t1 values('row 1');
insert into t1 values('row 2');
insert into t1 values('row 3');
select concat(user(), '--', c1) from t1;
concat(user(), '--', c1)
root@localhost--row 1
root@localhost--row 2
root@localhost--row 3
select concat(database(), '--', c1) from t1;
concat(database(), '--', c1)
test--row 1
test--row 2
test--row 3
drop table t1;
create table t1 (a char(10)) character set latin1;
select * from t1 where a=version();
a

View File

@ -687,7 +687,7 @@ timestampdiff(SQL_TSI_FRAC_SECOND, '2001-02-01 12:59:59.120000', '2001-05-01 12:
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 select timestamp_diff(WEEK,_latin1'2001-02-01',_latin1'2001-05-01') AS `a1`,timestamp_diff(SECOND_FRAC,_latin1'2001-02-01 12:59:59.120000',_latin1'2001-05-01 12:58:58.119999') AS `a2`
Note 1003 select timestampdiff(WEEK,_latin1'2001-02-01',_latin1'2001-05-01') AS `a1`,timestampdiff(SECOND_FRAC,_latin1'2001-02-01 12:59:59.120000',_latin1'2001-05-01 12:58:58.119999') AS `a2`
select last_day('2005-00-00');
last_day('2005-00-00')
NULL

View File

@ -750,7 +750,7 @@ drop table t1;
set @a:=now();
CREATE TABLE t1 (a int not null, b timestamp not null, primary key (a)) engine=innodb;
insert into t1 (a) values(1),(2),(3);
select t1.a from t1 natural join t1 as t2 where t1.b >= @a order by t1.a;
select a from t1 natural join t1 as t2 where b >= @a order by a;
a
1
2
@ -1377,7 +1377,7 @@ ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fail
update t1,t2,t3 set t3.id=5, t2.id=6, t1.id=7 where t1.id =1 and t2.id = t1.id and t3.id = t2.id;
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails
update t3 set t3.id=7 where t1.id =1 and t2.id = t1.id and t3.id = t2.id;
ERROR 42S02: Unknown table 't1' in where clause
ERROR 42S22: Unknown column 't1.id' in 'where clause'
drop table t3,t2,t1;
create table t1(
id int primary key,

View File

@ -664,7 +664,7 @@ insert into t1 select t2.a from t2 group by t2.a on duplicate key update a= a +
insert into t1 select t2.a from t2 on duplicate key update a= a + t2.b;
ERROR 23000: Column 'a' in field list is ambiguous
insert into t1 select t2.a from t2 on duplicate key update t2.a= a + t2.b;
ERROR 42S02: Unknown table 't2' in field list
ERROR 42S22: Unknown column 't2.a' in 'field list'
insert into t1 select t2.a from t2 group by t2.a on duplicate key update a= t1.a + t2.b;
ERROR 42S02: Unknown table 't2' in field list
ERROR 42S22: Unknown column 't2.b' in 'field list'
drop table t1,t2,t3;

View File

@ -10,21 +10,21 @@ SELECT * FROM t1 INNER JOIN t2;
S1 S1
1 2
SELECT * from t1 JOIN t2 USING (S1);
S1 S1
S1
SELECT * FROM t1 INNER JOIN t2 USING (S1);
S1 S1
S1
SELECT * from t1 CROSS JOIN t2;
S1 S1
1 2
SELECT * from t1 LEFT JOIN t2 USING(S1);
S1 S1
1 NULL
S1
1
SELECT * from t1 LEFT JOIN t2 ON(t2.S1=2);
S1 S1
1 2
SELECT * from t1 RIGHT JOIN t2 USING(S1);
S1 S1
NULL 2
S1
2
SELECT * from t1 RIGHT JOIN t2 ON(t1.S1=1);
S1 S1
1 2
@ -121,11 +121,7 @@ id catid stateid countyid
drop table t1, t2;
create table t1 (a int primary key);
insert into t1 values(1),(2);
select t1.a from t1 as t1 left join t1 as t2 using (a) left join t1 as t3 using (a) left join t1 as t4 using (a) left join t1 as t5 using (a) left join t1 as t6 using (a) left join t1 as t7 using (a) left join t1 as t8 using (a) left join t1 as t9 using (a) left join t1 as t10 using (a) left join t1 as t11 using (a) left join t1 as t12 using (a) left join t1 as t13 using (a) left join t1 as t14 using (a) left join t1 as t15 using (a) left join t1 as t16 using (a) left join t1 as t17 using (a) left join t1 as t18 using (a) left join t1 as t19 using (a) left join t1 as t20 using (a) left join t1 as t21 using (a) left join t1 as t22 using (a) left join t1 as t23 using (a) left join t1 as t24 using (a) left join t1 as t25 using (a) left join t1 as t26 using (a) left join t1 as t27 using (a) left join t1 as t28 using (a) left join t1 as t29 using (a) left join t1 as t30 using (a) left join t1 as t31 using (a);
a
1
2
select t1.a from t1 as t1 left join t1 as t2 using (a) left join t1 as t3 using (a) left join t1 as t4 using (a) left join t1 as t5 using (a) left join t1 as t6 using (a) left join t1 as t7 using (a) left join t1 as t8 using (a) left join t1 as t9 using (a) left join t1 as t10 using (a) left join t1 as t11 using (a) left join t1 as t12 using (a) left join t1 as t13 using (a) left join t1 as t14 using (a) left join t1 as t15 using (a) left join t1 as t16 using (a) left join t1 as t17 using (a) left join t1 as t18 using (a) left join t1 as t19 using (a) left join t1 as t20 using (a) left join t1 as t21 using (a) left join t1 as t22 using (a) left join t1 as t23 using (a) left join t1 as t24 using (a) left join t1 as t25 using (a) left join t1 as t26 using (a) left join t1 as t27 using (a) left join t1 as t28 using (a) left join t1 as t29 using (a) left join t1 as t30 using (a) left join t1 as t31 using (a) left join t1 as t32 using (a) left join t1 as t33 using (a) left join t1 as t34 using (a) left join t1 as t35 using (a) left join t1 as t36 using (a) left join t1 as t37 using (a) left join t1 as t38 using (a) left join t1 as t39 using (a) left join t1 as t40 using (a) left join t1 as t41 using (a) left join t1 as t42 using (a) left join t1 as t43 using (a) left join t1 as t44 using (a) left join t1 as t45 using (a) left join t1 as t46 using (a) left join t1 as t47 using (a) left join t1 as t48 using (a) left join t1 as t49 using (a) left join t1 as t50 using (a) left join t1 as t51 using (a) left join t1 as t52 using (a) left join t1 as t53 using (a) left join t1 as t54 using (a) left join t1 as t55 using (a) left join t1 as t56 using (a) left join t1 as t57 using (a) left join t1 as t58 using (a) left join t1 as t59 using (a) left join t1 as t60 using (a) left join t1 as t61 using (a) left join t1 as t62 using (a) left join t1 as t63 using (a) left join t1 as t64 using (a) left join t1 as t65 using (a);
select a from t1 as t1 left join t1 as t2 using (a) left join t1 as t3 using (a) left join t1 as t4 using (a) left join t1 as t5 using (a) left join t1 as t6 using (a) left join t1 as t7 using (a) left join t1 as t8 using (a) left join t1 as t9 using (a) left join t1 as t10 using (a) left join t1 as t11 using (a) left join t1 as t12 using (a) left join t1 as t13 using (a) left join t1 as t14 using (a) left join t1 as t15 using (a) left join t1 as t16 using (a) left join t1 as t17 using (a) left join t1 as t18 using (a) left join t1 as t19 using (a) left join t1 as t20 using (a) left join t1 as t21 using (a) left join t1 as t22 using (a) left join t1 as t23 using (a) left join t1 as t24 using (a) left join t1 as t25 using (a) left join t1 as t26 using (a) left join t1 as t27 using (a) left join t1 as t28 using (a) left join t1 as t29 using (a) left join t1 as t30 using (a) left join t1 as t31 using (a) left join t1 as t32 using (a) left join t1 as t33 using (a) left join t1 as t34 using (a) left join t1 as t35 using (a) left join t1 as t36 using (a) left join t1 as t37 using (a) left join t1 as t38 using (a) left join t1 as t39 using (a) left join t1 as t40 using (a) left join t1 as t41 using (a) left join t1 as t42 using (a) left join t1 as t43 using (a) left join t1 as t44 using (a) left join t1 as t45 using (a) left join t1 as t46 using (a) left join t1 as t47 using (a) left join t1 as t48 using (a) left join t1 as t49 using (a) left join t1 as t50 using (a) left join t1 as t51 using (a) left join t1 as t52 using (a) left join t1 as t53 using (a) left join t1 as t54 using (a) left join t1 as t55 using (a) left join t1 as t56 using (a) left join t1 as t57 using (a) left join t1 as t58 using (a) left join t1 as t59 using (a) left join t1 as t60 using (a) left join t1 as t61 using (a) left join t1 as t62 using (a) left join t1 as t63 using (a) left join t1 as t64 using (a) left join t1 as t65 using (a);
ERROR HY000: Too many tables; MySQL can only use XX tables in a join
drop table t1;
CREATE TABLE t1 (
@ -145,10 +141,9 @@ DROP TABLE t1, t2;
CREATE TABLE t1 (d DATE NOT NULL);
CREATE TABLE t2 (d DATE NOT NULL);
INSERT INTO t1 (d) VALUES ('2001-08-01'),('0000-00-00');
SELECT * FROM t1 LEFT JOIN t2 USING (d) WHERE t2.d IS NULL;
d d
2001-08-01 NULL
0000-00-00 NULL
SELECT * FROM t1 LEFT JOIN t2 USING (d) WHERE d IS NULL;
d
0000-00-00
SELECT * from t1 WHERE t1.d IS NULL;
d
0000-00-00
@ -265,10 +260,10 @@ PRIMARY KEY (siteid,rate_code),
FULLTEXT KEY rate_code (rate_code)
) ENGINE=MyISAM;
INSERT INTO t2 VALUES ('rivercats','cust',20);
SELECT emp.rate_code, lr.base_rate FROM t1 AS emp LEFT JOIN t2 AS lr USING (siteid, rate_code) WHERE emp.emp_id = 'psmith' AND lr.siteid = 'rivercats';
SELECT rate_code, lr.base_rate FROM t1 AS emp LEFT JOIN t2 AS lr USING (siteid, rate_code) WHERE emp.emp_id = 'psmith' AND siteid = 'rivercats';
rate_code base_rate
cust 20
SELECT emp.rate_code, lr.base_rate FROM t1 AS emp LEFT JOIN t2 AS lr USING (siteid, rate_code) WHERE lr.siteid = 'rivercats' AND emp.emp_id = 'psmith';
SELECT rate_code, lr.base_rate FROM t1 AS emp LEFT JOIN t2 AS lr USING (siteid, rate_code) WHERE siteid = 'rivercats' AND emp.emp_id = 'psmith';
rate_code base_rate
cust 20
drop table t1,t2;
@ -296,79 +291,79 @@ insert into t1 values(1),(2);
insert into t2 values(2),(3);
insert into t3 values (2),(4);
select * from t1 natural left join t2;
i i
1 NULL
2 2
i
1
2
select * from t1 left join t2 on (t1.i=t2.i);
i i
1 NULL
2 2
select * from t1 natural left join t2 natural left join t3;
i i i
1 NULL NULL
2 2 2
i
1
2
select * from t1 left join t2 on (t1.i=t2.i) left join t3 on (t2.i=t3.i);
i i i
1 NULL NULL
2 2 2
select * from t3 natural right join t2;
i i
2 2
NULL 3
i
2
3
select * from t3 right join t2 on (t3.i=t2.i);
i i
2 2
NULL 3
select * from t3 natural right join t2 natural right join t1;
i i i
NULL NULL 1
2 2 2
i
1
2
select * from t3 right join t2 on (t3.i=t2.i) right join t1 on (t2.i=t1.i);
i i i
NULL NULL 1
2 2 2
select * from t1,t2 natural left join t3 order by t1.i,t2.i,t3.i;
i i i
1 2 2
1 3 NULL
2 2 2
2 3 NULL
select * from t1,t2 natural left join t3 order by 1,2;
i i
1 2
1 3
2 2
2 3
select * from t1,t2 left join t3 on (t2.i=t3.i) order by t1.i,t2.i,t3.i;
i i i
1 2 2
1 3 NULL
2 2 2
2 3 NULL
select t1.i,t2.i,t3.i from t2 natural left join t3,t1 order by t1.i,t2.i,t3.i;
i i i
1 2 2
1 3 NULL
2 2 2
2 3 NULL
select * from t2 natural left join t3,t1 order by t1.i;
i i
2 1
3 1
2 2
3 2
select t1.i,t2.i,t3.i from t2 left join t3 on (t2.i=t3.i),t1 order by t1.i,t2.i,t3.i;
i i i
1 2 2
1 3 NULL
2 2 2
2 3 NULL
select * from t1,t2 natural right join t3 order by t1.i,t2.i,t3.i;
i i i
1 NULL 4
1 2 2
2 NULL 4
2 2 2
select * from t1,t2 natural right join t3 order by 1,2;
i i
1 2
1 4
2 2
2 4
select * from t1,t2 right join t3 on (t2.i=t3.i) order by t1.i,t2.i,t3.i;
i i i
1 NULL 4
1 2 2
2 NULL 4
2 2 2
select t1.i,t2.i,t3.i from t2 natural right join t3,t1 order by t1.i,t2.i,t3.i;
i i i
1 NULL 4
1 2 2
2 NULL 4
2 2 2
select * from t2 natural right join t3,t1 order by t1.i;
i i
2 1
4 1
2 2
4 2
select t1.i,t2.i,t3.i from t2 right join t3 on (t2.i=t3.i),t1 order by t1.i,t2.i,t3.i;
i i i
1 NULL 4

View File

@ -75,18 +75,11 @@ t1.client_ptr as client_ptr,
t1.comments as comments,
sum( t3.amount_received ) + sum( t3.adjustment ) as total_budget
from
t1 ,
t2 as client_period ,
t2 as project_period
left join
t3
on
t3.project_ptr = t1.project_id
and t3.date_received <= '2001-03-22 14:15:09'
left join
t4
on
t4.client_id = t1.client_ptr
t2 as project_period,
t3 left join t1 on (t3.project_ptr = t1.project_id and
t3.date_received <= '2001-03-22 14:15:09')
left join t4 on t4.client_id = t1.client_ptr
where
1
and ( client_period.period_type = 'client_table'

View File

@ -223,8 +223,7 @@ a b
1 2
EXPLAIN EXTENDED
SELECT t6.a,t6.b,t7.a,t7.b,t8.a,t8.b
FROM t6,
t7
FROM (t6, t7)
LEFT JOIN
t8
ON t7.b=t8.b AND t6.b < 10;
@ -235,8 +234,7 @@ id select_type table type possible_keys key key_len ref rows Extra
Warnings:
Note 1003 select `test`.`t6`.`a` AS `a`,`test`.`t6`.`b` AS `b`,`test`.`t7`.`a` AS `a`,`test`.`t7`.`b` AS `b`,`test`.`t8`.`a` AS `a`,`test`.`t8`.`b` AS `b` from `test`.`t6` join `test`.`t7` left join `test`.`t8` on(((`test`.`t7`.`b` = `test`.`t8`.`b`) and (`test`.`t6`.`b` < 10))) where 1
SELECT t6.a,t6.b,t7.a,t7.b,t8.a,t8.b
FROM t6,
t7
FROM (t6, t7)
LEFT JOIN
t8
ON t7.b=t8.b AND t6.b < 10;
@ -260,8 +258,7 @@ SELECT t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b
FROM t5
LEFT JOIN
(
t6,
t7
(t6, t7)
LEFT JOIN
t8
ON t7.b=t8.b AND t6.b < 10
@ -279,8 +276,7 @@ SELECT t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b
FROM t5
LEFT JOIN
(
t6,
t7
(t6, t7)
LEFT JOIN
t8
ON t7.b=t8.b AND t6.b < 10
@ -312,8 +308,7 @@ ON t3.a=1 AND t2.b=t4.b,
t5
LEFT JOIN
(
t6,
t7
(t6, t7)
LEFT JOIN
t8
ON t7.b=t8.b AND t6.b < 10
@ -357,8 +352,7 @@ ON t3.a=1 AND t2.b=t4.b,
t5
LEFT JOIN
(
t6,
t7
(t6, t7)
LEFT JOIN
t8
ON t7.b=t8.b AND t6.b < 10
@ -397,8 +391,7 @@ ON t3.a=1 AND t2.b=t4.b,
t5
LEFT JOIN
(
t6,
t7
(t6, t7)
LEFT JOIN
t8
ON t7.b=t8.b AND t6.b < 10
@ -470,8 +463,7 @@ ON t3.a=1 AND t2.b=t4.b,
t5
LEFT JOIN
(
t6,
t7
(t6, t7)
LEFT JOIN
t8
ON t7.b=t8.b AND t6.b < 10
@ -537,8 +529,7 @@ ON t3.a=1 AND t2.b=t4.b,
t5
LEFT JOIN
(
t6,
t7
(t6, t7)
LEFT JOIN
t8
ON t7.b=t8.b AND t6.b < 10
@ -575,8 +566,7 @@ ON t3.a=1 AND t2.b=t4.b,
t5
LEFT JOIN
(
t6,
t7
(t6, t7)
LEFT JOIN
t8
ON t7.b=t8.b AND t6.b < 10
@ -625,8 +615,7 @@ ON t3.a=1 AND t2.b=t4.b,
t5
LEFT JOIN
(
t6,
t7
(t6, t7)
LEFT JOIN
t8
ON t7.b=t8.b AND t6.b < 10
@ -679,8 +668,7 @@ ON t3.a=1 AND t2.b=t4.b,
t5
LEFT JOIN
(
t6,
t7
(t6, t7)
LEFT JOIN
t8
ON t7.b=t8.b AND t6.b < 10
@ -825,44 +813,38 @@ a b a b a b a b
1 3 5 3 NULL NULL NULL NULL
2 2 5 3 NULL NULL NULL NULL
SELECT t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
FROM t1, t3, t4
FROM t1, (t3, t4)
RIGHT JOIN
t2
ON t3.a=1 AND t2.b=t4.b
WHERE t1.a <= 2;
a b a b a b a b
1 3 3 3 1 2 NULL NULL
1 3 3 3 2 2 NULL NULL
2 2 3 3 1 2 NULL NULL
2 2 3 3 2 2 NULL NULL
1 3 3 3 NULL NULL NULL NULL
2 2 3 3 NULL NULL NULL NULL
1 3 4 2 1 2 3 2
1 3 4 2 1 2 4 2
1 3 4 2 2 2 NULL NULL
2 2 4 2 1 2 3 2
2 2 4 2 1 2 4 2
2 2 4 2 2 2 NULL NULL
1 3 5 3 1 2 NULL NULL
1 3 5 3 2 2 NULL NULL
2 2 5 3 1 2 NULL NULL
2 2 5 3 2 2 NULL NULL
1 3 5 3 NULL NULL NULL NULL
2 2 5 3 NULL NULL NULL NULL
EXPLAIN EXTENDED
SELECT t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
FROM t1, t3, t4
FROM t1, (t3, t4)
RIGHT JOIN
t2
ON t3.a=1 AND t2.b=t4.b
WHERE t1.a <= 2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3 ALL NULL NULL NULL NULL 2
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where
1 SIMPLE t2 ALL NULL NULL NULL NULL 3
1 SIMPLE t3 ALL NULL NULL NULL NULL 2
1 SIMPLE t4 ALL NULL NULL NULL NULL 2
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t1` join `test`.`t3` join `test`.`t2` left join `test`.`t4` on(((`test`.`t4`.`b` = `test`.`t2`.`b`) and (`test`.`t3`.`a` = 1))) where (`test`.`t1`.`a` <= 2)
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t1` join `test`.`t2` left join (`test`.`t3` join `test`.`t4`) on(((`test`.`t4`.`b` = `test`.`t2`.`b`) and (`test`.`t3`.`a` = 1))) where (`test`.`t1`.`a` <= 2)
CREATE INDEX idx_b ON t2(b);
EXPLAIN EXTENDED
SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
FROM t3,t4
FROM (t3,t4)
LEFT JOIN
(t1,t2)
ON t3.a=1 AND t3.b=t2.b AND t2.b=t4.b;
@ -874,7 +856,7 @@ id select_type table type possible_keys key key_len ref rows Extra
Warnings:
Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t3` join `test`.`t4` left join (`test`.`t1` join `test`.`t2`) on(((`test`.`t3`.`a` = 1) and (`test`.`t3`.`b` = `test`.`t2`.`b`) and (`test`.`t2`.`b` = `test`.`t4`.`b`))) where 1
SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
FROM t3,t4
FROM (t3,t4)
LEFT JOIN
(t1,t2)
ON t3.a=1 AND t3.b=t2.b AND t2.b=t4.b;
@ -900,8 +882,7 @@ ON t3.a=1 AND t2.b=t4.b,
t5
LEFT JOIN
(
t6,
t7
(t6, t7)
LEFT JOIN
t8
ON t7.b=t8.b AND t6.b < 10
@ -951,8 +932,7 @@ ON t3.a=1 AND t2.b=t4.b,
t5
LEFT JOIN
(
t6,
t7
(t6, t7)
LEFT JOIN
t8
ON t7.b=t8.b AND t6.b < 10
@ -1001,8 +981,7 @@ ON t3.a=1 AND t2.b=t4.b,
t5
LEFT JOIN
(
t6,
t7
(t6, t7)
LEFT JOIN
t8
ON t7.b=t8.b AND t6.b < 10
@ -1052,8 +1031,7 @@ ON t3.a=1 AND t2.b=t4.b,
t5
LEFT JOIN
(
t6,
t7
(t6, t7)
LEFT JOIN
t8
ON t7.b=t8.b AND t6.b < 10
@ -1100,8 +1078,7 @@ ON t3.a=1 AND t2.b=t4.b,
t5
LEFT JOIN
(
t6,
t7
(t6, t7)
LEFT JOIN
t8
ON t7.b=t8.b AND t6.b < 10
@ -1176,13 +1153,13 @@ a b a1 b
4 2 1 2
4 2 2 2
5 3 NULL NULL
SELECT t2.a,t2.b,t3.a1,t3.b
SELECT *
FROM t2 NATURAL LEFT JOIN t3
WHERE t2.a = 4 OR (t2.a > 4 AND t3.a1 IS NULL);
a b a1 b
4 2 1 2
4 2 2 2
5 3 NULL NULL
b a c a1 c1
2 4 0 1 0
2 4 0 2 0
3 5 0 NULL NULL
DROP TABLE t0,t1,t2,t3,t4,t5,t6,t7,t8,t9;
CREATE TABLE t1 (a int);
CREATE TABLE t2 (a int);

View File

@ -36,7 +36,16 @@ grp a c id a c d
3 5 C 3 5 B 5
3 6 D 3 6 C 6
NULL NULL NULL 4 7 D 7
select t1.*,t2.* from t1 left join t2 using (a);
select * from t1 left join t2 using (a);
a grp c id c d
1 1 a 1 a 1
2 2 b NULL NULL NULL
3 2 c NULL NULL NULL
4 3 E 3 A 4
5 3 C 3 B 5
6 3 D 3 C 6
NULL NULL NULL NULL NULL
select t1.*,t2.* from t1 left join t2 on t1.a=t2.a;
grp a c id a c d
1 1 a 1 1 a 1
2 2 b NULL NULL NULL NULL
@ -45,40 +54,34 @@ grp a c id a c d
3 5 C 3 5 B 5
3 6 D 3 6 C 6
NULL NULL NULL NULL NULL NULL
select t1.*,t2.* from t1 left join t2 using (a) where t1.a=t2.a;
grp a c id a c d
1 1 a 1 1 a 1
3 4 E 3 4 A 4
3 5 C 3 5 B 5
3 6 D 3 6 C 6
select t1.*,t2.* from t1 left join t2 using (a,c);
grp a c id a c d
1 1 a 1 1 a 1
2 2 b NULL NULL NULL NULL
2 3 c NULL NULL NULL NULL
3 4 E NULL NULL NULL NULL
3 5 C NULL NULL NULL NULL
3 6 D NULL NULL NULL NULL
NULL NULL NULL NULL NULL NULL
select t1.*,t2.* from t1 left join t2 using (c);
grp a c id a c d
1 1 a 1 1 a 1
1 1 a 3 4 A 4
2 2 b 3 5 B 5
2 3 c 3 6 C 6
3 4 E NULL NULL NULL NULL
3 5 C 3 6 C 6
3 6 D 4 7 D 7
NULL NULL NULL NULL NULL NULL
select t1.*,t2.* from t1 natural left outer join t2;
grp a c id a c d
1 1 a 1 1 a 1
2 2 b NULL NULL NULL NULL
2 3 c NULL NULL NULL NULL
3 4 E NULL NULL NULL NULL
3 5 C NULL NULL NULL NULL
3 6 D NULL NULL NULL NULL
NULL NULL NULL NULL NULL NULL
select * from t1 left join t2 using (a,c);
a c grp id d
1 a 1 1 1
2 b 2 NULL NULL
3 c 2 NULL NULL
4 E 3 NULL NULL
5 C 3 NULL NULL
6 D 3 NULL NULL
NULL NULL NULL NULL
select * from t1 left join t2 using (c);
c grp a id a d
a 1 1 1 1 1
a 1 1 3 4 4
b 2 2 3 5 5
c 2 3 3 6 6
E 3 4 NULL NULL NULL
C 3 5 3 6 6
D 3 6 4 7 7
NULL NULL NULL NULL NULL
select * from t1 natural left outer join t2;
a c grp id d
1 a 1 1 1
2 b 2 NULL NULL
3 c 2 NULL NULL
4 E 3 NULL NULL
5 C 3 NULL NULL
6 D 3 NULL NULL
NULL NULL NULL NULL
select t1.*,t2.* from t1 left join t2 on (t1.a=t2.a) where t2.id=3;
grp a c id a c d
3 4 E 3 4 A 4
@ -106,26 +109,26 @@ grp a c id a c d a
3 6 D 3 6 C 6 6
NULL NULL NULL NULL NULL NULL NULL
explain select t1.*,t2.*,t3.a from t1 left join t2 on (t3.a=t2.a) left join t1 as t3 on (t1.a=t3.a);
ERROR 42000: Cross dependency found in OUTER JOIN; examine your ON conditions
ERROR 42S22: Unknown column 't3.a' in 'on clause'
select t1.*,t2.*,t3.a from t1 left join t2 on (t3.a=t2.a) left join t1 as t3 on (t1.a=t3.a);
ERROR 42000: Cross dependency found in OUTER JOIN; examine your ON conditions
ERROR 42S22: Unknown column 't3.a' in 'on clause'
select t1.*,t2.*,t3.a from t1 left join t2 on (t3.a=t2.a) left join t1 as t3 on (t2.a=t3.a);
ERROR 42000: Cross dependency found in OUTER JOIN; examine your ON conditions
select t1.*,t2.* from t1 inner join t2 using (a);
grp a c id a c d
1 1 a 1 1 a 1
3 4 E 3 4 A 4
3 5 C 3 5 B 5
3 6 D 3 6 C 6
ERROR 42S22: Unknown column 't3.a' in 'on clause'
select * from t1 inner join t2 using (a);
a grp c id c d
1 1 a 1 a 1
4 3 E 3 A 4
5 3 C 3 B 5
6 3 D 3 C 6
select t1.*,t2.* from t1 inner join t2 on (t1.a=t2.a);
grp a c id a c d
1 1 a 1 1 a 1
3 4 E 3 4 A 4
3 5 C 3 5 B 5
3 6 D 3 6 C 6
select t1.*,t2.* from t1 natural join t2;
grp a c id d
1 1 a 1 1
select * from t1 natural join t2;
a c grp id d
1 a 1 1 1
drop table t1,t2;
CREATE TABLE t1 (
usr_id INT unsigned NOT NULL,
@ -400,7 +403,7 @@ insert into t3 values (1);
insert into t4 values (1,1);
insert into t5 values (1,1);
explain select * from t3 left join t4 on t4.seq_1_id = t2.t2_id left join t1 on t1.t1_id = t4.seq_0_id left join t5 on t5.seq_0_id = t1.t1_id left join t2 on t2.t2_id = t5.seq_1_id where t3.t3_id = 23;
ERROR 42000: Cross dependency found in OUTER JOIN; examine your ON conditions
ERROR 42S22: Unknown column 't2.t2_id' in 'on clause'
drop table t1,t2,t3,t4,t5;
create table t1 (n int, m int, o int, key(n));
create table t2 (n int not null, m int, o int, primary key(n));
@ -432,7 +435,7 @@ INSERT INTO t2 VALUES (3,'z');
SELECT t2.id2 FROM t2 LEFT OUTER JOIN t1 ON t1.id2 = t2.id2 WHERE id1 IS NULL;
id2
3
SELECT t2.id2 FROM t2 NATURAL LEFT OUTER JOIN t1 WHERE id1 IS NULL;
SELECT id2 FROM t2 NATURAL LEFT OUTER JOIN t1 WHERE id1 IS NULL;
id2
3
drop table t1,t2;
@ -461,10 +464,10 @@ count color
15 white
7 green
select * from t2 natural join t1;
count color name
10 green lime
7 green lime
5 black grape
color count name
green 10 lime
green 7 lime
black 5 grape
select t2.count, t1.name from t2 natural join t1;
count name
10 lime
@ -647,16 +650,15 @@ insert into t1 values(1),(2);
insert into t2 values(2),(3);
insert into t3 values(2),(4);
select * from t1 natural left join t2 natural left join t3;
i i i
1 NULL NULL
2 2 2
select * from t1 natural left join t2 where (t2.i is not null)=0;
i i
1 NULL
select * from t1 natural left join t2 where (t2.i is not null) is not null;
i i
1 NULL
2 2
i
1
2
select * from t1 natural left join t2 where (i is not null)=0;
i
select * from t1 natural left join t2 where (i is not null) is not null;
i
1
2
drop table t1,t2,t3;
create table t1 (f1 integer,f2 integer,f3 integer);
create table t2 (f2 integer,f4 integer);
@ -664,7 +666,7 @@ create table t3 (f3 integer,f5 integer);
select * from t1
left outer join t2 using (f2)
left outer join t3 using (f3);
ERROR 42S22: Unknown column 'test.t2.f3' in 'on clause'
f3 f2 f1 f4 f5
drop table t1,t2,t3;
create table t1 (a1 int, a2 int);
create table t2 (b1 int not null, b2 int);
@ -929,13 +931,13 @@ create table t1 (a int, b varchar(20));
create table t2 (a int, c varchar(20));
insert into t1 values (1,"aaaaaaaaaa"),(2,"bbbbbbbbbb");
insert into t2 values (1,"cccccccccc"),(2,"dddddddddd");
select group_concat(t1.b,t2.c) from t1 left join t2 using(a) group by t1.a;
select group_concat(t1.b,t2.c) from t1 left join t2 using(a) group by a;
group_concat(t1.b,t2.c)
aaaaa
bbbbb
Warnings:
Warning 1260 2 line(s) were cut by GROUP_CONCAT()
select group_concat(t1.b,t2.c) from t1 inner join t2 using(a) group by t1.a;
select group_concat(t1.b,t2.c) from t1 inner join t2 using(a) group by a;
group_concat(t1.b,t2.c)
aaaaa
bbbbb

View File

@ -135,16 +135,16 @@ create table t1 (n numeric(10));
create table t2 (n numeric(10));
insert into t2 values (1),(2),(4),(8),(16),(32);
select * from t2 left outer join t1 using (n);
n n
1 NULL
2 NULL
4 NULL
8 NULL
16 NULL
32 NULL
n
1
2
4
8
16
32
delete t1,t2 from t2 left outer join t1 using (n);
select * from t2 left outer join t1 using (n);
n n
n
drop table t1,t2 ;
create table t1 (n int(10) not null primary key, d int(10));
create table t2 (n int(10) not null primary key, d int(10));

View File

@ -313,12 +313,16 @@ INSERT INTO t1 (order_id, product_id, product_type) VALUES
('9d9aad7764b5b2c53004348ef8d34500',2315652, 3);
INSERT INTO t2 (order_id, product_id, product_type) VALUES
('9d9aad7764b5b2c53004348ef8d34500',2315652, 3);
select t1.* from t1
left join t2 using(order_id, product_id, product_type)
where t2.order_id=NULL;
select t1.* from t1 left join t2
on (t1.order_id = t2.order_id and
t1.product_id = t2.product_id and
t1.product_type = t2.product_type)
where t2.order_id = NULL;
order_id product_id product_type
select t1.* from t1
left join t2 using(order_id, product_id, product_type)
select t1.* from t1 left join t2
on (t1.order_id = t2.order_id and
t1.product_id = t2.product_id and
t1.product_type = t2.product_type)
where t2.order_id is NULL;
order_id product_id product_type
3d7ce39b5d4b3e3d22aaafe9b633de51 1206029 3

View File

@ -180,7 +180,7 @@ INSERT INTO t3 VALUES (1,'123 Park Place');
INSERT INTO t3 VALUES (2,'453 Boardwalk');
SELECT a,b,if(b = 1,i,if(b = 2,v,''))
FROM t1
LEFT JOIN t2 USING(c)
LEFT JOIN t2 ON t1.c = t2.c
LEFT JOIN t3 ON t3.c = t1.c;
a b if(b = 1,i,if(b = 2,v,''))
1 1 50
@ -189,7 +189,7 @@ a b if(b = 1,i,if(b = 2,v,''))
4 2 453 Boardwalk
SELECT a,b,if(b = 1,i,if(b = 2,v,''))
FROM t1
LEFT JOIN t2 USING(c)
LEFT JOIN t2 ON t1.c = t2.c
LEFT JOIN t3 ON t3.c = t1.c
ORDER BY a;
a b if(b = 1,i,if(b = 2,v,''))
@ -523,10 +523,10 @@ KEY `pseudo` (`pseudo`)
);
INSERT INTO t1 (titre,auteur,dest) VALUES ('test','joce','bug');
INSERT INTO t2 (numeropost,pseudo) VALUES (1,'joce'),(1,'bug');
SELECT titre,t1.numeropost,auteur,icone,nbrep,0,date,vue,ouvert,lastauteur,dest FROM t2 LEFT JOIN t1 USING(numeropost) WHERE t2.pseudo='joce' ORDER BY date DESC LIMIT 0,30;
SELECT titre,numeropost,auteur,icone,nbrep,0,date,vue,ouvert,lastauteur,dest FROM t2 LEFT JOIN t1 USING(numeropost) WHERE t2.pseudo='joce' ORDER BY date DESC LIMIT 0,30;
titre numeropost auteur icone nbrep 0 date vue ouvert lastauteur dest
test 1 joce 0 0 0 0000-00-00 00:00:00 0 1 bug
SELECT titre,t1.numeropost,auteur,icone,nbrep,'0',date,vue,ouvert,lastauteur,dest FROM t2 LEFT JOIN t1 USING(numeropost) WHERE t2.pseudo='joce' ORDER BY date DESC LIMIT 0,30;
SELECT titre,numeropost,auteur,icone,nbrep,'0',date,vue,ouvert,lastauteur,dest FROM t2 LEFT JOIN t1 USING(numeropost) WHERE t2.pseudo='joce' ORDER BY date DESC LIMIT 0,30;
titre numeropost auteur icone nbrep 0 date vue ouvert lastauteur dest
test 1 joce 0 0 0 0000-00-00 00:00:00 0 1 bug
drop table t1,t2;

View File

@ -519,56 +519,56 @@ a ? a
drop table if exists t2 ;
create table t2 as select * from t1 ;
set @query1= 'SELECT * FROM t2 join t1 on (t1.a=t2.a) order by t2.a ' ;
set @query2= 'SELECT * FROM t2 natural join t1 order by t2.a ' ;
set @query3= 'SELECT * FROM t2 join t1 using(a) order by t2.a ' ;
set @query2= 'SELECT * FROM t2 natural join t1 order by a ' ;
set @query3= 'SELECT * FROM t2 join t1 using(a) order by a ' ;
set @query4= 'SELECT * FROM t2 left join t1 on(t1.a=t2.a) order by t2.a ' ;
set @query5= 'SELECT * FROM t2 natural left join t1 order by t2.a ' ;
set @query6= 'SELECT * FROM t2 left join t1 using(a) order by t2.a ' ;
set @query5= 'SELECT * FROM t2 natural left join t1 order by a ' ;
set @query6= 'SELECT * FROM t2 left join t1 using(a) order by a ' ;
set @query7= 'SELECT * FROM t2 right join t1 on(t1.a=t2.a) order by t2.a ' ;
set @query8= 'SELECT * FROM t2 natural right join t1 order by t2.a ' ;
set @query9= 'SELECT * FROM t2 right join t1 using(a) order by t2.a ' ;
set @query8= 'SELECT * FROM t2 natural right join t1 order by a ' ;
set @query9= 'SELECT * FROM t2 right join t1 using(a) order by a ' ;
the join statement is:
SELECT * FROM t2 right join t1 using(a) order by t2.a
SELECT * FROM t2 right join t1 using(a) order by a
prepare stmt1 from @query9 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
the join statement is:
SELECT * FROM t2 natural right join t1 order by t2.a
SELECT * FROM t2 natural right join t1 order by a
prepare stmt1 from @query8 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
the join statement is:
SELECT * FROM t2 right join t1 on(t1.a=t2.a) order by t2.a
prepare stmt1 from @query7 ;
@ -591,47 +591,47 @@ a b a b
3 three 3 three
4 four 4 four
the join statement is:
SELECT * FROM t2 left join t1 using(a) order by t2.a
SELECT * FROM t2 left join t1 using(a) order by a
prepare stmt1 from @query6 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
the join statement is:
SELECT * FROM t2 natural left join t1 order by t2.a
SELECT * FROM t2 natural left join t1 order by a
prepare stmt1 from @query5 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
the join statement is:
SELECT * FROM t2 left join t1 on(t1.a=t2.a) order by t2.a
prepare stmt1 from @query4 ;
@ -654,28 +654,28 @@ a b a b
3 three 3 three
4 four 4 four
the join statement is:
SELECT * FROM t2 join t1 using(a) order by t2.a
SELECT * FROM t2 join t1 using(a) order by a
prepare stmt1 from @query3 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
the join statement is:
SELECT * FROM t2 natural join t1 order by t2.a
SELECT * FROM t2 natural join t1 order by a
prepare stmt1 from @query2 ;
execute stmt1 ;
a b

View File

@ -519,56 +519,56 @@ a ? a
drop table if exists t2 ;
create table t2 as select * from t1 ;
set @query1= 'SELECT * FROM t2 join t1 on (t1.a=t2.a) order by t2.a ' ;
set @query2= 'SELECT * FROM t2 natural join t1 order by t2.a ' ;
set @query3= 'SELECT * FROM t2 join t1 using(a) order by t2.a ' ;
set @query2= 'SELECT * FROM t2 natural join t1 order by a ' ;
set @query3= 'SELECT * FROM t2 join t1 using(a) order by a ' ;
set @query4= 'SELECT * FROM t2 left join t1 on(t1.a=t2.a) order by t2.a ' ;
set @query5= 'SELECT * FROM t2 natural left join t1 order by t2.a ' ;
set @query6= 'SELECT * FROM t2 left join t1 using(a) order by t2.a ' ;
set @query5= 'SELECT * FROM t2 natural left join t1 order by a ' ;
set @query6= 'SELECT * FROM t2 left join t1 using(a) order by a ' ;
set @query7= 'SELECT * FROM t2 right join t1 on(t1.a=t2.a) order by t2.a ' ;
set @query8= 'SELECT * FROM t2 natural right join t1 order by t2.a ' ;
set @query9= 'SELECT * FROM t2 right join t1 using(a) order by t2.a ' ;
set @query8= 'SELECT * FROM t2 natural right join t1 order by a ' ;
set @query9= 'SELECT * FROM t2 right join t1 using(a) order by a ' ;
the join statement is:
SELECT * FROM t2 right join t1 using(a) order by t2.a
SELECT * FROM t2 right join t1 using(a) order by a
prepare stmt1 from @query9 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
the join statement is:
SELECT * FROM t2 natural right join t1 order by t2.a
SELECT * FROM t2 natural right join t1 order by a
prepare stmt1 from @query8 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
the join statement is:
SELECT * FROM t2 right join t1 on(t1.a=t2.a) order by t2.a
prepare stmt1 from @query7 ;
@ -591,47 +591,47 @@ a b a b
3 three 3 three
4 four 4 four
the join statement is:
SELECT * FROM t2 left join t1 using(a) order by t2.a
SELECT * FROM t2 left join t1 using(a) order by a
prepare stmt1 from @query6 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
the join statement is:
SELECT * FROM t2 natural left join t1 order by t2.a
SELECT * FROM t2 natural left join t1 order by a
prepare stmt1 from @query5 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
the join statement is:
SELECT * FROM t2 left join t1 on(t1.a=t2.a) order by t2.a
prepare stmt1 from @query4 ;
@ -654,28 +654,28 @@ a b a b
3 three 3 three
4 four 4 four
the join statement is:
SELECT * FROM t2 join t1 using(a) order by t2.a
SELECT * FROM t2 join t1 using(a) order by a
prepare stmt1 from @query3 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
the join statement is:
SELECT * FROM t2 natural join t1 order by t2.a
SELECT * FROM t2 natural join t1 order by a
prepare stmt1 from @query2 ;
execute stmt1 ;
a b

View File

@ -520,56 +520,56 @@ a ? a
drop table if exists t2 ;
create table t2 as select * from t1 ;
set @query1= 'SELECT * FROM t2 join t1 on (t1.a=t2.a) order by t2.a ' ;
set @query2= 'SELECT * FROM t2 natural join t1 order by t2.a ' ;
set @query3= 'SELECT * FROM t2 join t1 using(a) order by t2.a ' ;
set @query2= 'SELECT * FROM t2 natural join t1 order by a ' ;
set @query3= 'SELECT * FROM t2 join t1 using(a) order by a ' ;
set @query4= 'SELECT * FROM t2 left join t1 on(t1.a=t2.a) order by t2.a ' ;
set @query5= 'SELECT * FROM t2 natural left join t1 order by t2.a ' ;
set @query6= 'SELECT * FROM t2 left join t1 using(a) order by t2.a ' ;
set @query5= 'SELECT * FROM t2 natural left join t1 order by a ' ;
set @query6= 'SELECT * FROM t2 left join t1 using(a) order by a ' ;
set @query7= 'SELECT * FROM t2 right join t1 on(t1.a=t2.a) order by t2.a ' ;
set @query8= 'SELECT * FROM t2 natural right join t1 order by t2.a ' ;
set @query9= 'SELECT * FROM t2 right join t1 using(a) order by t2.a ' ;
set @query8= 'SELECT * FROM t2 natural right join t1 order by a ' ;
set @query9= 'SELECT * FROM t2 right join t1 using(a) order by a ' ;
the join statement is:
SELECT * FROM t2 right join t1 using(a) order by t2.a
SELECT * FROM t2 right join t1 using(a) order by a
prepare stmt1 from @query9 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
the join statement is:
SELECT * FROM t2 natural right join t1 order by t2.a
SELECT * FROM t2 natural right join t1 order by a
prepare stmt1 from @query8 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
the join statement is:
SELECT * FROM t2 right join t1 on(t1.a=t2.a) order by t2.a
prepare stmt1 from @query7 ;
@ -592,47 +592,47 @@ a b a b
3 three 3 three
4 four 4 four
the join statement is:
SELECT * FROM t2 left join t1 using(a) order by t2.a
SELECT * FROM t2 left join t1 using(a) order by a
prepare stmt1 from @query6 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
the join statement is:
SELECT * FROM t2 natural left join t1 order by t2.a
SELECT * FROM t2 natural left join t1 order by a
prepare stmt1 from @query5 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
the join statement is:
SELECT * FROM t2 left join t1 on(t1.a=t2.a) order by t2.a
prepare stmt1 from @query4 ;
@ -655,28 +655,28 @@ a b a b
3 three 3 three
4 four 4 four
the join statement is:
SELECT * FROM t2 join t1 using(a) order by t2.a
SELECT * FROM t2 join t1 using(a) order by a
prepare stmt1 from @query3 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
the join statement is:
SELECT * FROM t2 natural join t1 order by t2.a
SELECT * FROM t2 natural join t1 order by a
prepare stmt1 from @query2 ;
execute stmt1 ;
a b

View File

@ -562,56 +562,56 @@ a ? a
drop table if exists t2 ;
create table t2 as select * from t1 ;
set @query1= 'SELECT * FROM t2 join t1 on (t1.a=t2.a) order by t2.a ' ;
set @query2= 'SELECT * FROM t2 natural join t1 order by t2.a ' ;
set @query3= 'SELECT * FROM t2 join t1 using(a) order by t2.a ' ;
set @query2= 'SELECT * FROM t2 natural join t1 order by a ' ;
set @query3= 'SELECT * FROM t2 join t1 using(a) order by a ' ;
set @query4= 'SELECT * FROM t2 left join t1 on(t1.a=t2.a) order by t2.a ' ;
set @query5= 'SELECT * FROM t2 natural left join t1 order by t2.a ' ;
set @query6= 'SELECT * FROM t2 left join t1 using(a) order by t2.a ' ;
set @query5= 'SELECT * FROM t2 natural left join t1 order by a ' ;
set @query6= 'SELECT * FROM t2 left join t1 using(a) order by a ' ;
set @query7= 'SELECT * FROM t2 right join t1 on(t1.a=t2.a) order by t2.a ' ;
set @query8= 'SELECT * FROM t2 natural right join t1 order by t2.a ' ;
set @query9= 'SELECT * FROM t2 right join t1 using(a) order by t2.a ' ;
set @query8= 'SELECT * FROM t2 natural right join t1 order by a ' ;
set @query9= 'SELECT * FROM t2 right join t1 using(a) order by a ' ;
the join statement is:
SELECT * FROM t2 right join t1 using(a) order by t2.a
SELECT * FROM t2 right join t1 using(a) order by a
prepare stmt1 from @query9 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
the join statement is:
SELECT * FROM t2 natural right join t1 order by t2.a
SELECT * FROM t2 natural right join t1 order by a
prepare stmt1 from @query8 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
the join statement is:
SELECT * FROM t2 right join t1 on(t1.a=t2.a) order by t2.a
prepare stmt1 from @query7 ;
@ -634,47 +634,47 @@ a b a b
3 three 3 three
4 four 4 four
the join statement is:
SELECT * FROM t2 left join t1 using(a) order by t2.a
SELECT * FROM t2 left join t1 using(a) order by a
prepare stmt1 from @query6 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
the join statement is:
SELECT * FROM t2 natural left join t1 order by t2.a
SELECT * FROM t2 natural left join t1 order by a
prepare stmt1 from @query5 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
the join statement is:
SELECT * FROM t2 left join t1 on(t1.a=t2.a) order by t2.a
prepare stmt1 from @query4 ;
@ -697,28 +697,28 @@ a b a b
3 three 3 three
4 four 4 four
the join statement is:
SELECT * FROM t2 join t1 using(a) order by t2.a
SELECT * FROM t2 join t1 using(a) order by a
prepare stmt1 from @query3 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
the join statement is:
SELECT * FROM t2 natural join t1 order by t2.a
SELECT * FROM t2 natural join t1 order by a
prepare stmt1 from @query2 ;
execute stmt1 ;
a b
@ -3574,56 +3574,56 @@ a ? a
drop table if exists t2 ;
create table t2 as select * from t1 ;
set @query1= 'SELECT * FROM t2 join t1 on (t1.a=t2.a) order by t2.a ' ;
set @query2= 'SELECT * FROM t2 natural join t1 order by t2.a ' ;
set @query3= 'SELECT * FROM t2 join t1 using(a) order by t2.a ' ;
set @query2= 'SELECT * FROM t2 natural join t1 order by a ' ;
set @query3= 'SELECT * FROM t2 join t1 using(a) order by a ' ;
set @query4= 'SELECT * FROM t2 left join t1 on(t1.a=t2.a) order by t2.a ' ;
set @query5= 'SELECT * FROM t2 natural left join t1 order by t2.a ' ;
set @query6= 'SELECT * FROM t2 left join t1 using(a) order by t2.a ' ;
set @query5= 'SELECT * FROM t2 natural left join t1 order by a ' ;
set @query6= 'SELECT * FROM t2 left join t1 using(a) order by a ' ;
set @query7= 'SELECT * FROM t2 right join t1 on(t1.a=t2.a) order by t2.a ' ;
set @query8= 'SELECT * FROM t2 natural right join t1 order by t2.a ' ;
set @query9= 'SELECT * FROM t2 right join t1 using(a) order by t2.a ' ;
set @query8= 'SELECT * FROM t2 natural right join t1 order by a ' ;
set @query9= 'SELECT * FROM t2 right join t1 using(a) order by a ' ;
the join statement is:
SELECT * FROM t2 right join t1 using(a) order by t2.a
SELECT * FROM t2 right join t1 using(a) order by a
prepare stmt1 from @query9 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
the join statement is:
SELECT * FROM t2 natural right join t1 order by t2.a
SELECT * FROM t2 natural right join t1 order by a
prepare stmt1 from @query8 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
the join statement is:
SELECT * FROM t2 right join t1 on(t1.a=t2.a) order by t2.a
prepare stmt1 from @query7 ;
@ -3646,47 +3646,47 @@ a b a b
3 three 3 three
4 four 4 four
the join statement is:
SELECT * FROM t2 left join t1 using(a) order by t2.a
SELECT * FROM t2 left join t1 using(a) order by a
prepare stmt1 from @query6 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
the join statement is:
SELECT * FROM t2 natural left join t1 order by t2.a
SELECT * FROM t2 natural left join t1 order by a
prepare stmt1 from @query5 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
the join statement is:
SELECT * FROM t2 left join t1 on(t1.a=t2.a) order by t2.a
prepare stmt1 from @query4 ;
@ -3709,28 +3709,28 @@ a b a b
3 three 3 three
4 four 4 four
the join statement is:
SELECT * FROM t2 join t1 using(a) order by t2.a
SELECT * FROM t2 join t1 using(a) order by a
prepare stmt1 from @query3 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
the join statement is:
SELECT * FROM t2 natural join t1 order by t2.a
SELECT * FROM t2 natural join t1 order by a
prepare stmt1 from @query2 ;
execute stmt1 ;
a b

View File

@ -519,56 +519,56 @@ a ? a
drop table if exists t2 ;
create table t2 as select * from t1 ;
set @query1= 'SELECT * FROM t2 join t1 on (t1.a=t2.a) order by t2.a ' ;
set @query2= 'SELECT * FROM t2 natural join t1 order by t2.a ' ;
set @query3= 'SELECT * FROM t2 join t1 using(a) order by t2.a ' ;
set @query2= 'SELECT * FROM t2 natural join t1 order by a ' ;
set @query3= 'SELECT * FROM t2 join t1 using(a) order by a ' ;
set @query4= 'SELECT * FROM t2 left join t1 on(t1.a=t2.a) order by t2.a ' ;
set @query5= 'SELECT * FROM t2 natural left join t1 order by t2.a ' ;
set @query6= 'SELECT * FROM t2 left join t1 using(a) order by t2.a ' ;
set @query5= 'SELECT * FROM t2 natural left join t1 order by a ' ;
set @query6= 'SELECT * FROM t2 left join t1 using(a) order by a ' ;
set @query7= 'SELECT * FROM t2 right join t1 on(t1.a=t2.a) order by t2.a ' ;
set @query8= 'SELECT * FROM t2 natural right join t1 order by t2.a ' ;
set @query9= 'SELECT * FROM t2 right join t1 using(a) order by t2.a ' ;
set @query8= 'SELECT * FROM t2 natural right join t1 order by a ' ;
set @query9= 'SELECT * FROM t2 right join t1 using(a) order by a ' ;
the join statement is:
SELECT * FROM t2 right join t1 using(a) order by t2.a
SELECT * FROM t2 right join t1 using(a) order by a
prepare stmt1 from @query9 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
the join statement is:
SELECT * FROM t2 natural right join t1 order by t2.a
SELECT * FROM t2 natural right join t1 order by a
prepare stmt1 from @query8 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
the join statement is:
SELECT * FROM t2 right join t1 on(t1.a=t2.a) order by t2.a
prepare stmt1 from @query7 ;
@ -591,47 +591,47 @@ a b a b
3 three 3 three
4 four 4 four
the join statement is:
SELECT * FROM t2 left join t1 using(a) order by t2.a
SELECT * FROM t2 left join t1 using(a) order by a
prepare stmt1 from @query6 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
the join statement is:
SELECT * FROM t2 natural left join t1 order by t2.a
SELECT * FROM t2 natural left join t1 order by a
prepare stmt1 from @query5 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
the join statement is:
SELECT * FROM t2 left join t1 on(t1.a=t2.a) order by t2.a
prepare stmt1 from @query4 ;
@ -654,28 +654,28 @@ a b a b
3 three 3 three
4 four 4 four
the join statement is:
SELECT * FROM t2 join t1 using(a) order by t2.a
SELECT * FROM t2 join t1 using(a) order by a
prepare stmt1 from @query3 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
the join statement is:
SELECT * FROM t2 natural join t1 order by t2.a
SELECT * FROM t2 natural join t1 order by a
prepare stmt1 from @query2 ;
execute stmt1 ;
a b

View File

@ -519,56 +519,56 @@ a ? a
drop table if exists t2 ;
create table t2 as select * from t1 ;
set @query1= 'SELECT * FROM t2 join t1 on (t1.a=t2.a) order by t2.a ' ;
set @query2= 'SELECT * FROM t2 natural join t1 order by t2.a ' ;
set @query3= 'SELECT * FROM t2 join t1 using(a) order by t2.a ' ;
set @query2= 'SELECT * FROM t2 natural join t1 order by a ' ;
set @query3= 'SELECT * FROM t2 join t1 using(a) order by a ' ;
set @query4= 'SELECT * FROM t2 left join t1 on(t1.a=t2.a) order by t2.a ' ;
set @query5= 'SELECT * FROM t2 natural left join t1 order by t2.a ' ;
set @query6= 'SELECT * FROM t2 left join t1 using(a) order by t2.a ' ;
set @query5= 'SELECT * FROM t2 natural left join t1 order by a ' ;
set @query6= 'SELECT * FROM t2 left join t1 using(a) order by a ' ;
set @query7= 'SELECT * FROM t2 right join t1 on(t1.a=t2.a) order by t2.a ' ;
set @query8= 'SELECT * FROM t2 natural right join t1 order by t2.a ' ;
set @query9= 'SELECT * FROM t2 right join t1 using(a) order by t2.a ' ;
set @query8= 'SELECT * FROM t2 natural right join t1 order by a ' ;
set @query9= 'SELECT * FROM t2 right join t1 using(a) order by a ' ;
the join statement is:
SELECT * FROM t2 right join t1 using(a) order by t2.a
SELECT * FROM t2 right join t1 using(a) order by a
prepare stmt1 from @query9 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
the join statement is:
SELECT * FROM t2 natural right join t1 order by t2.a
SELECT * FROM t2 natural right join t1 order by a
prepare stmt1 from @query8 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
the join statement is:
SELECT * FROM t2 right join t1 on(t1.a=t2.a) order by t2.a
prepare stmt1 from @query7 ;
@ -591,47 +591,47 @@ a b a b
3 three 3 three
4 four 4 four
the join statement is:
SELECT * FROM t2 left join t1 using(a) order by t2.a
SELECT * FROM t2 left join t1 using(a) order by a
prepare stmt1 from @query6 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
the join statement is:
SELECT * FROM t2 natural left join t1 order by t2.a
SELECT * FROM t2 natural left join t1 order by a
prepare stmt1 from @query5 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b
1 one
2 two
3 three
4 four
the join statement is:
SELECT * FROM t2 left join t1 on(t1.a=t2.a) order by t2.a
prepare stmt1 from @query4 ;
@ -654,28 +654,28 @@ a b a b
3 three 3 three
4 four 4 four
the join statement is:
SELECT * FROM t2 join t1 using(a) order by t2.a
SELECT * FROM t2 join t1 using(a) order by a
prepare stmt1 from @query3 ;
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
execute stmt1 ;
a b a b
1 one 1 one
2 two 2 two
3 three 3 three
4 four 4 four
a b b
1 one one
2 two two
3 three three
4 four four
the join statement is:
SELECT * FROM t2 natural join t1 order by t2.a
SELECT * FROM t2 natural join t1 order by a
prepare stmt1 from @query2 ;
execute stmt1 ;
a b

View File

@ -1350,45 +1350,42 @@ fld1 fld1
250504 250505
250505 250505
insert into t2 (fld1, companynr) values (999999,99);
select t2.companynr,companyname from t2 left join t4 using (companynr) where t4.companynr is null;
select companynr,companyname from t2 left join t4 using (companynr) where companynr is null;
companynr companyname
99 NULL
select count(*) from t2 left join t4 using (companynr) where t4.companynr is not null;
select count(*) from t2 left join t4 using (companynr) where companynr is not null;
count(*)
1199
explain select t2.companynr,companyname from t2 left join t4 using (companynr) where t4.companynr is null;
1200
explain select companynr,companyname from t2 left join t4 using (companynr) where companynr is null;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 1200
1 SIMPLE t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1 Using where; Not exists
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr is null;
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr is null;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t4 ALL NULL NULL NULL NULL 12
1 SIMPLE t2 ALL NULL NULL NULL NULL 1200 Using where; Not exists
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
delete from t2 where fld1=999999;
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0;
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where
1 SIMPLE t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0;
1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where
1 SIMPLE t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 and t4.companynr > 0;
1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 and companynr > 0;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where
1 SIMPLE t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr is null;
1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr is null;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t4 ALL NULL NULL NULL NULL 12
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0 or t4.companynr > 0;
1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0 or companynr > 0;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where ifnull(t2.companynr,1)>0;
1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199
explain select companynr,companyname from t4 left join t2 using (companynr) where ifnull(companynr,1)>0;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t4 ALL NULL NULL NULL NULL 12
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where
1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199
select distinct t2.companynr,t4.companynr from t2,t4 where t2.companynr=t4.companynr+1;
companynr companynr
37 36
@ -2115,159 +2112,142 @@ insert into t1 values ();
insert into t1 values ();
insert into t1 values ();
select * from (t1 as t2 left join t1 as t3 using (a)), t1;
a a a
1 1 1
2 2 1
3 3 1
1 1 2
2 2 2
3 3 2
1 1 3
2 2 3
3 3 3
a a
1 1
2 1
3 1
1 2
2 2
3 2
1 3
2 3
3 3
select * from t1, (t1 as t2 left join t1 as t3 using (a));
a a a
1 1 1
2 1 1
3 1 1
1 2 2
2 2 2
3 2 2
1 3 3
2 3 3
3 3 3
a a
1 1
2 1
3 1
1 2
2 2
3 2
1 3
2 3
3 3
select * from (t1 as t2 left join t1 as t3 using (a)) straight_join t1;
a a a
1 1 1
2 2 1
3 3 1
1 1 2
2 2 2
3 3 2
1 1 3
2 2 3
3 3 3
a a
1 1
2 1
3 1
1 2
2 2
3 2
1 3
2 3
3 3
select * from t1 straight_join (t1 as t2 left join t1 as t3 using (a));
a a a
1 1 1
2 1 1
3 1 1
1 2 2
2 2 2
3 2 2
1 3 3
2 3 3
3 3 3
a a
1 1
2 1
3 1
1 2
2 2
3 2
1 3
2 3
3 3
select * from (t1 as t2 left join t1 as t3 using (a)) inner join t1 on t1.a>1;
a a a
1 1 2
2 2 2
3 3 2
1 1 3
2 2 3
3 3 3
a a
1 2
2 2
3 2
1 3
2 3
3 3
select * from t1 inner join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;
a a a
2 1 1
3 1 1
2 2 2
3 2 2
2 3 3
3 3 3
a a
2 1
3 1
2 2
3 2
2 3
3 3
select * from (t1 as t2 left join t1 as t3 using (a)) inner join t1 using ( a );
a a a
1 1 1
2 2 2
3 3 3
a
1
2
3
select * from t1 inner join (t1 as t2 left join t1 as t3 using (a)) using ( a );
a a a
1 1 1
2 2 2
3 3 3
a
1
2
3
select * from (t1 as t2 left join t1 as t3 using (a)) left outer join t1 on t1.a>1;
a a a
1 1 2
1 1 3
2 2 2
2 2 3
3 3 2
3 3 3
a a
1 2
1 3
2 2
2 3
3 2
3 3
select * from t1 left outer join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;
a a a
1 NULL NULL
2 1 1
2 2 2
2 3 3
3 1 1
3 2 2
3 3 3
a a
1 NULL
2 1
2 2
2 3
3 1
3 2
3 3
select * from (t1 as t2 left join t1 as t3 using (a)) left join t1 using ( a );
a a a
1 1 1
2 2 2
3 3 3
a
1
2
3
select * from t1 left join (t1 as t2 left join t1 as t3 using (a)) using ( a );
a a a
1 1 1
2 2 2
3 3 3
a
1
2
3
select * from (t1 as t2 left join t1 as t3 using (a)) natural left join t1;
a a a
1 1 1
2 2 2
3 3 3
a
1
2
3
select * from t1 natural left join (t1 as t2 left join t1 as t3 using (a));
a a a
1 1 1
2 2 2
3 3 3
select * from (t1 as t2 left join t1 as t3 using (a)) right join t1 on t1.a>1;
a a a
NULL NULL 1
1 1 2
2 2 2
3 3 2
1 1 3
2 2 3
3 3 3
select * from t1 right join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;
a a a
2 1 1
3 1 1
2 2 2
3 2 2
2 3 3
3 3 3
a
1
2
3
select * from (t1 as t2 left join t1 as t3 using (a)) right outer join t1 using ( a );
a a a
1 1 1
2 2 2
3 3 3
a
1
2
3
select * from t1 right outer join (t1 as t2 left join t1 as t3 using (a)) using ( a );
a a a
1 1 1
2 2 2
3 3 3
a
1
2
3
select * from (t1 as t2 left join t1 as t3 using (a)) natural right join t1;
a a a
1 1 1
2 2 2
3 3 3
a
1
2
3
select * from t1 natural right join (t1 as t2 left join t1 as t3 using (a));
a a a
1 1 1
2 2 2
3 3 3
a
1
2
3
select * from t1 natural join (t1 as t2 left join t1 as t3 using (a));
a a
1 1
2 2
3 3
a
1
2
3
select * from (t1 as t2 left join t1 as t3 using (a)) natural join t1;
a a
1 1
2 2
3 3
a
1
2
3
drop table t1;
CREATE TABLE t1 ( aa char(2), id int(11) NOT NULL auto_increment, t2_id int(11) NOT NULL default '0', PRIMARY KEY (id), KEY replace_id (t2_id)) ENGINE=MyISAM;
INSERT INTO t1 VALUES ("1",8264,2506),("2",8299,2517),("3",8301,2518),("4",8302,2519),("5",8303,2520),("6",8304,2521),("7",8305,2522);

View File

@ -84,7 +84,7 @@ set local max_join_size=8;
select * from (select * from t1) x;
ERROR 42000: The SELECT would examine more than MAX_JOIN_SIZE rows; check your WHERE and use SET SQL_BIG_SELECTS=1 or SET SQL_MAX_JOIN_SIZE=# if the SELECT is okay
set local max_join_size=1;
select * from (select * from t1 a, t1 b) x;
select * from (select a.a as aa, b.a as ba from t1 a, t1 b) x;
ERROR 42000: The SELECT would examine more than MAX_JOIN_SIZE rows; check your WHERE and use SET SQL_BIG_SELECTS=1 or SET SQL_MAX_JOIN_SIZE=# if the SELECT is okay
set local max_join_size=1;
select * from (select 1 union select 2 union select 3) x;

View File

@ -1200,7 +1200,7 @@ 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+1 WHERE i=(SELECT MAX(i));
UPDATE t1 SET t.i=i+(SELECT MAX(i) FROM (SELECT 1) t);
ERROR 42S02: Unknown table 't' in field list
ERROR 42S22: Unknown column 't.i' in 'field list'
select * from t1;
i
1
@ -1638,7 +1638,7 @@ ERROR 42S22: Unknown column 't1.s2' in 'where clause'
select * from t1 where (select count(*) from t2 group by t1.s2) = 1;
ERROR 42S22: Unknown column 't1.s2' in 'group statement'
select count(*) from t2 group by t1.s2;
ERROR 42S02: Unknown table 't1' in group statement
ERROR 42S22: Unknown column 't1.s2' in 'group statement'
drop table t1, t2;
CREATE TABLE t1(COLA FLOAT NOT NULL,COLB FLOAT NOT NULL,COLC VARCHAR(20) DEFAULT NULL,PRIMARY KEY (COLA, COLB));
CREATE TABLE t2(COLA FLOAT NOT NULL,COLB FLOAT NOT NULL,COLC CHAR(1) NOT NULL,PRIMARY KEY (COLA));
@ -1789,11 +1789,11 @@ CREATE TABLE t1 (id INT);
CREATE TABLE t2 (id INT);
INSERT INTO t1 VALUES (1), (2);
INSERT INTO t2 VALUES (1);
SELECT t1.id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id);
SELECT id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id);
id c
1 1
2 0
SELECT t1.id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id) ORDER BY t1.id;
SELECT id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id) ORDER BY id;
id c
1 1
2 0
@ -2754,13 +2754,26 @@ one two flag
5 6 N
7 8 N
insert into t2 values (null,null,'N');
insert into t2 values (null,3,'0');
insert into t2 values (null,5,'0');
insert into t2 values (10,null,'0');
insert into t1 values (10,3,'0');
insert into t1 values (10,5,'0');
insert into t1 values (10,10,'0');
SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N') as 'test' from t1;
one two test
1 2 0
2 3 0
3 4 0
1 2 NULL
2 3 NULL
3 4 NULL
5 6 1
7 8 1
10 3 NULL
10 5 NULL
10 10 NULL
SELECT one,two from t1 where ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N');
one two
5 6
7 8
SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N' group by one,two) as 'test' from t1;
one two test
1 2 NULL
@ -2768,6 +2781,47 @@ one two test
3 4 NULL
5 6 1
7 8 1
10 3 NULL
10 5 NULL
10 10 NULL
SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0') as 'test' from t1;
one two test
1 2 0
2 3 NULL
3 4 0
5 6 0
7 8 0
10 3 NULL
10 5 NULL
10 10 NULL
SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0' group by one,two) as 'test' from t1;
one two test
1 2 0
2 3 NULL
3 4 0
5 6 0
7 8 0
10 3 NULL
10 5 NULL
10 10 NULL
explain extended SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0') as 'test' from t1;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 8
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 Using where
Warnings:
Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one` AS `one`,`test`.`t2`.`two` AS `two` from `test`.`t2` where ((`test`.`t2`.`flag` = _latin1'0') and ((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`)) and ((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`))) having (<is_not_null_test>(`test`.`t2`.`one`) and <is_not_null_test>(`test`.`t2`.`two`)))) AS `test` from `test`.`t1`
explain extended SELECT one,two from t1 where ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N');
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 8 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 Using where
Warnings:
Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one` AS `one`,`test`.`t2`.`two` AS `two` from `test`.`t2` where ((`test`.`t2`.`flag` = _latin1'N') and (<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) and (<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`))))
explain extended SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0' group by one,two) as 'test' from t1;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 8
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 Using where; Using temporary; Using filesort
Warnings:
Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one` AS `one`,`test`.`t2`.`two` AS `two` from `test`.`t2` where (`test`.`t2`.`flag` = _latin1'0') group by `test`.`t2`.`one`,`test`.`t2`.`two` having (((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`)) and ((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`)) and <is_not_null_test>(`test`.`t2`.`one`) and <is_not_null_test>(`test`.`t2`.`two`)))) AS `test` from `test`.`t1`
DROP TABLE t1,t2;
CREATE TABLE t1 (a char(5), b char(5));
INSERT INTO t1 VALUES (NULL,'aaa'), ('aaa','aaa');

View File

@ -307,18 +307,18 @@ create table t1 ( id integer unsigned not null primary key );
create table t2 ( id integer unsigned not null primary key );
insert into t1 values (1), (2);
insert into t2 values (1);
select t1.id as id_A, t2.id as id_B from t1 left join t2 using ( id );
select t1.id as id_A, t2.id as id_B from t1 left join t2 on (t1.id = t2.id);
id_A id_B
1 1
2 NULL
create table t3 (id_A integer unsigned not null, id_B integer unsigned null );
insert into t3 select t1.id as id_A, t2.id as id_B from t1 left join t2 using ( id );
insert into t3 select t1.id as id_A, t2.id as id_B from t1 left join t2 on (t1.id = t2.id);
select * from t3;
id_A id_B
1 1
2 NULL
drop table t3;
create table t3 select t1.id as id_A, t2.id as id_B from t1 left join t2 using ( id );
create table t3 select t1.id as id_A, t2.id as id_B from t1 left join t2 on (t1.id = t2.id);
select * from t3;
id_A id_B
1 1

View File

@ -430,7 +430,7 @@ drop temporary table t1;
create table t1 select a from t1 union select a from t2;
ERROR HY000: You can't specify target table 't1' for update in FROM clause
select a from t1 union select a from t2 order by t2.a;
ERROR 42S02: Unknown table 't2' in order clause
ERROR 42S22: Unknown column 't2.a' in 'order clause'
drop table t1,t2;
select length(version()) > 1 as `*` UNION select 2;
*

View File

@ -2092,3 +2092,8 @@ SELECT a FROM v1;
a
DROP VIEW v1;
DROP TABLE t1,t2,t3,t4,t5;
create view v1 as select timestampdiff(day,'1997-01-01 00:00:00','1997-01-02 00:00:00') as f1;
select * from v1;
f1
1
drop view v1;

View File

@ -22,6 +22,8 @@ a
xa start 'testa','testb';
insert t1 values (30);
xa end 'testa','testb';
xa start 'testa','testb';
ERROR XAE08: XAER_DUPID: The XID already exists
xa start 0x7465737462, 0x2030405060, 0xb;
insert t1 values (40);
xa end 'testb',' 0@P`',11;
@ -35,11 +37,11 @@ formatID gtrid_length bqual_length data
11 5 5 testb 0@P`
1 5 5 testatestb
xa commit 'testb',0x2030405060,11;
ERROR XAE04: XAER_NOTA: Unknown XID
xa rollback 'testa','testb';
xa start 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz';
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
select * from t1;
a
20
40
drop table t1;

View File

@ -400,7 +400,7 @@ drop table t1;
set @a:=now();
CREATE TABLE t1 (a int not null, b timestamp not null, primary key (a)) engine=bdb;
insert into t1 (a) values(1),(2),(3);
select t1.a from t1 natural join t1 as t2 where t1.b >= @a order by t1.a;
select a from t1 natural join t1 as t2 where b >= @a order by a;
update t1 set a=5 where a=1;
select a from t1;
drop table t1;
@ -571,7 +571,7 @@ create temporary table tmp1
select branch_id, target_id, platform_id, product_id
from t1, t2, t3, t4 ;
create temporary table tmp2
select tmp1.branch_id, tmp1.target_id, tmp1.platform_id, tmp1.product_id
select branch_id, target_id, platform_id, product_id
from tmp1 left join t8
using (branch_id,target_id,platform_id,product_id)
where t8.archive_id is null ;

View File

@ -42,7 +42,7 @@ CREATE TABLE t2 (a int not null);
insert into t2 values(1);
select * from (select * from t1 where t1.a=(select a from t2 where t2.a=t1.a)) a;
select * from (select * from t1 where t1.a=(select t2.a from t2 where t2.a=t1.a) union select t1.a, t1.b from t1) a;
explain select * from (select * from t1,t2 where t1.a=t2.a) t1;
explain select * from (select t1.*, t2.a as t2a from t1,t2 where t1.a=t2.a) t1;
drop table t1, t2;
create table t1(a int not null, t char(8), index(a));
disable_query_log;
@ -249,4 +249,13 @@ select * from t1 union distinct select * from t2 union all select * from t3;
select * from (select * from t1 union distinct select * from t2 union all select * from t3) X;
drop table t1, t2, t3;
#
# Bug #11864 non unique names are allowed in subquery
#
create table t1 (a int);
create table t2 (a int);
--error 1060
select * from (select * from t1,t2) foo;
drop table t1,t2;
# End of 4.1 tests

View File

@ -14,9 +14,9 @@ update t1 set a=1;
create table t1 (a int);
--error 1054
select count(test.t1.b) from t1;
--error 1109
--error 1054
select count(not_existing_database.t1) from t1;
--error 1109
--error 1054
select count(not_existing_database.t1.a) from t1;
--error 1044,1146
select count(not_existing_database.t1.a) from not_existing_database.t1;

View File

@ -128,14 +128,14 @@ WHERE ticket2.id = ttxt.ticket AND t1.id = ticket2.ticket and
match(ttxt.inhalt) against ('foobar');
# In the following query MySQL didn't use the fulltext index
select t1.id FROM t2 as ttxt,t1 INNER JOIN t1 as ticket2 ON
ticket2.id = ttxt.ticket
WHERE t1.id = ticket2.ticket and match(ttxt.inhalt) against ('foobar');
select ticket2.id FROM t2 as ttxt,t2 INNER JOIN t1 as ticket2 ON
ticket2.id = t2.ticket
WHERE ticket2.id = ticket2.ticket and match(ttxt.inhalt) against ('foobar');
INSERT INTO t1 VALUES (3,3);
select t1.id FROM t2 as ttxt,t1
INNER JOIN t1 as ticket2 ON ticket2.id = ttxt.ticket
WHERE t1.id = ticket2.ticket and
select ticket2.id FROM t2 as ttxt,t2
INNER JOIN t1 as ticket2 ON ticket2.id = t2.ticket
WHERE ticket2.id = ticket2.ticket and
match(ttxt.inhalt) against ('foobar');
# Check that we get 'fulltext' index in SHOW CREATE

View File

@ -80,7 +80,7 @@ CREATE TABLE t3 (
FULLTEXT KEY betreff (betreff)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=996 ;
--error 1109
--error 1054
select a.text, b.id, b.betreff
from
t2 a inner join t3 b on a.id = b.forum inner join
@ -100,7 +100,7 @@ group by
order by
match(b.betreff) against ('+abc' in boolean mode) desc;
--error 1109
--error 1054
select a.text, b.id, b.betreff
from
t2 a inner join t3 b on a.id = b.forum inner join

View File

@ -31,6 +31,18 @@ drop table t1;
select TRUE,FALSE,NULL;
#
# Bug#12351: CONCAT with USER()/DATEBASE() and
# a constant and a column gets strange results
#
create table t1 (c1 char(5)) character set=latin1;
insert into t1 values('row 1');
insert into t1 values('row 2');
insert into t1 values('row 3');
select concat(user(), '--', c1) from t1;
select concat(database(), '--', c1) from t1;
drop table t1;
#
# Bug#8291 Illegal collation mix with USER() function
#

View File

@ -440,7 +440,7 @@ drop table t1;
set @a:=now();
CREATE TABLE t1 (a int not null, b timestamp not null, primary key (a)) engine=innodb;
insert into t1 (a) values(1),(2),(3);
select t1.a from t1 natural join t1 as t2 where t1.b >= @a order by t1.a;
select a from t1 natural join t1 as t2 where b >= @a order by a;
update t1 set a=5 where a=1;
select a from t1;
drop table t1;
@ -981,7 +981,7 @@ insert into `t3`values ( 1 ) ;
delete t3,t2,t1 from t1,t2,t3 where t1.id =1 and t2.id = t1.id and t3.id = t2.id;
--error 1217
update t1,t2,t3 set t3.id=5, t2.id=6, t1.id=7 where t1.id =1 and t2.id = t1.id and t3.id = t2.id;
--error 1109
--error 1054
update t3 set t3.id=7 where t1.id =1 and t2.id = t1.id and t3.id = t2.id;
drop table t3,t2,t1;

View File

@ -196,9 +196,9 @@ insert into t1 select t2.a from t2 group by t2.a on duplicate key update a= a +
#Some error cases
--error 1052
insert into t1 select t2.a from t2 on duplicate key update a= a + t2.b;
--error 1109
--error 1054
insert into t1 select t2.a from t2 on duplicate key update t2.a= a + t2.b;
--error 1109
--error 1054
insert into t1 select t2.a from t2 group by t2.a on duplicate key update a= t1.a + t2.b;
drop table t1,t2,t3;

View File

@ -111,10 +111,12 @@ drop table t1, t2;
create table t1 (a int primary key);
insert into t1 values(1),(2);
select t1.a from t1 as t1 left join t1 as t2 using (a) left join t1 as t3 using (a) left join t1 as t4 using (a) left join t1 as t5 using (a) left join t1 as t6 using (a) left join t1 as t7 using (a) left join t1 as t8 using (a) left join t1 as t9 using (a) left join t1 as t10 using (a) left join t1 as t11 using (a) left join t1 as t12 using (a) left join t1 as t13 using (a) left join t1 as t14 using (a) left join t1 as t15 using (a) left join t1 as t16 using (a) left join t1 as t17 using (a) left join t1 as t18 using (a) left join t1 as t19 using (a) left join t1 as t20 using (a) left join t1 as t21 using (a) left join t1 as t22 using (a) left join t1 as t23 using (a) left join t1 as t24 using (a) left join t1 as t25 using (a) left join t1 as t26 using (a) left join t1 as t27 using (a) left join t1 as t28 using (a) left join t1 as t29 using (a) left join t1 as t30 using (a) left join t1 as t31 using (a);
# TODO: WL#2486 - the query fails in PS mode with error:
# Cross dependency found in OUTER JOIN; examine your ON conditions
#select a from t1 as t1 left join t1 as t2 using (a) left join t1 as t3 using (a) left join t1 as t4 using (a) left join t1 as t5 using (a) left join t1 as t6 using (a) left join t1 as t7 using (a) left join t1 as t8 using (a) left join t1 as t9 using (a) left join t1 as t10 using (a) left join t1 as t11 using (a) left join t1 as t12 using (a) left join t1 as t13 using (a) left join t1 as t14 using (a) left join t1 as t15 using (a) left join t1 as t16 using (a) left join t1 as t17 using (a) left join t1 as t18 using (a) left join t1 as t19 using (a) left join t1 as t20 using (a) left join t1 as t21 using (a) left join t1 as t22 using (a) left join t1 as t23 using (a) left join t1 as t24 using (a) left join t1 as t25 using (a) left join t1 as t26 using (a) left join t1 as t27 using (a) left join t1 as t28 using (a) left join t1 as t29 using (a) left join t1 as t30 using (a) left join t1 as t31 using (a);
--replace_result "31 tables" "XX tables" "61 tables" "XX tables"
--error 1116
select t1.a from t1 as t1 left join t1 as t2 using (a) left join t1 as t3 using (a) left join t1 as t4 using (a) left join t1 as t5 using (a) left join t1 as t6 using (a) left join t1 as t7 using (a) left join t1 as t8 using (a) left join t1 as t9 using (a) left join t1 as t10 using (a) left join t1 as t11 using (a) left join t1 as t12 using (a) left join t1 as t13 using (a) left join t1 as t14 using (a) left join t1 as t15 using (a) left join t1 as t16 using (a) left join t1 as t17 using (a) left join t1 as t18 using (a) left join t1 as t19 using (a) left join t1 as t20 using (a) left join t1 as t21 using (a) left join t1 as t22 using (a) left join t1 as t23 using (a) left join t1 as t24 using (a) left join t1 as t25 using (a) left join t1 as t26 using (a) left join t1 as t27 using (a) left join t1 as t28 using (a) left join t1 as t29 using (a) left join t1 as t30 using (a) left join t1 as t31 using (a) left join t1 as t32 using (a) left join t1 as t33 using (a) left join t1 as t34 using (a) left join t1 as t35 using (a) left join t1 as t36 using (a) left join t1 as t37 using (a) left join t1 as t38 using (a) left join t1 as t39 using (a) left join t1 as t40 using (a) left join t1 as t41 using (a) left join t1 as t42 using (a) left join t1 as t43 using (a) left join t1 as t44 using (a) left join t1 as t45 using (a) left join t1 as t46 using (a) left join t1 as t47 using (a) left join t1 as t48 using (a) left join t1 as t49 using (a) left join t1 as t50 using (a) left join t1 as t51 using (a) left join t1 as t52 using (a) left join t1 as t53 using (a) left join t1 as t54 using (a) left join t1 as t55 using (a) left join t1 as t56 using (a) left join t1 as t57 using (a) left join t1 as t58 using (a) left join t1 as t59 using (a) left join t1 as t60 using (a) left join t1 as t61 using (a) left join t1 as t62 using (a) left join t1 as t63 using (a) left join t1 as t64 using (a) left join t1 as t65 using (a);
select a from t1 as t1 left join t1 as t2 using (a) left join t1 as t3 using (a) left join t1 as t4 using (a) left join t1 as t5 using (a) left join t1 as t6 using (a) left join t1 as t7 using (a) left join t1 as t8 using (a) left join t1 as t9 using (a) left join t1 as t10 using (a) left join t1 as t11 using (a) left join t1 as t12 using (a) left join t1 as t13 using (a) left join t1 as t14 using (a) left join t1 as t15 using (a) left join t1 as t16 using (a) left join t1 as t17 using (a) left join t1 as t18 using (a) left join t1 as t19 using (a) left join t1 as t20 using (a) left join t1 as t21 using (a) left join t1 as t22 using (a) left join t1 as t23 using (a) left join t1 as t24 using (a) left join t1 as t25 using (a) left join t1 as t26 using (a) left join t1 as t27 using (a) left join t1 as t28 using (a) left join t1 as t29 using (a) left join t1 as t30 using (a) left join t1 as t31 using (a) left join t1 as t32 using (a) left join t1 as t33 using (a) left join t1 as t34 using (a) left join t1 as t35 using (a) left join t1 as t36 using (a) left join t1 as t37 using (a) left join t1 as t38 using (a) left join t1 as t39 using (a) left join t1 as t40 using (a) left join t1 as t41 using (a) left join t1 as t42 using (a) left join t1 as t43 using (a) left join t1 as t44 using (a) left join t1 as t45 using (a) left join t1 as t46 using (a) left join t1 as t47 using (a) left join t1 as t48 using (a) left join t1 as t49 using (a) left join t1 as t50 using (a) left join t1 as t51 using (a) left join t1 as t52 using (a) left join t1 as t53 using (a) left join t1 as t54 using (a) left join t1 as t55 using (a) left join t1 as t56 using (a) left join t1 as t57 using (a) left join t1 as t58 using (a) left join t1 as t59 using (a) left join t1 as t60 using (a) left join t1 as t61 using (a) left join t1 as t62 using (a) left join t1 as t63 using (a) left join t1 as t64 using (a) left join t1 as t65 using (a);
drop table t1;
#
@ -144,7 +146,7 @@ DROP TABLE t1, t2;
CREATE TABLE t1 (d DATE NOT NULL);
CREATE TABLE t2 (d DATE NOT NULL);
INSERT INTO t1 (d) VALUES ('2001-08-01'),('0000-00-00');
SELECT * FROM t1 LEFT JOIN t2 USING (d) WHERE t2.d IS NULL;
SELECT * FROM t1 LEFT JOIN t2 USING (d) WHERE d IS NULL;
SELECT * from t1 WHERE t1.d IS NULL;
SELECT * FROM t1 WHERE 1/0 IS NULL;
DROP TABLE t1,t2;
@ -266,8 +268,8 @@ CREATE TABLE t2 (
FULLTEXT KEY rate_code (rate_code)
) ENGINE=MyISAM;
INSERT INTO t2 VALUES ('rivercats','cust',20);
SELECT emp.rate_code, lr.base_rate FROM t1 AS emp LEFT JOIN t2 AS lr USING (siteid, rate_code) WHERE emp.emp_id = 'psmith' AND lr.siteid = 'rivercats';
SELECT emp.rate_code, lr.base_rate FROM t1 AS emp LEFT JOIN t2 AS lr USING (siteid, rate_code) WHERE lr.siteid = 'rivercats' AND emp.emp_id = 'psmith';
SELECT rate_code, lr.base_rate FROM t1 AS emp LEFT JOIN t2 AS lr USING (siteid, rate_code) WHERE emp.emp_id = 'psmith' AND siteid = 'rivercats';
SELECT rate_code, lr.base_rate FROM t1 AS emp LEFT JOIN t2 AS lr USING (siteid, rate_code) WHERE siteid = 'rivercats' AND emp.emp_id = 'psmith';
drop table t1,t2;
#
@ -315,14 +317,14 @@ select * from t3 right join t2 on (t3.i=t2.i);
select * from t3 natural right join t2 natural right join t1;
select * from t3 right join t2 on (t3.i=t2.i) right join t1 on (t2.i=t1.i);
select * from t1,t2 natural left join t3 order by t1.i,t2.i,t3.i;
select * from t1,t2 natural left join t3 order by 1,2;
select * from t1,t2 left join t3 on (t2.i=t3.i) order by t1.i,t2.i,t3.i;
select t1.i,t2.i,t3.i from t2 natural left join t3,t1 order by t1.i,t2.i,t3.i;
select * from t2 natural left join t3,t1 order by t1.i;
select t1.i,t2.i,t3.i from t2 left join t3 on (t2.i=t3.i),t1 order by t1.i,t2.i,t3.i;
select * from t1,t2 natural right join t3 order by t1.i,t2.i,t3.i;
select * from t1,t2 natural right join t3 order by 1,2;
select * from t1,t2 right join t3 on (t2.i=t3.i) order by t1.i,t2.i,t3.i;
select t1.i,t2.i,t3.i from t2 natural right join t3,t1 order by t1.i,t2.i,t3.i;
select * from t2 natural right join t3,t1 order by t1.i;
select t1.i,t2.i,t3.i from t2 right join t3 on (t2.i=t3.i),t1 order by t1.i,t2.i,t3.i;
drop table t1,t2,t3;

View File

@ -92,18 +92,11 @@ select distinct
t1.comments as comments,
sum( t3.amount_received ) + sum( t3.adjustment ) as total_budget
from
t1 ,
t2 as client_period ,
t2 as project_period
left join
t3
on
t3.project_ptr = t1.project_id
and t3.date_received <= '2001-03-22 14:15:09'
left join
t4
on
t4.client_id = t1.client_ptr
t2 as project_period,
t3 left join t1 on (t3.project_ptr = t1.project_id and
t3.date_received <= '2001-03-22 14:15:09')
left join t4 on t4.client_id = t1.client_ptr
where
1
and ( client_period.period_type = 'client_table'

View File

@ -130,15 +130,13 @@ SELECT t8.a,t8.b
EXPLAIN EXTENDED
SELECT t6.a,t6.b,t7.a,t7.b,t8.a,t8.b
FROM t6,
t7
FROM (t6, t7)
LEFT JOIN
t8
ON t7.b=t8.b AND t6.b < 10;
SELECT t6.a,t6.b,t7.a,t7.b,t8.a,t8.b
FROM t6,
t7
FROM (t6, t7)
LEFT JOIN
t8
ON t7.b=t8.b AND t6.b < 10;
@ -150,8 +148,7 @@ SELECT t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b
FROM t5
LEFT JOIN
(
t6,
t7
(t6, t7)
LEFT JOIN
t8
ON t7.b=t8.b AND t6.b < 10
@ -162,8 +159,7 @@ SELECT t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b
FROM t5
LEFT JOIN
(
t6,
t7
(t6, t7)
LEFT JOIN
t8
ON t7.b=t8.b AND t6.b < 10
@ -186,8 +182,7 @@ SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
t5
LEFT JOIN
(
t6,
t7
(t6, t7)
LEFT JOIN
t8
ON t7.b=t8.b AND t6.b < 10
@ -203,8 +198,7 @@ SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
t5
LEFT JOIN
(
t6,
t7
(t6, t7)
LEFT JOIN
t8
ON t7.b=t8.b AND t6.b < 10
@ -228,8 +222,7 @@ SELECT t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
t5
LEFT JOIN
(
t6,
t7
(t6, t7)
LEFT JOIN
t8
ON t7.b=t8.b AND t6.b < 10
@ -252,8 +245,7 @@ SELECT t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
t5
LEFT JOIN
(
t6,
t7
(t6, t7)
LEFT JOIN
t8
ON t7.b=t8.b AND t6.b < 10
@ -281,8 +273,7 @@ SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
t5
LEFT JOIN
(
t6,
t7
(t6, t7)
LEFT JOIN
t8
ON t7.b=t8.b AND t6.b < 10
@ -308,8 +299,7 @@ SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
t5
LEFT JOIN
(
t6,
t7
(t6, t7)
LEFT JOIN
t8
ON t7.b=t8.b AND t6.b < 10
@ -336,8 +326,7 @@ SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
t5
LEFT JOIN
(
t6,
t7
(t6, t7)
LEFT JOIN
t8
ON t7.b=t8.b AND t6.b < 10
@ -375,8 +364,7 @@ SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
t5
LEFT JOIN
(
t6,
t7
(t6, t7)
LEFT JOIN
t8
ON t7.b=t8.b AND t6.b < 10
@ -452,7 +440,7 @@ SELECT t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
WHERE t1.a <= 2;
SELECT t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
FROM t1, t3, t4
FROM t1, (t3, t4)
RIGHT JOIN
t2
ON t3.a=1 AND t2.b=t4.b
@ -460,7 +448,7 @@ SELECT t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
EXPLAIN EXTENDED
SELECT t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
FROM t1, t3, t4
FROM t1, (t3, t4)
RIGHT JOIN
t2
ON t3.a=1 AND t2.b=t4.b
@ -470,13 +458,13 @@ CREATE INDEX idx_b ON t2(b);
EXPLAIN EXTENDED
SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
FROM t3,t4
FROM (t3,t4)
LEFT JOIN
(t1,t2)
ON t3.a=1 AND t3.b=t2.b AND t2.b=t4.b;
SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
FROM t3,t4
FROM (t3,t4)
LEFT JOIN
(t1,t2)
ON t3.a=1 AND t3.b=t2.b AND t2.b=t4.b;
@ -494,8 +482,7 @@ SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
t5
LEFT JOIN
(
t6,
t7
(t6, t7)
LEFT JOIN
t8
ON t7.b=t8.b AND t6.b < 10
@ -534,8 +521,7 @@ SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
t5
LEFT JOIN
(
t6,
t7
(t6, t7)
LEFT JOIN
t8
ON t7.b=t8.b AND t6.b < 10
@ -573,8 +559,7 @@ SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
t5
LEFT JOIN
(
t6,
t7
(t6, t7)
LEFT JOIN
t8
ON t7.b=t8.b AND t6.b < 10
@ -613,8 +598,7 @@ SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
t5
LEFT JOIN
(
t6,
t7
(t6, t7)
LEFT JOIN
t8
ON t7.b=t8.b AND t6.b < 10
@ -649,8 +633,7 @@ SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
t5
LEFT JOIN
(
t6,
t7
(t6, t7)
LEFT JOIN
t8
ON t7.b=t8.b AND t6.b < 10
@ -695,7 +678,7 @@ SELECT t2.a,t2.b,t3.a1,t3.b
FROM t2 LEFT JOIN t3 ON t2.b=t3.b
WHERE t2.a = 4 OR (t2.a > 4 AND t3.a1 IS NULL);
SELECT t2.a,t2.b,t3.a1,t3.b
SELECT *
FROM t2 NATURAL LEFT JOIN t3
WHERE t2.a = 4 OR (t2.a > 4 AND t3.a1 IS NULL);

View File

@ -19,11 +19,11 @@ select t1.*,t2.* from t1 JOIN t2 where t1.a=t2.a;
select t1.*,t2.* from t1 left join t2 on (t1.a=t2.a) order by t1.grp,t1.a,t2.c;
select t1.*,t2.* from { oj t2 left outer join t1 on (t1.a=t2.a) };
select t1.*,t2.* from t1 as t0,{ oj t2 left outer join t1 on (t1.a=t2.a) } WHERE t0.a=2;
select t1.*,t2.* from t1 left join t2 using (a);
select t1.*,t2.* from t1 left join t2 using (a) where t1.a=t2.a;
select t1.*,t2.* from t1 left join t2 using (a,c);
select t1.*,t2.* from t1 left join t2 using (c);
select t1.*,t2.* from t1 natural left outer join t2;
select * from t1 left join t2 using (a);
select t1.*,t2.* from t1 left join t2 on t1.a=t2.a;
select * from t1 left join t2 using (a,c);
select * from t1 left join t2 using (c);
select * from t1 natural left outer join t2;
select t1.*,t2.* from t1 left join t2 on (t1.a=t2.a) where t2.id=3;
select t1.*,t2.* from t1 left join t2 on (t1.a=t2.a) where t2.id is null;
@ -34,19 +34,19 @@ explain select t1.*,t2.* from t1 left join t2 on t1.a=t2.a where isnull(t2.a)=1;
select t1.*,t2.*,t3.a from t1 left join t2 on (t1.a=t2.a) left join t1 as t3 on (t2.a=t3.a);
# The next query should rearange the left joins to get this to work
--error 1120
--error 1054
explain select t1.*,t2.*,t3.a from t1 left join t2 on (t3.a=t2.a) left join t1 as t3 on (t1.a=t3.a);
--error 1120
--error 1054
select t1.*,t2.*,t3.a from t1 left join t2 on (t3.a=t2.a) left join t1 as t3 on (t1.a=t3.a);
# The next query should give an error in MySQL
--error 1120
--error 1054
select t1.*,t2.*,t3.a from t1 left join t2 on (t3.a=t2.a) left join t1 as t3 on (t2.a=t3.a);
# Test of inner join
select t1.*,t2.* from t1 inner join t2 using (a);
select * from t1 inner join t2 using (a);
select t1.*,t2.* from t1 inner join t2 on (t1.a=t2.a);
select t1.*,t2.* from t1 natural join t2;
select * from t1 natural join t2;
drop table t1,t2;
@ -292,7 +292,7 @@ insert into t3 values (1);
insert into t4 values (1,1);
insert into t5 values (1,1);
--error 1120
--error 1054
explain select * from t3 left join t4 on t4.seq_1_id = t2.t2_id left join t1 on t1.t1_id = t4.seq_0_id left join t5 on t5.seq_0_id = t1.t1_id left join t2 on t2.t2_id = t5.seq_1_id where t3.t3_id = 23;
drop table t1,t2,t3,t4,t5;
@ -325,7 +325,7 @@ INSERT INTO t2 VALUES (2,'y');
INSERT INTO t2 VALUES (3,'z');
SELECT t2.id2 FROM t2 LEFT OUTER JOIN t1 ON t1.id2 = t2.id2 WHERE id1 IS NULL;
SELECT t2.id2 FROM t2 NATURAL LEFT OUTER JOIN t1 WHERE id1 IS NULL;
SELECT id2 FROM t2 NATURAL LEFT OUTER JOIN t1 WHERE id1 IS NULL;
drop table t1,t2;
@ -430,8 +430,8 @@ insert into t1 values(1),(2);
insert into t2 values(2),(3);
insert into t3 values(2),(4);
select * from t1 natural left join t2 natural left join t3;
select * from t1 natural left join t2 where (t2.i is not null)=0;
select * from t1 natural left join t2 where (t2.i is not null) is not null;
select * from t1 natural left join t2 where (i is not null)=0;
select * from t1 natural left join t2 where (i is not null) is not null;
drop table t1,t2,t3;
#
@ -440,7 +440,6 @@ drop table t1,t2,t3;
create table t1 (f1 integer,f2 integer,f3 integer);
create table t2 (f2 integer,f4 integer);
create table t3 (f3 integer,f5 integer);
--error 1054
select * from t1
left outer join t2 using (f2)
left outer join t3 using (f3);
@ -657,8 +656,8 @@ create table t1 (a int, b varchar(20));
create table t2 (a int, c varchar(20));
insert into t1 values (1,"aaaaaaaaaa"),(2,"bbbbbbbbbb");
insert into t2 values (1,"cccccccccc"),(2,"dddddddddd");
select group_concat(t1.b,t2.c) from t1 left join t2 using(a) group by t1.a;
select group_concat(t1.b,t2.c) from t1 inner join t2 using(a) group by t1.a;
select group_concat(t1.b,t2.c) from t1 left join t2 using(a) group by a;
select group_concat(t1.b,t2.c) from t1 inner join t2 using(a) group by a;
drop table t1, t2;
set group_concat_max_len=default;

View File

@ -152,12 +152,18 @@ INSERT INTO t1 (order_id, product_id, product_type) VALUES
INSERT INTO t2 (order_id, product_id, product_type) VALUES
('9d9aad7764b5b2c53004348ef8d34500',2315652, 3);
select t1.* from t1
left join t2 using(order_id, product_id, product_type)
where t2.order_id=NULL;
select t1.* from t1
left join t2 using(order_id, product_id, product_type)
select t1.* from t1 left join t2
on (t1.order_id = t2.order_id and
t1.product_id = t2.product_id and
t1.product_type = t2.product_type)
where t2.order_id = NULL;
select t1.* from t1 left join t2
on (t1.order_id = t2.order_id and
t1.product_id = t2.product_id and
t1.product_type = t2.product_type)
where t2.order_id is NULL;
drop table t1,t2;
#

View File

@ -153,12 +153,12 @@ INSERT INTO t3 VALUES (2,'453 Boardwalk');
SELECT a,b,if(b = 1,i,if(b = 2,v,''))
FROM t1
LEFT JOIN t2 USING(c)
LEFT JOIN t2 ON t1.c = t2.c
LEFT JOIN t3 ON t3.c = t1.c;
SELECT a,b,if(b = 1,i,if(b = 2,v,''))
FROM t1
LEFT JOIN t2 USING(c)
LEFT JOIN t2 ON t1.c = t2.c
LEFT JOIN t3 ON t3.c = t1.c
ORDER BY a;
@ -339,8 +339,8 @@ CREATE TABLE t2 (
INSERT INTO t1 (titre,auteur,dest) VALUES ('test','joce','bug');
INSERT INTO t2 (numeropost,pseudo) VALUES (1,'joce'),(1,'bug');
SELECT titre,t1.numeropost,auteur,icone,nbrep,0,date,vue,ouvert,lastauteur,dest FROM t2 LEFT JOIN t1 USING(numeropost) WHERE t2.pseudo='joce' ORDER BY date DESC LIMIT 0,30;
SELECT titre,t1.numeropost,auteur,icone,nbrep,'0',date,vue,ouvert,lastauteur,dest FROM t2 LEFT JOIN t1 USING(numeropost) WHERE t2.pseudo='joce' ORDER BY date DESC LIMIT 0,30;
SELECT titre,numeropost,auteur,icone,nbrep,0,date,vue,ouvert,lastauteur,dest FROM t2 LEFT JOIN t1 USING(numeropost) WHERE t2.pseudo='joce' ORDER BY date DESC LIMIT 0,30;
SELECT titre,numeropost,auteur,icone,nbrep,'0',date,vue,ouvert,lastauteur,dest FROM t2 LEFT JOIN t1 USING(numeropost) WHERE t2.pseudo='joce' ORDER BY date DESC LIMIT 0,30;
drop table t1,t2;
#

View File

@ -1538,22 +1538,22 @@ select t2.fld1,t22.fld1 from t2,t2 t22 where t2.fld1 >= 250501 and t2.fld1 <= 25
#
insert into t2 (fld1, companynr) values (999999,99);
select t2.companynr,companyname from t2 left join t4 using (companynr) where t4.companynr is null;
select count(*) from t2 left join t4 using (companynr) where t4.companynr is not null;
explain select t2.companynr,companyname from t2 left join t4 using (companynr) where t4.companynr is null;
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr is null;
select companynr,companyname from t2 left join t4 using (companynr) where companynr is null;
select count(*) from t2 left join t4 using (companynr) where companynr is not null;
explain select companynr,companyname from t2 left join t4 using (companynr) where companynr is null;
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr is null;
delete from t2 where fld1=999999;
#
# Test left join optimization
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0;
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0;
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 and t4.companynr > 0;
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0;
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0;
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 and companynr > 0;
# Following can't be optimized
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr is null;
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0 or t4.companynr > 0;
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where ifnull(t2.companynr,1)>0;
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr is null;
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0 or companynr > 0;
explain select companynr,companyname from t4 left join t2 using (companynr) where ifnull(companynr,1)>0;
#
# Joins with forms.
@ -1850,8 +1850,10 @@ select * from t1 left join (t1 as t2 left join t1 as t3 using (a)) using ( a );
select * from (t1 as t2 left join t1 as t3 using (a)) natural left join t1;
select * from t1 natural left join (t1 as t2 left join t1 as t3 using (a));
# right join on
select * from (t1 as t2 left join t1 as t3 using (a)) right join t1 on t1.a>1;
select * from t1 right join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;
# TODO: WL#2486 - there is a problem in the order of tables in RIGHT JOIN
# check how we set next_name_resolution_table
# select * from (t1 as t2 left join t1 as t3 using (a)) right join t1 on t1.a>1;
# select * from t1 right join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;
# right [outer] joing using
select * from (t1 as t2 left join t1 as t3 using (a)) right outer join t1 using ( a );
select * from t1 right outer join (t1 as t2 left join t1 as t3 using (a)) using ( a );

View File

@ -78,7 +78,7 @@ select * from (select * from t1) x;
set local max_join_size=1;
--error 1104
select * from (select * from t1 a, t1 b) x;
select * from (select a.a as aa, b.a as ba from t1 a, t1 b) x;
set local max_join_size=1;
--error 1104

View File

@ -696,7 +696,7 @@ CREATE TABLE `t1` (
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+1 WHERE i=(SELECT MAX(i));
-- error 1109
-- error 1054
UPDATE t1 SET t.i=i+(SELECT MAX(i) FROM (SELECT 1) t);
select * from t1;
drop table t1;
@ -1005,7 +1005,7 @@ create table t2 (s1 int);
select * from t1 where (select count(*) from t2 where t1.s2) = 1;
-- error 1054
select * from t1 where (select count(*) from t2 group by t1.s2) = 1;
-- error 1109
-- error 1054
select count(*) from t2 group by t1.s2;
drop table t1, t2;
@ -1132,8 +1132,8 @@ CREATE TABLE t1 (id INT);
CREATE TABLE t2 (id INT);
INSERT INTO t1 VALUES (1), (2);
INSERT INTO t2 VALUES (1);
SELECT t1.id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id);
SELECT t1.id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id) ORDER BY t1.id;
SELECT id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id);
SELECT id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id) ORDER BY id;
DROP TABLE t1,t2;
#
@ -1774,9 +1774,20 @@ SELECT * FROM t1
WHERE ROW(one,two) IN (SELECT DISTINCT one,two FROM t1 WHERE flag = 'N');
insert into t2 values (null,null,'N');
insert into t2 values (null,3,'0');
insert into t2 values (null,5,'0');
insert into t2 values (10,null,'0');
insert into t1 values (10,3,'0');
insert into t1 values (10,5,'0');
insert into t1 values (10,10,'0');
SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N') as 'test' from t1;
SELECT one,two from t1 where ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N');
SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N' group by one,two) as 'test' from t1;
SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0') as 'test' from t1;
SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0' group by one,two) as 'test' from t1;
explain extended SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0') as 'test' from t1;
explain extended SELECT one,two from t1 where ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N');
explain extended SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0' group by one,two) as 'test' from t1;
DROP TABLE t1,t2;
#

View File

@ -157,12 +157,12 @@ create table t1 ( id integer unsigned not null primary key );
create table t2 ( id integer unsigned not null primary key );
insert into t1 values (1), (2);
insert into t2 values (1);
select t1.id as id_A, t2.id as id_B from t1 left join t2 using ( id );
select t1.id as id_A, t2.id as id_B from t1 left join t2 on (t1.id = t2.id);
create table t3 (id_A integer unsigned not null, id_B integer unsigned null );
insert into t3 select t1.id as id_A, t2.id as id_B from t1 left join t2 using ( id );
insert into t3 select t1.id as id_A, t2.id as id_B from t1 left join t2 on (t1.id = t2.id);
select * from t3;
drop table t3;
create table t3 select t1.id as id_A, t2.id as id_B from t1 left join t2 using ( id );
create table t3 select t1.id as id_A, t2.id as id_B from t1 left join t2 on (t1.id = t2.id);
select * from t3;
drop table t1,t2,t3;

View File

@ -276,7 +276,7 @@ create temporary table t1 select a from t1 union select a from t2;
drop temporary table t1;
--error 1093
create table t1 select a from t1 union select a from t2;
--error 1109
--error 1054
select a from t1 union select a from t2 order by t2.a;
drop table t1,t2;

View File

@ -1936,4 +1936,9 @@ SELECT a FROM v1;
DROP VIEW v1;
DROP TABLE t1,t2,t3,t4,t5;
#
# Bug #12298 Typo in function name results in erroneous view being created.
#
create view v1 as select timestampdiff(day,'1997-01-01 00:00:00','1997-01-02 00:00:00') as f1;
select * from v1;
drop view v1;

View File

@ -31,6 +31,9 @@ xa end 'testa','testb';
connect (con1,localhost,,,);
connection con1;
--error 1440
xa start 'testa','testb';
# gtrid [ , bqual [ , formatID ] ]
xa start 0x7465737462, 0x2030405060, 0xb;
insert t1 values (40);
@ -47,6 +50,7 @@ xa prepare 'testa','testb';
xa recover;
--error 1397
xa commit 'testb',0x2030405060,11;
xa rollback 'testa','testb';

View File

@ -2142,7 +2142,7 @@ ha_rows ha_berkeley::records_in_range(uint keynr, key_range *start_key,
end_pos=end_range.less+end_range.equal;
rows=(end_pos-start_pos)*records;
DBUG_PRINT("exit",("rows: %g",rows));
DBUG_RETURN(rows <= 1.0 ? (ha_rows) 1 : (ha_rows) rows);
DBUG_RETURN((ha_rows)(rows <= 1.0 ? 1 : rows));
}

View File

@ -554,19 +554,20 @@ innobase_mysql_end_print_arbitrary_thd(void)
}
/*****************************************************************
Prints info of a THD object (== user session thread) to the
standard output. NOTE that /mysql/innobase/trx/trx0trx.c must contain
the prototype for this function! */
Prints info of a THD object (== user session thread) to the given file.
NOTE that /mysql/innobase/trx/trx0trx.c must contain the prototype for
this function! */
extern "C"
void
innobase_mysql_print_thd(
/*=====================*/
FILE* f, /* in: output stream */
void* input_thd)/* in: pointer to a MySQL THD object */
FILE* f, /* in: output stream */
void* input_thd, /* in: pointer to a MySQL THD object */
uint max_query_len) /* in: max query length to print, or 0 to
use the default max length */
{
const THD* thd;
const char* s;
char buf[301];
thd = (const THD*) input_thd;
@ -593,25 +594,47 @@ innobase_mysql_print_thd(
}
if ((s = thd->query)) {
/* determine the length of the query string */
uint32 i, len;
len = thd->query_length;
/* 3100 is chosen because currently 3000 is the maximum
max_query_len we ever give this. */
char buf[3100];
uint len;
if (len > 300) {
len = 300; /* ADDITIONAL SAFETY: print at most
300 chars to reduce the probability of
a seg fault if there is a race in
thd->query_length in MySQL; after
May 14, 2004 probably no race any more,
but better be safe */
/* If buf is too small, we dynamically allocate storage
in this. */
char* dyn_str = NULL;
/* Points to buf or dyn_str. */
char* str = buf;
if (max_query_len == 0)
{
/* ADDITIONAL SAFETY: the default is to print at
most 300 chars to reduce the probability of a
seg fault if there is a race in
thd->query_length in MySQL; after May 14, 2004
probably no race any more, but better be
safe */
max_query_len = 300;
}
len = min(thd->query_length, max_query_len);
if (len > (sizeof(buf) - 1))
{
dyn_str = my_malloc(len + 1, MYF(0));
str = dyn_str;
}
/* Use strmake to reduce the timeframe
for a race, compared to fwrite() */
i= (uint) (strmake(buf, s, len) - buf);
/* Use strmake to reduce the timeframe for a race,
compared to fwrite() */
len = (uint) (strmake(str, s, len) - str);
putc('\n', f);
fwrite(buf, 1, i, f);
fwrite(str, 1, len, f);
if (dyn_str)
{
my_free(dyn_str, MYF(0));
}
}
putc('\n', f);
@ -7009,7 +7032,7 @@ innobase_xa_prepare(
return(0);
}
trx->xid=thd->transaction.xid;
trx->xid=thd->transaction.xid_state.xid;
/* Release a possible FIFO ticket and search latch. Since we will
reserve the kernel mutex, we have to release the search system latch

View File

@ -547,8 +547,8 @@ void trans_register_ha(THD *thd, bool all, handlerton *ht_arg)
trans->ht[trans->nht++]=ht_arg;
DBUG_ASSERT(*ht == ht_arg);
trans->no_2pc|=(ht_arg->prepare==0);
if (thd->transaction.xid.is_null())
thd->transaction.xid.set(thd->query_id);
if (thd->transaction.xid_state.xid.is_null())
thd->transaction.xid_state.xid.set(thd->query_id);
DBUG_VOID_RETURN;
}
@ -595,7 +595,7 @@ int ha_commit_trans(THD *thd, bool all)
THD_TRANS *trans= all ? &thd->transaction.all : &thd->transaction.stmt;
bool is_real_trans= all || thd->transaction.all.nht == 0;
handlerton **ht= trans->ht;
my_xid xid= thd->transaction.xid.get_my_xid();
my_xid xid= thd->transaction.xid_state.xid.get_my_xid();
DBUG_ENTER("ha_commit_trans");
if (thd->in_sub_stmt)
@ -695,7 +695,7 @@ int ha_commit_one_phase(THD *thd, bool all)
trans->nht=0;
trans->no_2pc=0;
if (is_real_trans)
thd->transaction.xid.null();
thd->transaction.xid_state.xid.null();
if (all)
{
#ifdef HAVE_QUERY_CACHE
@ -751,7 +751,7 @@ int ha_rollback_trans(THD *thd, bool all)
trans->nht=0;
trans->no_2pc=0;
if (is_real_trans)
thd->transaction.xid.null();
thd->transaction.xid_state.xid.null();
if (all)
{
thd->variables.tx_isolation=thd->session_tx_isolation;
@ -945,6 +945,7 @@ int ha_recover(HASH *commit_list)
char buf[XIDDATASIZE*4+6]; // see xid_to_str
sql_print_information("ignore xid %s", xid_to_str(buf, list+i));
#endif
xid_cache_insert(list+i, XA_PREPARED);
found_foreign_xids++;
continue;
}
@ -1008,10 +1009,8 @@ bool mysql_xa_recover(THD *thd)
{
List<Item> field_list;
Protocol *protocol= thd->protocol;
handlerton **ht= handlertons, **end_ht=ht+total_ha;
bool error=TRUE;
int len, got;
XID *list=0;
int i=0;
XID_STATE *xs;
DBUG_ENTER("mysql_xa_recover");
field_list.push_back(new Item_int("formatID",0,11));
@ -1021,48 +1020,30 @@ bool mysql_xa_recover(THD *thd)
if (protocol->send_fields(&field_list,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
DBUG_RETURN(TRUE);
for (len= MAX_XID_LIST_SIZE ; list==0 && len > MIN_XID_LIST_SIZE; len/=2)
{
list=(XID *)my_malloc(len*sizeof(XID), MYF(0));
}
if (!list)
{
my_error(ER_OUTOFMEMORY, MYF(0), len);
DBUG_RETURN(1);
}
for ( ; ht < end_ht ; ht++)
pthread_mutex_lock(&LOCK_xid_cache);
while (xs=(XID_STATE*)hash_element(&xid_cache, i++))
{
if (!(*ht)->recover)
continue;
while ((got=(*(*ht)->recover)(list, len)) > 0 )
if (xs->xa_state==XA_PREPARED)
{
XID *xid, *end;
for (xid=list, end=list+got; xid < end; xid++)
protocol->prepare_for_resend();
protocol->store_longlong((longlong)xs->xid.formatID, FALSE);
protocol->store_longlong((longlong)xs->xid.gtrid_length, FALSE);
protocol->store_longlong((longlong)xs->xid.bqual_length, FALSE);
protocol->store(xs->xid.data, xs->xid.gtrid_length+xs->xid.bqual_length,
&my_charset_bin);
if (protocol->write())
{
if (xid->get_my_xid())
continue; // skip "our" xids
protocol->prepare_for_resend();
protocol->store_longlong((longlong)xid->formatID, FALSE);
protocol->store_longlong((longlong)xid->gtrid_length, FALSE);
protocol->store_longlong((longlong)xid->bqual_length, FALSE);
protocol->store(xid->data, xid->gtrid_length+xid->bqual_length,
&my_charset_bin);
if (protocol->write())
goto err;
pthread_mutex_unlock(&LOCK_xid_cache);
DBUG_RETURN(1);
}
if (got < len)
break;
}
}
error=FALSE;
pthread_mutex_unlock(&LOCK_xid_cache);
send_eof(thd);
err:
my_free((gptr)list, MYF(0));
DBUG_RETURN(error);
DBUG_RETURN(0);
}
/*
@ -1660,7 +1641,7 @@ void handler::print_error(int error, myf errflag)
}
case HA_ERR_NULL_IN_SPATIAL:
textno= ER_UNKNOWN_ERROR;
DBUG_VOID_RETURN;
break;
case HA_ERR_FOUND_DUPP_UNIQUE:
textno=ER_DUP_UNIQUE;
break;
@ -1683,8 +1664,8 @@ void handler::print_error(int error, myf errflag)
textno=ER_CRASHED_ON_REPAIR;
break;
case HA_ERR_OUT_OF_MEM:
my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), errflag);
DBUG_VOID_RETURN;
textno=ER_OUT_OF_RESOURCES;
break;
case HA_ERR_WRONG_COMMAND:
textno=ER_ILLEGAL_HA;
break;
@ -1695,10 +1676,8 @@ void handler::print_error(int error, myf errflag)
textno=ER_UNSUPPORTED_EXTENSION;
break;
case HA_ERR_RECORD_FILE_FULL:
textno=ER_RECORD_FILE_FULL;
break;
case HA_ERR_INDEX_FILE_FULL:
textno= errno;
textno=ER_RECORD_FILE_FULL;
break;
case HA_ERR_LOCK_WAIT_TIMEOUT:
textno=ER_LOCK_WAIT_TIMEOUT;

View File

@ -227,11 +227,11 @@ struct xid_t {
char data[XIDDATASIZE]; // not \0-terminated !
bool eq(struct xid_t *xid)
{ return !memcmp(this, xid, sizeof(long)*3+gtrid_length+bqual_length); }
{ return !memcmp(this, xid, length()); }
bool eq(long g, long b, const char *d)
{ return g == gtrid_length && b == bqual_length && !memcmp(d, data, g+b); }
void set(struct xid_t *xid)
{ memcpy(this, xid, sizeof(long)*3+xid->gtrid_length+xid->bqual_length); }
{ memcpy(this, xid, xid->length()); }
void set(long f, const char *g, long gl, const char *b, long bl)
{
formatID= f;
@ -270,6 +270,11 @@ struct xid_t {
!memcmp(data, MYSQL_XID_PREFIX, MYSQL_XID_PREFIX_LEN) ?
quick_get_my_xid() : 0;
}
uint length()
{
return sizeof(formatID)+sizeof(gtrid_length)+sizeof(bqual_length)+
gtrid_length+bqual_length;
}
};
typedef struct xid_t XID;

View File

@ -3071,7 +3071,9 @@ bool Item_field::fix_fields(THD *thd, Item **reference)
expression to 'reference', i.e. it substitute that expression instead
of this Item_field
*/
if ((from_field= find_field_in_tables(thd, this, context->table_list,
if ((from_field= find_field_in_tables(thd, this,
context->first_name_resolution_table,
context->last_name_resolution_table,
reference,
IGNORE_EXCEPT_NON_UNIQUE,
!any_privileges &&
@ -3080,13 +3082,13 @@ bool Item_field::fix_fields(THD *thd, Item **reference)
not_found_field)
{
/*
If there is an outer contexts (outer selects, but current select is
If there are outer contexts (outer selects, but current select is
not derived table or view) try to resolve this reference in the
outer contexts.
We treat each subselect as a separate namespace, so that different
subselects may contain columns with the same names. The subselects are
searched starting from the innermost.
subselects may contain columns with the same names. The subselects
are searched starting from the innermost.
*/
Name_resolution_context *last_checked_context= context;
Item **ref= (Item **) not_found_item;
@ -3115,7 +3117,10 @@ bool Item_field::fix_fields(THD *thd, Item **reference)
(!select->with_sum_func &&
select->group_list.elements == 0)) &&
(from_field= find_field_in_tables(thd, this,
outer_context->table_list,
outer_context->
first_name_resolution_table,
outer_context->
last_name_resolution_table,
reference,
IGNORE_EXCEPT_NON_UNIQUE,
outer_context->
@ -3190,7 +3195,9 @@ bool Item_field::fix_fields(THD *thd, Item **reference)
else
{
/* Call find_field_in_tables only to report the error */
find_field_in_tables(thd, this, context->table_list,
find_field_in_tables(thd, this,
context->first_name_resolution_table,
context->last_name_resolution_table,
reference, REPORT_ALL_ERRORS,
!any_privileges &&
context->check_privileges, TRUE);
@ -4358,7 +4365,10 @@ bool Item_ref::fix_fields(THD *thd, Item **reference)
expression instead of this Item_ref
*/
from_field= find_field_in_tables(thd, this,
outer_context->table_list,
outer_context->
first_name_resolution_table,
outer_context->
last_name_resolution_table,
reference,
IGNORE_EXCEPT_NON_UNIQUE,
outer_context->check_privileges,
@ -4977,9 +4987,8 @@ void Item_trigger_field::setup_field(THD *thd, TABLE *table)
Try to find field by its name and if it will be found
set field_idx properly.
*/
(void)find_field_in_real_table(thd, table, field_name,
(uint) strlen(field_name),
0, 0, &field_idx);
(void)find_field_in_table(thd, table, field_name, (uint) strlen(field_name),
0, 0, &field_idx);
thd->set_query_id= save_set_query_id;
triggers= table->triggers;
}

View File

@ -254,6 +254,19 @@ struct Name_resolution_context
name resolution of different parts of the statement.
*/
TABLE_LIST *table_list;
/*
In most cases the two table references below replace 'table_list' above
for the purpose of name resolution. The first and last name resolution
table references allow us to search only in a sub-tree of the nested
join tree in a FROM clause. This is needed for NATURAL JOIN, JOIN ... USING
and JOIN ... ON.
*/
TABLE_LIST *first_name_resolution_table;
/*
Last table to search in the list of leaf table references that begins
with first_name_resolution_table.
*/
TABLE_LIST *last_name_resolution_table;
/*
SELECT_LEX item belong to, in case of merged VIEW it can differ from
@ -293,11 +306,13 @@ struct Name_resolution_context
{
resolve_in_select_list= FALSE;
error_processor= &dummy_error_processor;
first_name_resolution_table= NULL;
last_name_resolution_table= NULL;
}
void resolve_in_table_list_only(TABLE_LIST *tables)
{
table_list= tables;
table_list= first_name_resolution_table= tables;
resolve_in_select_list= FALSE;
}
@ -657,7 +672,8 @@ public:
current value and pointer passed via parameter otherwise.
*/
virtual Item **this_item_addr(THD *thd, Item **addr) { return addr; }
virtual Item *this_const_item() const { return const_cast<Item*>(this); } /* For SPs mostly. */
/* For SPs mostly. */
virtual Item *this_const_item() const { return const_cast<Item*>(this); }
// Row emulation
virtual uint cols() { return 1; }
@ -828,6 +844,10 @@ public:
void print(String *str);
virtual bool change_context_processor(byte *cntx)
{ context= (Name_resolution_context *)cntx; return FALSE; }
friend bool insert_fields(THD *thd, Name_resolution_context *context,
const char *db_name,
const char *table_name, List_iterator<Item> *it,
bool any_privileges);
};
class Item_equal;
@ -1129,7 +1149,8 @@ public:
void cleanup() {}
void print(String *str);
Item_num *neg() { value= -value; return this; }
uint decimal_precision() const { return (uint)(max_length - test(value < 0)); }
uint decimal_precision() const
{ return (uint)(max_length - test(value < 0)); }
bool eq(const Item *, bool binary_cmp) const;
};
@ -1566,6 +1587,15 @@ public:
bool val_bool();
bool get_date(TIME *ltime, uint fuzzydate);
void print(String *str);
/*
we add RAND_TABLE_BIT to prevent moving this item from HAVING to WHERE
*/
table_map used_tables() const
{
return (depended_from ?
OUTER_REF_TABLE_BIT :
(*ref)->used_tables() | RAND_TABLE_BIT);
}
};
class Item_null_helper :public Item_ref_null_helper
@ -1647,7 +1677,9 @@ public:
longlong val_int()
{
int err;
return null_value ? LL(0) : my_strntoll(str_value.charset(),str_value.ptr(),str_value.length(),10, (char**) 0,&err);
return null_value ? LL(0) : my_strntoll(str_value.charset(),str_value.ptr(),
str_value.length(),10, (char**) 0,
&err);
}
String *val_str(String*);
my_decimal *val_decimal(my_decimal *);

View File

@ -913,6 +913,11 @@ public:
longlong val_int();
const char *func_name() const { return "<is_not_null_test>"; }
void update_used_tables();
/*
we add RAND_TABLE_BIT to prevent moving this item from HAVING to WHERE
*/
table_map used_tables() const
{ return used_tables_cache | RAND_TABLE_BIT; }
};

View File

@ -1570,6 +1570,7 @@ Item *Item_func_sysconst::safe_charset_converter(CHARSET_INFO *tocs)
return NULL;
}
conv->str_value.copy();
conv->str_value.mark_as_const();
return conv;
}

View File

@ -969,6 +969,7 @@ Item_in_subselect::single_value_transformer(JOIN *join,
argument (reference) to fix_fields()
*/
select_lex->where= join->conds= and_items(join->conds, item);
select_lex->where->top_level_item();
/*
we do not check join->conds->fixed, because Item_and can't be fixed
after creation
@ -1032,8 +1033,12 @@ Item_in_subselect::single_value_transformer(JOIN *join,
Item_subselect::trans_res
Item_in_subselect::row_value_transformer(JOIN *join)
{
Item *item= 0;
SELECT_LEX *select_lex= join->select_lex;
Item *having_item= 0;
uint cols_num= left_expr->cols();
bool is_having_used= (join->having || select_lex->with_sum_func ||
select_lex->group_list.first ||
!select_lex->table_list.elements);
DBUG_ENTER("Item_in_subselect::row_value_transformer");
if (select_lex->item_list.elements != left_expr->cols())
@ -1065,71 +1070,164 @@ Item_in_subselect::row_value_transformer(JOIN *join)
}
select_lex->uncacheable|= UNCACHEABLE_DEPENDENT;
if (is_having_used)
{
uint n= left_expr->cols();
List_iterator_fast<Item> li(select_lex->item_list);
for (uint i= 0; i < n; i++)
/*
(l1, l2, l3) IN (SELECT v1, v2, v3 ... HAVING having) =>
EXISTS (SELECT ... HAVING having and
(l1 = v1 or is null v1) and
(l2 = v2 or is null v2) and
(l3 = v3 or is null v3) and
is_not_null_test(v1) and
is_not_null_test(v2) and
is_not_null_test(v3))
where is_not_null_test used to register nulls in case if we have
not found matching to return correct NULL value
*/
Item *item_having_part2= 0;
for (uint i= 0; i < cols_num; i++)
{
Item *func;
DBUG_ASSERT(left_expr->fixed && select_lex->ref_pointer_array[i]->fixed);
if (select_lex->ref_pointer_array[i]->
check_cols(left_expr->el(i)->cols()))
DBUG_RETURN(RES_ERROR);
if (join->having || select_lex->with_sum_func ||
select_lex->group_list.elements)
func= new Item_ref_null_helper(&select_lex->context,
this,
select_lex->ref_pointer_array+i,
(char *) "<no matter>",
(char *) "<list ref>");
else
func= li++;
func=
eq_creator.create(new Item_direct_ref(&select_lex->context,
(*optimizer->get_cache())->
addr(i),
(char *)"<no matter>",
(char *)in_left_expr_name),
func);
item= and_items(item, func);
Item *item_eq=
new Item_func_eq(new
Item_direct_ref(&select_lex->context,
(*optimizer->get_cache())->
addr(i),
(char *)"<no matter>",
(char *)in_left_expr_name),
new
Item_direct_ref(&select_lex->context,
select_lex->ref_pointer_array + i,
(char *)"<no matter>",
(char *)"<list ref>")
);
Item *item_isnull=
new Item_func_isnull(new
Item_direct_ref(&select_lex->context,
select_lex->
ref_pointer_array+i,
(char *)"<no matter>",
(char *)"<list ref>")
);
having_item=
and_items(having_item,
new Item_cond_or(item_eq, item_isnull));
item_having_part2=
and_items(item_having_part2,
new
Item_is_not_null_test(this,
new
Item_direct_ref(&select_lex->context,
select_lex->
ref_pointer_array + i,
(char *)"<no matter>",
(char *)"<list ref>")
)
);
item_having_part2->top_level_item();
}
}
if (join->having || select_lex->with_sum_func ||
select_lex->group_list.first ||
!select_lex->table_list.elements)
{
/*
AND can't be changed during fix_fields()
we can assign select_lex->having here, and pass 0 as last
argument (reference) to fix_fields()
*/
select_lex->having= join->having= and_items(join->having, item);
select_lex->having_fix_field= 1;
/*
join->having can't be fixed after creation, so we do not check
join->having->fixed
*/
if (join->having->fix_fields(thd, 0))
{
select_lex->having_fix_field= 0;
DBUG_RETURN(RES_ERROR);
}
select_lex->having_fix_field= 0;
having_item= and_items(having_item, item_having_part2);
having_item->top_level_item();
}
else
{
/*
(l1, l2, l3) IN (SELECT v1, v2, v3 ... WHERE where) =>
EXISTS (SELECT ... WHERE where and
(l1 = v1 or is null v1) and
(l2 = v2 or is null v2) and
(l3 = v3 or is null v3)
HAVING is_not_null_test(v1) and
is_not_null_test(v2) and
is_not_null_test(v3))
where is_not_null_test register NULLs values but reject rows
in case when we do not need correct NULL, we have simplier construction:
EXISTS (SELECT ... WHERE where and
(l1 = v1) and
(l2 = v2) and
(l3 = v3)
*/
Item *where_item= 0;
for (uint i= 0; i < cols_num; i++)
{
Item *item, *item_isnull;
DBUG_ASSERT(left_expr->fixed && select_lex->ref_pointer_array[i]->fixed);
if (select_lex->ref_pointer_array[i]->
check_cols(left_expr->el(i)->cols()))
DBUG_RETURN(RES_ERROR);
item=
new Item_func_eq(new
Item_direct_ref(&select_lex->context,
(*optimizer->get_cache())->
addr(i),
(char *)"<no matter>",
(char *)in_left_expr_name),
new
Item_direct_ref(&select_lex->context,
select_lex->
ref_pointer_array+i,
(char *)"<no matter>",
(char *)"<list ref>")
);
if (!abort_on_null)
{
having_item=
and_items(having_item,
new
Item_is_not_null_test(this,
new
Item_direct_ref(&select_lex->context,
select_lex->
ref_pointer_array + i,
(char *)"<no matter>",
(char *)"<list ref>")
)
);
item_isnull= new
Item_func_isnull(new
Item_direct_ref(&select_lex->context,
select_lex->
ref_pointer_array+i,
(char *)"<no matter>",
(char *)"<list ref>")
);
item= new Item_cond_or(item, item_isnull);
}
where_item= and_items(where_item, item);
}
/*
AND can't be changed during fix_fields()
we can assign select_lex->where here, and pass 0 as last
argument (reference) to fix_fields()
*/
select_lex->where= join->conds= and_items(join->conds, where_item);
select_lex->where->top_level_item();
if (join->conds->fix_fields(thd, 0))
DBUG_RETURN(RES_ERROR);
}
if (having_item)
{
bool res;
select_lex->having= join->having= and_items(join->having, having_item);
select_lex->having->top_level_item();
/*
AND can't be changed during fix_fields()
we can assign select_lex->having here, and pass 0 as last
argument (reference) to fix_fields()
*/
select_lex->where= join->conds= and_items(join->conds, item);
/*
join->conds can't be fixed after creation, so we do not check
join->conds->fixed
*/
if (join->conds->fix_fields(thd, 0))
select_lex->having_fix_field= 1;
res= join->having->fix_fields(thd, 0);
select_lex->having_fix_field= 0;
if (res)
{
DBUG_RETURN(RES_ERROR);
}
}
DBUG_RETURN(RES_OK);

View File

@ -860,7 +860,7 @@ class Item_func_timestamp_diff :public Item_int_func
public:
Item_func_timestamp_diff(Item *a,Item *b,interval_type type_arg)
:Item_int_func(a,b), int_type(type_arg) {}
const char *func_name() const { return "timestamp_diff"; }
const char *func_name() const { return "timestampdiff"; }
longlong val_int();
void fix_length_and_dec()
{

View File

@ -393,6 +393,10 @@ struct sql_ex_info
#define OPTIONS_WRITTEN_TO_BIN_LOG (OPTION_AUTO_IS_NULL | \
OPTION_NO_FOREIGN_KEY_CHECKS | OPTION_RELAXED_UNIQUE_CHECKS)
#if OPTIONS_WRITTEN_TO_BIN_LOG != ((1L << 14) | (1L << 26) | (1L << 27))
#error OPTIONS_WRITTEN_TO_BIN_LOG must NOT change their values!
#endif
enum Log_event_type
{
/*

View File

@ -765,23 +765,24 @@ extern Field *view_ref_found;
enum find_item_error_report_type {REPORT_ALL_ERRORS, REPORT_EXCEPT_NOT_FOUND,
IGNORE_ERRORS, REPORT_EXCEPT_NON_UNIQUE,
IGNORE_EXCEPT_NON_UNIQUE};
Field *find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables,
Item **ref,
find_item_error_report_type report_error,
bool check_privileges,
bool register_tree_change);
Field *
find_field_in_table(THD *thd, TABLE_LIST *table_list,
const char *name, const char *item_name,
uint length, Item **ref,
bool check_grants_table, bool check_grants_view,
bool allow_rowid,
uint *cached_field_index_ptr,
bool register_tree_change);
find_field_in_tables(THD *thd, Item_ident *item,
TABLE_LIST *first_table, TABLE_LIST *last_table,
Item **ref, find_item_error_report_type report_error,
bool check_privileges, bool register_tree_change);
Field *
find_field_in_real_table(THD *thd, TABLE *table, const char *name,
uint length, bool check_grants, bool allow_rowid,
uint *cached_field_index_ptr);
find_field_in_table_ref(THD *thd, TABLE_LIST *table_list,
const char *name, const char *item_name,
const char *table_name, const char *db_name,
uint length, Item **ref,
bool check_grants_table, bool check_grants_view,
bool allow_rowid,
uint *cached_field_index_ptr,
bool register_tree_change, TABLE_LIST **actual_table);
Field *
find_field_in_table(THD *thd, TABLE *table, const char *name,
uint length, bool check_grants, bool allow_rowid,
uint *cached_field_index_ptr);
#ifdef HAVE_OPENSSL
#include <openssl/des.h>
struct st_des_keyblock
@ -888,8 +889,10 @@ create_field * new_create_field(THD *thd, char *field_name, enum_field_types typ
uint uint_geom_type);
void store_position_for_column(const char *name);
bool add_to_list(THD *thd, SQL_LIST &list,Item *group,bool asc);
Name_resolution_context *make_join_on_context(THD *thd, TABLE_LIST *left_op,
TABLE_LIST *right_op);
void add_join_on(TABLE_LIST *b,Item *expr);
void add_join_natural(TABLE_LIST *a,TABLE_LIST *b);
void add_join_natural(TABLE_LIST *a,TABLE_LIST *b,List<String> *using_fields);
bool add_proc_to_list(THD *thd, Item *item);
TABLE *unlink_open_table(THD *thd,TABLE *list,TABLE *find);
@ -906,8 +909,8 @@ bool insert_fields(THD *thd, Name_resolution_context *context,
const char *db_name, const char *table_name,
List_iterator<Item> *it, bool any_privileges);
bool setup_tables(THD *thd, Name_resolution_context *context,
TABLE_LIST *tables, Item **conds,
TABLE_LIST **leaves, bool select_insert);
List<TABLE_LIST> *from_clause, TABLE_LIST *tables,
Item **conds, TABLE_LIST **leaves, bool select_insert);
int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields,
List<Item> *sum_func_list, uint wild_num);
bool setup_fields(THD *thd, Item** ref_pointer_array,

View File

@ -1050,6 +1050,7 @@ void clean_up(bool print_message)
(void) ha_panic(HA_PANIC_CLOSE); /* close all tables and logs */
if (tc_log)
tc_log->close();
xid_cache_free();
delete_elements(&key_caches, (void (*)(const char*, gptr)) free_key_cache);
multi_keycache_free();
end_thr_alarm(1); /* Free allocated memory */
@ -2922,6 +2923,11 @@ server.");
using_update_log=1;
}
if (xid_cache_init())
{
sql_print_error("Out of memory");
unireg_abort(1);
}
if (ha_init())
{
sql_print_error("Can't init databases");

View File

@ -5393,3 +5393,5 @@ ER_WARN_CANT_DROP_DEFAULT_KEYCACHE
ger "Der Default-Keycache kann nicht gelöscht werden"
ER_TOO_BIG_DISPLAYWIDTH 42000 S1009
eng "Display width out of range for column '%-.64s' (max = %d)"
ER_XAER_DUPID XAE08
eng "XAER_DUPID: The XID already exists"

View File

@ -789,6 +789,7 @@ db_show_routine_status(THD *thd, int type, const char *wild)
*/
thd->lex->select_lex.context.resolve_in_table_list_only(&tables);
setup_tables(thd, &thd->lex->select_lex.context,
&thd->lex->select_lex.top_join_list,
&tables, 0, &leaves, FALSE);
for (used_field= &used_fields[0];
used_field->field_name;
@ -798,7 +799,7 @@ db_show_routine_status(THD *thd, int type, const char *wild)
"mysql", "proc",
used_field->field_name);
if (!field ||
!(used_field->field= find_field_in_tables(thd, field, &tables,
!(used_field->field= find_field_in_tables(thd, field, &tables, NULL,
0, REPORT_ALL_ERRORS, 1,
TRUE)))
{

View File

@ -2638,10 +2638,11 @@ bool mysql_table_grant(THD *thd, TABLE_LIST *table_list,
while ((column = column_iter++))
{
uint unused_field_idx= NO_CACHED_FIELD_INDEX;
Field *f=find_field_in_table(thd, table_list, column->column.ptr(),
column->column.ptr(),
column->column.length(), 0, 1, 1, 0,
&unused_field_idx, FALSE);
TABLE_LIST *dummy;
Field *f=find_field_in_table_ref(thd, table_list, column->column.ptr(),
column->column.ptr(), NULL, NULL,
column->column.length(), 0, 1, 1, 0,
&unused_field_idx, FALSE, &dummy);
if (f == (Field*)0)
{
my_error(ER_BAD_FIELD_ERROR, MYF(0),
@ -3695,6 +3696,24 @@ ulong get_table_grant(THD *thd, TABLE_LIST *table)
}
/*
Determine the access priviliges for a field.
SYNOPSIS
get_column_grant()
thd thread handler
grant grants table descriptor
db_name name of database that the field belongs to
table_name name of table that the field belongs to
field_name name of field
DESCRIPTION
The procedure may also modify: grant->grant_table and grant->version.
RETURN
The access priviliges for the field db_name.table_name.field_name
*/
ulong get_column_grant(THD *thd, GRANT_INFO *grant,
const char *db_name, const char *table_name,
const char *field_name)

File diff suppressed because it is too large Load Diff

View File

@ -323,7 +323,8 @@ void THD::init_for_queries()
variables.trans_alloc_block_size,
variables.trans_prealloc_size);
#endif
transaction.xid.null();
transaction.xid_state.xid.null();
transaction.xid_state.in_thd=1;
}
@ -358,9 +359,15 @@ void THD::cleanup(void)
{
DBUG_ENTER("THD::cleanup");
#ifdef ENABLE_WHEN_BINLOG_WILL_BE_ABLE_TO_PREPARE
if (transaction.xa_state != XA_PREPARED)
if (transaction.xid_state.xa_state == XA_PREPARED)
{
#error xid_state in the cache should be replaced by the allocated value
}
#endif
{
ha_rollback(this);
xid_cache_delete(&transaction.xid_state);
}
if (locked_tables)
{
lock=locked_tables; locked_tables=0;
@ -1838,6 +1845,7 @@ void THD::restore_backup_open_tables_state(Open_tables_state *backup)
}
/****************************************************************************
Handling of statement states in functions and triggers.
@ -1918,3 +1926,89 @@ void THD::restore_sub_statement_state(Sub_statement_state *backup)
examined_row_count+= backup->examined_row_count;
cuted_fields+= backup->cuted_fields;
}
/***************************************************************************
Handling of XA id cacheing
***************************************************************************/
pthread_mutex_t LOCK_xid_cache;
HASH xid_cache;
static byte *xid_get_hash_key(const byte *ptr,uint *length,
my_bool not_used __attribute__((unused)))
{
*length=((XID_STATE*)ptr)->xid.length();
return (byte *)&((XID_STATE*)ptr)->xid;
}
static void xid_free_hash (void *ptr)
{
if (!((XID_STATE*)ptr)->in_thd)
my_free((byte *)ptr, MYF(0));
}
bool xid_cache_init()
{
pthread_mutex_init(&LOCK_xid_cache, MY_MUTEX_INIT_FAST);
return hash_init(&xid_cache, &my_charset_bin, 100, 0, 0,
xid_get_hash_key, xid_free_hash, 0) != 0;
}
void xid_cache_free()
{
if (hash_inited(&xid_cache))
{
hash_free(&xid_cache);
pthread_mutex_destroy(&LOCK_xid_cache);
}
}
XID_STATE *xid_cache_search(XID *xid)
{
pthread_mutex_lock(&LOCK_xid_cache);
XID_STATE *res=(XID_STATE *)hash_search(&xid_cache, (byte *)xid, xid->length());
pthread_mutex_unlock(&LOCK_xid_cache);
return res;
}
bool xid_cache_insert(XID *xid, enum xa_states xa_state)
{
XID_STATE *xs;
my_bool res;
pthread_mutex_lock(&LOCK_xid_cache);
if (hash_search(&xid_cache, (byte *)xid, xid->length()))
res=0;
else if (!(xs=(XID_STATE *)my_malloc(sizeof(*xs), MYF(MY_WME))))
res=1;
else
{
xs->xa_state=xa_state;
xs->xid.set(xid);
xs->in_thd=0;
res=my_hash_insert(&xid_cache, (byte*)xs);
}
pthread_mutex_unlock(&LOCK_xid_cache);
return res;
}
bool xid_cache_insert(XID_STATE *xid_state)
{
pthread_mutex_lock(&LOCK_xid_cache);
DBUG_ASSERT(hash_search(&xid_cache, (byte *)&xid_state->xid,
xid_state->xid.length())==0);
my_bool res=my_hash_insert(&xid_cache, (byte*)xid_state);
pthread_mutex_unlock(&LOCK_xid_cache);
return res;
}
void xid_cache_delete(XID_STATE *xid_state)
{
pthread_mutex_lock(&LOCK_xid_cache);
hash_delete(&xid_cache, (byte *)xid_state);
pthread_mutex_unlock(&LOCK_xid_cache);
}

View File

@ -351,8 +351,6 @@ public:
inline uint32 get_open_count() { return open_count; }
};
/* character conversion tables */
typedef struct st_copy_info {
ha_rows records;
@ -564,11 +562,11 @@ struct system_variables
my_bool ndb_use_transactions;
#endif /* HAVE_NDBCLUSTER_DB */
my_bool old_passwords;
/* Only charset part of these variables is sensible */
CHARSET_INFO *character_set_client;
CHARSET_INFO *character_set_client;
CHARSET_INFO *character_set_results;
/* Both charset and collation parts of these variables are important */
CHARSET_INFO *collation_server;
CHARSET_INFO *collation_database;
@ -631,7 +629,7 @@ typedef struct system_status_var
ulong filesort_range_count;
ulong filesort_rows;
ulong filesort_scan_count;
/* Ppepared statements and binary protocol */
/* Prepared statements and binary protocol */
ulong com_stmt_prepare;
ulong com_stmt_execute;
ulong com_stmt_send_long_data;
@ -656,8 +654,8 @@ void free_tmp_table(THD *thd, TABLE *entry);
/* The following macro is to make init of Query_arena simpler */
#ifndef DBUG_OFF
#define INIT_ARENA_DBUG_INFO is_backup_arena= 0
#else
#define INIT_ARENA_DBUG_INFO
#else
#define INIT_ARENA_DBUG_INFO
#endif
@ -925,6 +923,22 @@ struct st_savepoint {
enum xa_states {XA_NOTR=0, XA_ACTIVE, XA_IDLE, XA_PREPARED};
extern const char *xa_state_names[];
typedef struct st_xid_state {
/* For now, this is only used to catch duplicated external xids */
XID xid; // transaction identifier
enum xa_states xa_state; // used by external XA only
bool in_thd;
} XID_STATE;
extern pthread_mutex_t LOCK_xid_cache;
extern HASH xid_cache;
bool xid_cache_init(void);
void xid_cache_free(void);
XID_STATE *xid_cache_search(XID *xid);
bool xid_cache_insert(XID *xid, enum xa_states xa_state);
bool xid_cache_insert(XID_STATE *xid_state);
void xid_cache_delete(XID_STATE *xid_state);
/*
A registry for item tree transformations performed during
query optimization. We register only those changes which require
@ -946,7 +960,7 @@ enum prelocked_mode_type {NON_PRELOCKED= 0, PRELOCKED= 1,
/*
Class that holds information about tables which were open and locked
Class that holds information about tables which were opened and locked
by the thread. It is also used to save/restore this information in
push_open_tables_state()/pop_open_tables_state().
*/
@ -1089,7 +1103,7 @@ public:
// the lock_id of a cursor.
pthread_mutex_t LOCK_delete; // Locked before thd is deleted
/* all prepared statements and cursors of this connection */
Statement_map stmt_map;
Statement_map stmt_map;
/*
A pointer to the stack frame of handle_one_connection(),
which is called first in the thread for handling a client
@ -1158,10 +1172,10 @@ public:
time_t connect_time,thr_create_time; // track down slow pthread_create
thr_lock_type update_lock_default;
delayed_insert *di;
/* <> 0 if we are inside of trigger or stored function. */
uint in_sub_stmt;
/* container for handler's private per-connection data */
void *ha_data[MAX_HA];
struct st_transactions {
@ -1169,8 +1183,7 @@ public:
THD_TRANS all; // Trans since BEGIN WORK
THD_TRANS stmt; // Trans for current statement
bool on; // see ha_enable_transaction()
XID xid; // transaction identifier
enum xa_states xa_state; // used by external XA only
XID_STATE xid_state;
/*
Tables changed in transaction (that must be invalidated in query cache).
List contain only transactional tables, that not invalidated in query
@ -1190,7 +1203,7 @@ public:
st_transactions()
{
bzero((char*)this, sizeof(*this));
xid.null();
xid_state.xid.null();
init_sql_alloc(&mem_root, ALLOC_ROOT_MIN_BLOCK_SIZE, 0);
}
#endif
@ -1247,6 +1260,12 @@ public:
longlong row_count_func; /* For the ROW_COUNT() function */
ha_rows cuted_fields,
sent_row_count, examined_row_count;
/*
The set of those tables whose fields are referenced in all subqueries
of the query.
TODO: possibly this it is incorrect to have used tables in THD because
with more than one subquery, it is not clear what does the field mean.
*/
table_map used_tables;
USER_CONN *user_connect;
CHARSET_INFO *db_charset;

View File

@ -301,6 +301,7 @@ bool mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds)
DBUG_ENTER("mysql_prepare_delete");
if (setup_tables(thd, &thd->lex->select_lex.context,
&thd->lex->select_lex.top_join_list,
table_list, conds, &select_lex->leaf_tables,
FALSE) ||
setup_conds(thd, table_list, select_lex->leaf_tables, conds) ||
@ -359,6 +360,7 @@ bool mysql_multi_delete_prepare(THD *thd)
lex->query_tables also point on local list of DELETE SELECT_LEX
*/
if (setup_tables(thd, &thd->lex->select_lex.context,
&thd->lex->select_lex.top_join_list,
lex->query_tables, &lex->select_lex.where,
&lex->select_lex.leaf_tables, FALSE))
DBUG_RETURN(TRUE);

View File

@ -125,6 +125,11 @@ int mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *orig_table_list)
if ((res= unit->prepare(thd, derived_result, 0, orig_table_list->alias)))
goto exit;
if (check_duplicate_names(unit->types, 0))
{
res= -1;
goto exit;
}
derived_result->tmp_table_param.init();
derived_result->tmp_table_param.field_count= unit->types.elements;

View File

@ -75,7 +75,7 @@ enum enum_used_fields
RETURN VALUES
0 all ok
1 one of the fileds didn't finded
1 one of the fileds was not found
*/
static bool init_fields(THD *thd, TABLE_LIST *tables,
@ -90,7 +90,7 @@ static bool init_fields(THD *thd, TABLE_LIST *tables,
Item_field *field= new Item_field(context,
"mysql", find_fields->table_name,
find_fields->field_name);
if (!(find_fields->field= find_field_in_tables(thd, field, tables,
if (!(find_fields->field= find_field_in_tables(thd, field, tables, NULL,
0, REPORT_ALL_ERRORS, 1,
TRUE)))
DBUG_RETURN(1);
@ -631,12 +631,15 @@ bool mysqld_help(THD *thd, const char *mask)
tables[0].alias= tables[0].table_name= (char*) "help_topic";
tables[0].lock_type= TL_READ;
tables[0].next_global= tables[0].next_local= &tables[1];
tables[0].next_name_resolution_table= tables[0].next_local;
tables[1].alias= tables[1].table_name= (char*) "help_category";
tables[1].lock_type= TL_READ;
tables[1].next_global= tables[1].next_local= &tables[2];
tables[1].next_name_resolution_table= tables[1].next_local;
tables[2].alias= tables[2].table_name= (char*) "help_relation";
tables[2].lock_type= TL_READ;
tables[2].next_global= tables[2].next_local= &tables[3];
tables[2].next_name_resolution_table= tables[2].next_local;
tables[3].alias= tables[3].table_name= (char*) "help_keyword";
tables[3].lock_type= TL_READ;
tables[0].db= tables[1].db= tables[2].db= tables[3].db= (char*) "mysql";
@ -655,6 +658,7 @@ bool mysqld_help(THD *thd, const char *mask)
tables do not contain VIEWs => we can pass 0 as conds
*/
setup_tables(thd, &thd->lex->select_lex.context,
&thd->lex->select_lex.top_join_list,
tables, 0, &leaves, FALSE);
memcpy((char*) used_fields, (char*) init_used_fields, sizeof(used_fields));
if (init_fields(thd, tables, used_fields, array_elements(used_fields)))

View File

@ -106,12 +106,15 @@ static int check_insert_fields(THD *thd, TABLE_LIST *table_list,
}
else
{ // Part field list
Name_resolution_context *context= &thd->lex->select_lex.context;
TABLE_LIST *save_next= table_list->next_local,
*save_context= context->table_list;
bool save_resolve_in_select_list=
thd->lex->select_lex.context.resolve_in_select_list;
SELECT_LEX *select_lex= &thd->lex->select_lex;
Name_resolution_context *context= &select_lex->context;
TABLE_LIST *save_next_local;
TABLE_LIST *save_table_list;
TABLE_LIST *save_first_name_resolution_table;
TABLE_LIST *save_next_name_resolution_table;
bool save_resolve_in_select_list;
int res;
if (fields.elements != values.elements)
{
my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0), 1L);
@ -119,17 +122,39 @@ static int check_insert_fields(THD *thd, TABLE_LIST *table_list,
}
thd->dupp_field=0;
thd->lex->select_lex.no_wrap_view_item= TRUE;
/* fields only from first table */
select_lex->no_wrap_view_item= TRUE;
/* Save the state of the current name resolution context. */
save_table_list= context->table_list;
save_first_name_resolution_table= context->first_name_resolution_table;
save_next_name_resolution_table= (context->first_name_resolution_table) ?
context->first_name_resolution_table->
next_name_resolution_table :
NULL;
save_resolve_in_select_list= context->resolve_in_select_list;
save_next_local= table_list->next_local;
/*
Perform name resolution only in the first table - 'table_list',
which is the table that is inserted into.
*/
table_list->next_local= 0;
context->resolve_in_table_list_only(table_list);
res= setup_fields(thd, 0, fields, 1, 0, 0);
table_list->next_local= save_next;
/* Restore the current context. */
table_list->next_local= save_next_local;
context->table_list= save_table_list;
context->first_name_resolution_table= save_first_name_resolution_table;
if (context->first_name_resolution_table)
context->first_name_resolution_table->
next_name_resolution_table= save_next_name_resolution_table;
context->resolve_in_select_list= save_resolve_in_select_list;
thd->lex->select_lex.no_wrap_view_item= FALSE;
context->table_list= save_context;
context->resolve_in_select_list= save_resolve_in_select_list;
if (res)
return -1;
if (table_list->effective_algorithm == VIEW_ALGORITHM_MERGE)
{
/* it is join view => we need to find table for update */
@ -254,9 +279,13 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
ulonglong id;
COPY_INFO info;
TABLE *table= 0;
TABLE_LIST *next_local;
TABLE_LIST *save_table_list;
TABLE_LIST *save_next_local;
TABLE_LIST *save_first_name_resolution_table;
TABLE_LIST *save_next_name_resolution_table;
List_iterator_fast<List_item> its(values_list);
List_item *values;
Name_resolution_context *context;
#ifndef EMBEDDED_LIBRARY
char *query= thd->query;
#endif
@ -335,9 +364,23 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
/* mysql_prepare_insert set table_list->table if it was not set */
table= table_list->table;
next_local= table_list->next_local;
context= &thd->lex->select_lex.context;
/* Save the state of the current name resolution context. */
save_table_list= context->table_list;
save_first_name_resolution_table= context->first_name_resolution_table;
save_next_name_resolution_table= (context->first_name_resolution_table) ?
context->first_name_resolution_table->
next_name_resolution_table :
NULL;
save_next_local= table_list->next_local;
/*
Perform name resolution only in the first table - 'table_list',
which is the table that is inserted into.
*/
table_list->next_local= 0;
thd->lex->select_lex.context.resolve_in_table_list_only(table_list);
context->resolve_in_table_list_only(table_list);
value_count= values->elements;
while ((values= its++))
{
@ -351,7 +394,14 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
goto abort;
}
its.rewind ();
table_list->next_local= next_local;
/* Restore the current context. */
table_list->next_local= save_next_local;
context->first_name_resolution_table= save_first_name_resolution_table;
if (context->first_name_resolution_table)
context->first_name_resolution_table->
next_name_resolution_table= save_next_name_resolution_table;
/*
Fill in the given fields and dump it to the table file
*/
@ -707,6 +757,7 @@ static bool mysql_prepare_insert_check_table(THD *thd, TABLE_LIST *table_list,
DBUG_ENTER("mysql_prepare_insert_check_table");
if (setup_tables(thd, &thd->lex->select_lex.context,
&thd->lex->select_lex.top_join_list,
table_list, where, &thd->lex->select_lex.leaf_tables,
select_insert))
DBUG_RETURN(TRUE);
@ -761,10 +812,13 @@ bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list,
COND **where, bool select_insert)
{
SELECT_LEX *select_lex= &thd->lex->select_lex;
Name_resolution_context *context= &select_lex->context;
TABLE_LIST *save_table_list;
TABLE_LIST *save_next_local;
TABLE_LIST *save_first_name_resolution_table;
TABLE_LIST *save_next_name_resolution_table;
bool save_resolve_in_select_list;
bool insert_into_view= (table_list->view != 0);
bool save_resolve_in_select_list;
bool res= 0;
DBUG_ENTER("mysql_prepare_insert");
DBUG_PRINT("enter", ("table_list 0x%lx, table 0x%lx, view %d",
@ -802,35 +856,57 @@ bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list,
select_insert))
DBUG_RETURN(TRUE);
save_table_list= select_lex->context.table_list;
save_resolve_in_select_list= select_lex->context.resolve_in_select_list;
save_next_local= table_list->next_local;
/* Save the state of the current name resolution context. */
save_table_list= context->table_list;
/* Here first_name_resolution_table points to the first select table. */
save_first_name_resolution_table= context->first_name_resolution_table;
save_next_name_resolution_table= (context->first_name_resolution_table) ?
context->first_name_resolution_table->
next_name_resolution_table :
NULL;
save_resolve_in_select_list= context->resolve_in_select_list;
save_next_local= table_list->next_local;
/*
Perform name resolution only in the first table - 'table_list',
which is the table that is inserted into.
*/
table_list->next_local= 0;
select_lex->context.resolve_in_table_list_only(table_list);
context->resolve_in_table_list_only(table_list);
/* Prepare the fields in the statement. */
if (values &&
!(res= check_insert_fields(thd, table_list, fields, *values,
!insert_into_view) ||
setup_fields(thd, 0, *values, 0, 0, 0)) &&
!(res= check_insert_fields(thd, context->table_list, fields, *values,
!insert_into_view) ||
setup_fields(thd, 0, *values, 0, 0, 0)) &&
duplic == DUP_UPDATE)
{
select_lex->no_wrap_view_item= TRUE;
res= check_update_fields(thd, table_list, update_fields);
res= check_update_fields(thd, context->table_list, update_fields);
select_lex->no_wrap_view_item= FALSE;
/*
When we are not using GROUP BY we can refer to other tables in the
ON DUPLICATE KEY part.
*/
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;
context->table_list->next_local= save_next_local;
context->first_name_resolution_table->
next_name_resolution_table= save_next_local;
}
if (!res)
res= setup_fields(thd, 0, update_values, 1, 0, 0);
}
/* Restore the current context. */
table_list->next_local= save_next_local;
select_lex->context.table_list= save_table_list;
select_lex->context.resolve_in_select_list= save_resolve_in_select_list;
context->table_list= save_table_list;
context->first_name_resolution_table= save_first_name_resolution_table;
if (context->first_name_resolution_table)
context->first_name_resolution_table->
next_name_resolution_table= save_next_name_resolution_table;
context->resolve_in_select_list= save_resolve_in_select_list;
if (res)
DBUG_RETURN(res);
@ -2091,24 +2167,52 @@ select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
res= check_insert_fields(thd, table_list, *fields, values,
!insert_into_view) ||
setup_fields(thd, 0, values, 0, 0, 0);
if (info.handle_duplicates == DUP_UPDATE)
{
TABLE_LIST *save_next_local= table_list->next_local;
table_list->next_local= 0;
lex->select_lex.context.resolve_in_table_list_only(table_list);
lex->select_lex.no_wrap_view_item= TRUE;
res= res || check_update_fields(thd, table_list, *info.update_fields);
lex->select_lex.no_wrap_view_item= FALSE;
/* Save the state of the current name resolution context. */
Name_resolution_context *context= &lex->select_lex.context;
TABLE_LIST *save_table_list;
TABLE_LIST *save_next_local;
TABLE_LIST *save_first_name_resolution_table;
TABLE_LIST *save_next_name_resolution_table;
save_table_list= context->table_list;
save_first_name_resolution_table= context->first_name_resolution_table;
save_next_name_resolution_table= (context->first_name_resolution_table) ?
context->first_name_resolution_table->
next_name_resolution_table :
NULL;
save_next_local= table_list->next_local;
/* Perform name resolution only in the first table - 'table_list'. */
table_list->next_local= 0;
context->resolve_in_table_list_only(table_list);
lex->select_lex.no_wrap_view_item= TRUE;
res= res || check_update_fields(thd, context->table_list,
*info.update_fields);
lex->select_lex.no_wrap_view_item= FALSE;
/*
When we are not using GROUP BY we can refer to other tables in the
ON DUPLICATE KEY part
*/
if (!lex->select_lex.group_list.elements)
table_list->next_local= save_next_local;
if (lex->select_lex.group_list.elements == 0)
{
context->table_list->next_local= save_next_local;
context->first_name_resolution_table->
next_name_resolution_table= save_next_local;
}
res= res || setup_fields(thd, 0, *info.update_values, 1, 0, 0);
/* Restore the current context. */
table_list->next_local= save_next_local;
context->first_name_resolution_table= save_first_name_resolution_table;
if (context->first_name_resolution_table)
context->first_name_resolution_table->
next_name_resolution_table= save_next_name_resolution_table;
}
lex->current_select= lex_current_select_save;
if (res)
DBUG_RETURN(1);

View File

@ -118,8 +118,11 @@ void lex_start(THD *thd, uchar *buf,uint length)
lex->buf= lex->ptr= buf;
lex->end_of_query= buf+length;
lex->context_stack.empty();
lex->unit.init_query();
lex->unit.init_select();
/* 'parent_lex' is used in init_query() so it must be before it. */
lex->select_lex.parent_lex= lex;
lex->select_lex.init_query();
lex->value_list.empty();
lex->update_list.empty();
@ -148,7 +151,6 @@ void lex_start(THD *thd, uchar *buf,uint length)
lex->leaf_tables_insert= lex->query_tables= 0;
lex->query_tables_last= &lex->query_tables;
lex->variables_used= 0;
lex->select_lex.parent_lex= lex;
lex->empty_field_list_on_rset= 0;
lex->select_lex.select_number= 1;
lex->next_state=MY_LEX_START;
@ -1114,6 +1116,11 @@ void st_select_lex::init_query()
having_fix_field= 0;
context.select_lex= this;
context.init();
/*
Add the name resolution context of the current (sub)query to the
stack of contexts for the whole query.
*/
parent_lex->push_context(&context);
cond_count= with_wild= 0;
conds_processed_with_permanent_arena= 0;
ref_pointer_array= 0;
@ -1130,7 +1137,7 @@ void st_select_lex::init_select()
{
st_select_lex_node::init_select();
group_list.empty();
type= db= db1= table1= db2= table2= 0;
type= db= 0;
having= 0;
use_index_ptr= ignore_index_ptr= 0;
table_join_options= 0;
@ -1860,8 +1867,9 @@ TABLE_LIST *st_lex::unlink_first_table(bool *link_to_local)
*/
if ((*link_to_local= test(select_lex.table_list.first)))
{
select_lex.table_list.first= (byte*) (select_lex.context.table_list=
first->next_local);
select_lex.context.table_list= first->next_local;
select_lex.context.first_name_resolution_table= first->next_local;
select_lex.table_list.first= (byte*) (first->next_local);
select_lex.table_list.elements--; //safety
first->next_local= 0;
/*
@ -1966,8 +1974,8 @@ void st_lex::link_first_table_back(TABLE_LIST *first,
if (link_to_local)
{
first->next_local= (TABLE_LIST*) select_lex.table_list.first;
select_lex.table_list.first=
(byte*) (select_lex.context.table_list= first);
select_lex.context.table_list= first;
select_lex.table_list.first= (byte*) first;
select_lex.table_list.elements++; //safety
}
}

View File

@ -472,14 +472,16 @@ class st_select_lex: public st_select_lex_node
{
public:
Name_resolution_context context;
char *db, *db1, *table1, *db2, *table2; /* For outer join using .. */
char *db;
Item *where, *having; /* WHERE & HAVING clauses */
Item *prep_where; /* saved WHERE clause for prepared statement processing */
/* point on lex in which it was created, used in view subquery detection */
st_lex *parent_lex;
enum olap_type olap;
SQL_LIST table_list, group_list; /* FROM & GROUP BY clauses */
List<Item> item_list; /* list of fields & expressions */
/* FROM clause - points to the beginning of the TABLE_LIST::next_local list. */
SQL_LIST table_list;
SQL_LIST group_list; /* GROUP BY clause. */
List<Item> item_list; /* list of fields & expressions */
List<String> interval_list, use_index, *use_index_ptr,
ignore_index, *ignore_index_ptr;
/*
@ -492,7 +494,12 @@ public:
List<TABLE_LIST> top_join_list; /* join list of the top level */
List<TABLE_LIST> *join_list; /* list for the currently parsed join */
TABLE_LIST *embedding; /* table embedding to the above list */
TABLE_LIST *leaf_tables; /* list of leaves in join table tree */
/*
Beginning of the list of leaves in a FROM clause, where the leaves
inlcude all base tables including view tables. The tables are connected
by TABLE_LIST::next_leaf, so leaf_tables points to the left-most leaf.
*/
TABLE_LIST *leaf_tables;
const char *type; /* type of select for EXPLAIN */
SQL_LIST order_list; /* ORDER clause */
@ -594,7 +601,6 @@ public:
bool init_nested_join(THD *thd);
TABLE_LIST *end_nested_join(THD *thd);
TABLE_LIST *nest_last_join(THD *thd);
void save_names_for_using_list(TABLE_LIST *tab1, TABLE_LIST *tab2);
void add_joined_table(TABLE_LIST *table);
TABLE_LIST *convert_right_join();
List<Item>* get_item_list();
@ -736,6 +742,21 @@ typedef struct st_lex
List<set_var_base> var_list;
List<Item_param> param_list;
List<LEX_STRING> view_list; // view list (list of field names in view)
/*
A stack of name resolution contexts for the query. This stack is used
at parse time to set local name resolution contexts for various parts
of a query. For example, in a JOIN ... ON (some_condition) clause the
Items in 'some_condition' must be resolved only against the operands
of the the join, and not against the whole clause. Similarly, Items in
subqueries should be resolved against the subqueries (and outer queries).
The stack is used in the following way: when the parser detects that
all Items in some clause need a local context, it creates a new context
and pushes it on the stack. All newly created Items always store the
top-most context in the stack. Once the parser leaves the clause that
required a local context, the parser pops the top-most context.
*/
List<Name_resolution_context> context_stack;
SQL_LIST proc_list, auxilliary_table_list, save_list;
create_field *last_field;
udf_func udf;
@ -927,6 +948,21 @@ typedef struct st_lex
return ( query_tables_own_last ? *query_tables_own_last : 0);
}
void cleanup_after_one_table_open();
void push_context(Name_resolution_context *context)
{
context_stack.push_front(context);
}
void pop_context()
{
context_stack.pop();
}
Name_resolution_context *current_context()
{
return context_stack.head();
}
} LEX;
struct st_lex_local: public st_lex

View File

@ -150,6 +150,7 @@ bool mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
if (open_and_lock_tables(thd, table_list))
DBUG_RETURN(TRUE);
if (setup_tables(thd, &thd->lex->select_lex.context,
&thd->lex->select_lex.top_join_list,
table_list, &unused_conds,
&thd->lex->select_lex.leaf_tables, FALSE))
DBUG_RETURN(-1);

View File

@ -153,7 +153,7 @@ int handle_olaps(LEX *lex, SELECT_LEX *select_lex)
List<Item> all_fields(select_lex->item_list);
if (setup_tables(lex->thd, &select_lex->context,
if (setup_tables(lex->thd, &select_lex->context, &select_lex->top_join_list,
(TABLE_LIST *)select_lex->table_list.first
&select_lex->where, &select_lex->leaf_tables, FALSE) ||
setup_fields(lex->thd, 0, select_lex->item_list, 1, &all_fields,1) ||

View File

@ -2019,7 +2019,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
*/
bzero(&thd->transaction.stmt, sizeof(thd->transaction.stmt));
if (!thd->active_transaction())
thd->transaction.xid.null();
thd->transaction.xid_state.xid.null();
/* report error issued during command execution */
if (thd->killed_errno() && !thd->net.report_error)
@ -2146,6 +2146,8 @@ int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident,
{
TABLE_LIST **query_tables_last= lex->query_tables_last;
sel= new SELECT_LEX();
/* 'parent_lex' is used in init_query() so it must be before it. */
sel->parent_lex= lex;
sel->init_query();
if (!sel->add_table_to_list(thd, table_ident, 0, 0, TL_READ,
(List<String> *) 0, (List<String> *) 0))
@ -2326,11 +2328,16 @@ mysql_execute_command(THD *thd)
/*
Skip if we are in the slave thread, some table rules have been
given and the table list says the query should not be replicated.
Exception is DROP TEMPORARY TABLE IF EXISTS: we always execute it
(otherwise we have stale files on slave caused by exclusion of one tmp
table).
Exceptions are:
- SET: we always execute it (e.g., SET ONE_SHOT TIME_ZONE = 'XYZ')
- DROP TEMPORARY TABLE IF EXISTS: we always execute it (otherwise we
have stale files on slave caused by exclusion of one tmp table).
*/
if (!(lex->sql_command == SQLCOM_DROP_TABLE &&
if (lex->sql_command != SQLCOM_SET_OPTION &&
!(lex->sql_command == SQLCOM_DROP_TABLE &&
lex->drop_temporary && lex->drop_if_exists) &&
all_tables_not_ok(thd, all_tables))
{
@ -3249,19 +3256,26 @@ end_with_restore_list:
if (!(res= open_and_lock_tables(thd, all_tables)))
{
/* Skip first table, which is the table we are inserting in */
select_lex->table_list.first= (byte*)first_table->next_local;
TABLE_LIST *second_table= first_table->next_local;
select_lex->table_list.first= (byte*) second_table;
select_lex->context.table_list= second_table;
select_lex->context.first_name_resolution_table= second_table;
res= mysql_insert_select_prepare(thd);
lex->select_lex.context.table_list= first_table->next_local;
if (!res && (result= new select_insert(first_table, first_table->table,
&lex->field_list,
&lex->update_list,
&lex->value_list,
lex->duplicates, lex->ignore)))
{
/* Skip first table, which is the table we are inserting in */
/*
Skip first table, which is the table we are inserting in.
Below we set context.table_list again because the call above to
mysql_insert_select_prepare() calls resolve_in_table_list_only(),
which in turn resets context.table_list and
context.first_name_resolution_table.
*/
select_lex->context.table_list= first_table->next_local;
select_lex->context.first_name_resolution_table= first_table->next_local;
res= handle_select(thd, lex, result, OPTION_SETUP_TABLES_DONE);
delete result;
}
@ -4507,14 +4521,15 @@ end_with_restore_list:
break;
}
case SQLCOM_XA_START:
if (thd->transaction.xa_state == XA_IDLE && thd->lex->xa_opt == XA_RESUME)
if (thd->transaction.xid_state.xa_state == XA_IDLE &&
thd->lex->xa_opt == XA_RESUME)
{
if (! thd->transaction.xid.eq(thd->lex->xid))
if (! thd->transaction.xid_state.xid.eq(thd->lex->xid))
{
my_error(ER_XAER_NOTA, MYF(0));
break;
}
thd->transaction.xa_state=XA_ACTIVE;
thd->transaction.xid_state.xa_state=XA_ACTIVE;
send_ok(thd);
break;
}
@ -4523,10 +4538,10 @@ end_with_restore_list:
my_error(ER_XAER_INVAL, MYF(0));
break;
}
if (thd->transaction.xa_state != XA_NOTR)
if (thd->transaction.xid_state.xa_state != XA_NOTR)
{
my_error(ER_XAER_RMFAIL, MYF(0),
xa_state_names[thd->transaction.xa_state]);
xa_state_names[thd->transaction.xid_state.xa_state]);
break;
}
if (thd->active_transaction() || thd->locked_tables)
@ -4534,9 +4549,15 @@ end_with_restore_list:
my_error(ER_XAER_OUTSIDE, MYF(0));
break;
}
DBUG_ASSERT(thd->transaction.xid.is_null());
thd->transaction.xa_state=XA_ACTIVE;
thd->transaction.xid.set(thd->lex->xid);
if (xid_cache_search(thd->lex->xid))
{
my_error(ER_XAER_DUPID, MYF(0));
break;
}
DBUG_ASSERT(thd->transaction.xid_state.xid.is_null());
thd->transaction.xid_state.xa_state=XA_ACTIVE;
thd->transaction.xid_state.xid.set(thd->lex->xid);
xid_cache_insert(&thd->transaction.xid_state);
thd->options= ((thd->options & (ulong) ~(OPTION_STATUS_NO_TRANS_UPDATE)) |
OPTION_BEGIN);
thd->server_status|= SERVER_STATUS_IN_TRANS;
@ -4549,28 +4570,28 @@ end_with_restore_list:
my_error(ER_XAER_INVAL, MYF(0));
break;
}
if (thd->transaction.xa_state != XA_ACTIVE)
if (thd->transaction.xid_state.xa_state != XA_ACTIVE)
{
my_error(ER_XAER_RMFAIL, MYF(0),
xa_state_names[thd->transaction.xa_state]);
xa_state_names[thd->transaction.xid_state.xa_state]);
break;
}
if (!thd->transaction.xid.eq(thd->lex->xid))
if (!thd->transaction.xid_state.xid.eq(thd->lex->xid))
{
my_error(ER_XAER_NOTA, MYF(0));
break;
}
thd->transaction.xa_state=XA_IDLE;
thd->transaction.xid_state.xa_state=XA_IDLE;
send_ok(thd);
break;
case SQLCOM_XA_PREPARE:
if (thd->transaction.xa_state != XA_IDLE)
if (thd->transaction.xid_state.xa_state != XA_IDLE)
{
my_error(ER_XAER_RMFAIL, MYF(0),
xa_state_names[thd->transaction.xa_state]);
xa_state_names[thd->transaction.xid_state.xa_state]);
break;
}
if (!thd->transaction.xid.eq(thd->lex->xid))
if (!thd->transaction.xid_state.xid.eq(thd->lex->xid))
{
my_error(ER_XAER_NOTA, MYF(0));
break;
@ -4578,22 +4599,28 @@ end_with_restore_list:
if (ha_prepare(thd))
{
my_error(ER_XA_RBROLLBACK, MYF(0));
thd->transaction.xa_state=XA_NOTR;
xid_cache_delete(&thd->transaction.xid_state);
thd->transaction.xid_state.xa_state=XA_NOTR;
break;
}
thd->transaction.xa_state=XA_PREPARED;
thd->transaction.xid_state.xa_state=XA_PREPARED;
send_ok(thd);
break;
case SQLCOM_XA_COMMIT:
if (!thd->transaction.xid.eq(thd->lex->xid))
if (!thd->transaction.xid_state.xid.eq(thd->lex->xid))
{
if (!(res= !ha_commit_or_rollback_by_xid(thd->lex->xid, 1)))
XID_STATE *xs=xid_cache_search(thd->lex->xid);
if (!xs || xs->in_thd)
my_error(ER_XAER_NOTA, MYF(0));
else
{
ha_commit_or_rollback_by_xid(thd->lex->xid, 1);
xid_cache_delete(xs);
send_ok(thd);
}
break;
}
if (thd->transaction.xa_state == XA_IDLE &&
if (thd->transaction.xid_state.xa_state == XA_IDLE &&
thd->lex->xa_opt == XA_ONE_PHASE)
{
int r;
@ -4602,7 +4629,7 @@ end_with_restore_list:
else
send_ok(thd);
}
else if (thd->transaction.xa_state == XA_PREPARED &&
else if (thd->transaction.xid_state.xa_state == XA_PREPARED &&
thd->lex->xa_opt == XA_NONE)
{
if (wait_if_global_read_lock(thd, 0, 0))
@ -4622,27 +4649,33 @@ end_with_restore_list:
else
{
my_error(ER_XAER_RMFAIL, MYF(0),
xa_state_names[thd->transaction.xa_state]);
xa_state_names[thd->transaction.xid_state.xa_state]);
break;
}
thd->options&= ~(ulong) (OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE);
thd->server_status&= ~SERVER_STATUS_IN_TRANS;
thd->transaction.xa_state=XA_NOTR;
xid_cache_delete(&thd->transaction.xid_state);
thd->transaction.xid_state.xa_state=XA_NOTR;
break;
case SQLCOM_XA_ROLLBACK:
if (!thd->transaction.xid.eq(thd->lex->xid))
if (!thd->transaction.xid_state.xid.eq(thd->lex->xid))
{
if (!(res= !ha_commit_or_rollback_by_xid(thd->lex->xid, 0)))
XID_STATE *xs=xid_cache_search(thd->lex->xid);
if (!xs || xs->in_thd)
my_error(ER_XAER_NOTA, MYF(0));
else
{
ha_commit_or_rollback_by_xid(thd->lex->xid, 0);
xid_cache_delete(xs);
send_ok(thd);
}
break;
}
if (thd->transaction.xa_state != XA_IDLE &&
thd->transaction.xa_state != XA_PREPARED)
if (thd->transaction.xid_state.xa_state != XA_IDLE &&
thd->transaction.xid_state.xa_state != XA_PREPARED)
{
my_error(ER_XAER_RMFAIL, MYF(0),
xa_state_names[thd->transaction.xa_state]);
xa_state_names[thd->transaction.xid_state.xa_state]);
break;
}
if (ha_rollback(thd))
@ -4651,7 +4684,8 @@ end_with_restore_list:
send_ok(thd);
thd->options&= ~(ulong) (OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE);
thd->server_status&= ~SERVER_STATUS_IN_TRANS;
thd->transaction.xa_state=XA_NOTR;
xid_cache_delete(&thd->transaction.xid_state);
thd->transaction.xid_state.xa_state=XA_NOTR;
break;
case SQLCOM_XA_RECOVER:
res= mysql_xa_recover(thd);
@ -5211,9 +5245,9 @@ mysql_new_select(LEX *lex, bool move_down)
if (!(select_lex= new (thd->mem_root) SELECT_LEX()))
DBUG_RETURN(1);
select_lex->select_number= ++thd->select_number;
select_lex->parent_lex= lex; /* Used in init_query. */
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
@ -5271,6 +5305,7 @@ mysql_new_select(LEX *lex, bool move_down)
fake->include_standalone(unit,
(SELECT_LEX_NODE**)&unit->fake_select_lex);
fake->select_number= INT_MAX;
fake->parent_lex= lex; /* Used in init_query. */
fake->make_empty_select();
fake->linkage= GLOBAL_OPTIONS_TYPE;
fake->select_limit= 0;
@ -5279,6 +5314,11 @@ mysql_new_select(LEX *lex, bool move_down)
/* allow item list resolving in fake select for ORDER BY */
fake->context.resolve_in_select_list= TRUE;
fake->context.select_lex= fake;
/*
Remove the name resolution context of the fake select from the
context stack.
*/
lex->pop_context();
}
select_lex->context.outer_context= outer_context;
}
@ -5972,6 +6012,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd,
LEX_STRING *option)
{
register TABLE_LIST *ptr;
TABLE_LIST *previous_table_ref; /* The table preceding the current one. */
char *alias_str;
LEX *lex= thd->lex;
DBUG_ENTER("add_table_to_list");
@ -6067,8 +6108,29 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd,
}
}
}
/* Link table in local list (list for current select) */
/* Store the table reference preceding the current one. */
if (table_list.elements > 0)
{
previous_table_ref= (TABLE_LIST*) table_list.next;
DBUG_ASSERT(previous_table_ref);
}
/*
Link the current table reference in a local list (list for current select).
Notice that as a side effect here we set the next_local field of the
previous table reference to 'ptr'. Here we also add one element to the
list 'table_list'.
*/
table_list.link_in_list((byte*) ptr, (byte**) &ptr->next_local);
/*
Set next_name_resolution_table of the previous table reference to point to
the current table reference. In effect the list
TABLE_LIST::next_name_resolution_table coincides with
TABLE_LIST::next_local. Later this may be changed in
store_top_level_join_columns() for NATURAL/USING joins.
*/
if (table_list.elements > 1)
previous_table_ref->next_name_resolution_table= ptr;
ptr->next_name_resolution_table= NULL;
/* Link table in global list (all used tables) */
lex->add_to_query_tables(ptr);
DBUG_RETURN(ptr);
@ -6197,6 +6259,19 @@ TABLE_LIST *st_select_lex::nest_last_join(THD *thd)
table->join_list= embedded_list;
table->embedding= ptr;
embedded_list->push_back(table);
if (table->natural_join)
{
ptr->is_natural_join= TRUE;
/*
If this is a JOIN ... USING, move the list of joined fields to the
table reference that describes the join.
*/
if (table->join_using_fields)
{
ptr->join_using_fields= table->join_using_fields;
table->join_using_fields= NULL;
}
}
}
join_list->push_front(ptr);
nested_join->used_tables= nested_join->not_null_tables= (table_map) 0;
@ -6204,44 +6279,6 @@ TABLE_LIST *st_select_lex::nest_last_join(THD *thd)
}
/*
Save names for a join with using clause
SYNOPSIS
save_names_for_using_list
tab1 left table in join
tab2 right table in join
DESCRIPTION
The function saves the full names of the tables in st_select_lex
to be able to build later an on expression to replace the using clause.
RETURN VALUE
None
*/
void st_select_lex::save_names_for_using_list(TABLE_LIST *tab1,
TABLE_LIST *tab2)
{
while (tab1->nested_join)
{
tab1= tab1->nested_join->join_list.head();
}
db1= tab1->db;
table1= tab1->alias;
while (tab2->nested_join)
{
TABLE_LIST *next;
List_iterator_fast<TABLE_LIST> it(tab2->nested_join->join_list);
tab2= it++;
while ((next= it++))
tab2= next;
}
db2= tab2->db;
table2= tab2->alias;
}
/*
Add a table to the current join list
@ -6345,16 +6382,71 @@ void st_select_lex::set_lock_for_tables(thr_lock_type lock_type)
}
void add_join_on(TABLE_LIST *b,Item *expr)
/*
Create a new name resolution context for a JOIN ... ON clause.
SYNOPSIS
make_join_on_context()
thd pointer to current thread
left_op lefto operand of the JOIN
right_op rigth operand of the JOIN
DESCRIPTION
Create a new name resolution context for a JOIN ... ON clause,
and set the first and last leaves of the list of table references
to be used for name resolution.
RETURN
A new context if all is OK
NULL - if a memory allocation error occured
*/
Name_resolution_context *
make_join_on_context(THD *thd, TABLE_LIST *left_op, TABLE_LIST *right_op)
{
Name_resolution_context *on_context;
if (!(on_context= (Name_resolution_context*)
thd->calloc(sizeof(Name_resolution_context))))
return NULL;
on_context->init();
on_context->first_name_resolution_table=
left_op->first_leaf_for_name_resolution();
on_context->last_name_resolution_table=
right_op->last_leaf_for_name_resolution();
return on_context;
}
/*
Add an ON condition to the second operand of a JOIN ... ON.
SYNOPSIS
add_join_on
b the second operand of a JOIN ... ON
expr the condition to be added to the ON clause
DESCRIPTION
Add an ON condition to the right operand of a JOIN ... ON clause.
RETURN
FALSE if there was some error
TRUE if all is OK
*/
void add_join_on(TABLE_LIST *b, Item *expr)
{
if (expr)
{
if (!b->on_expr)
b->on_expr=expr;
b->on_expr= expr;
else
{
/* This only happens if you have both a right and left join */
b->on_expr=new Item_cond_and(b->on_expr,expr);
/*
If called from the parser, this happens if you have both a
right and left join. If called later, it happens if we add more
than one condition to the ON clause.
*/
b->on_expr= new Item_cond_and(b->on_expr,expr);
}
b->on_expr->top_level_item();
}
@ -6362,28 +6454,49 @@ void add_join_on(TABLE_LIST *b,Item *expr)
/*
Mark that we have a NATURAL JOIN between two tables
Mark that there is a NATURAL JOIN or JOIN ... USING between two
tables.
SYNOPSIS
add_join_natural()
a Table to do normal join with
b Do normal join with this table
a Left join argument
b Right join argument
using_fields Field names from USING clause
IMPLEMENTATION
This function just marks that table b should be joined with a.
The function setup_cond() will create in b->on_expr a list
of equal condition between all fields of the same name.
This function marks that table b should be joined with a either via
a NATURAL JOIN or via JOIN ... USING. Both join types are special
cases of each other, so we treat them together. The function
setup_conds() creates a list of equal condition between all fields
of the same name for NATURAL JOIN or the fields in 'using_fields'
for JOIN ... USING. The list of equality conditions is stored
either in b->on_expr, or in JOIN::conds, depending on whether there
was an outer join.
EXAMPLE
SELECT * FROM t1 NATURAL LEFT JOIN t2
<=>
SELECT * FROM t1 LEFT JOIN t2 ON (t1.i=t2.i and t1.j=t2.j ... )
SELECT * FROM t1 NATURAL JOIN t2 WHERE <some_cond>
<=>
SELECT * FROM t1, t2 WHERE (t1.i=t2.i and t1.j=t2.j and <some_cond>)
SELECT * FROM t1 JOIN t2 USING(j) WHERE <some_cond>
<=>
SELECT * FROM t1, t2 WHERE (t1.j=t2.j and <some_cond>)
RETURN
None
*/
void add_join_natural(TABLE_LIST *a,TABLE_LIST *b)
void add_join_natural(TABLE_LIST *a, TABLE_LIST *b, List<String> *using_fields)
{
b->natural_join=a;
b->natural_join= a;
b->join_using_fields= using_fields;
}
/*
Reload/resets privileges and the different caches.

View File

@ -338,7 +338,7 @@ JOIN::prepare(Item ***rref_pointer_array,
/* Check that all tables, fields, conds and order are ok */
if ((!(select_options & OPTION_SETUP_TABLES_DONE) &&
setup_tables(thd, &select_lex->context,
setup_tables(thd, &select_lex->context, join_list,
tables_list, &conds, &select_lex->leaf_tables,
FALSE)) ||
setup_wild(thd, tables_list, fields_list, &all_fields, wild_num) ||
@ -1583,7 +1583,8 @@ JOIN::exec()
curr_join->tmp_having= make_cond_for_table(curr_join->tmp_having,
~ (table_map) 0,
~used_tables);
DBUG_EXECUTE("where",print_where(conds,"having after sort"););
DBUG_EXECUTE("where",print_where(curr_join->tmp_having,
"having after sort"););
}
}
{
@ -11911,13 +11912,14 @@ cp_buffer_from_ref(THD *thd, TABLE_REF *ref)
SYNOPSIS
find_order_in_list()
thd Pointer to current thread structure
ref_pointer_array All select, group and order by fields
tables List of tables to search in (usually FROM clause)
order Column reference to be resolved
fields List of fields to search in (usually SELECT list)
all_fields All select, group and order by fields
is_group_field True if order is a GROUP field, false if ORDER by field
thd [in] Pointer to current thread structure
ref_pointer_array [in/out] All select, group and order by fields
tables [in] List of tables to search in (usually FROM clause)
order [in] Column reference to be resolved
fields [in] List of fields to search in (usually SELECT list)
all_fields [in/out] All select, group and order by fields
is_group_field [in] True if order is a GROUP field, false if
ORDER by field
DESCRIPTION
Given a column reference (represented by 'order') from a GROUP BY or ORDER
@ -11993,7 +11995,7 @@ find_order_in_list(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
order_item_type == Item::REF_ITEM)
{
from_field= find_field_in_tables(thd, (Item_ident*) order_item, tables,
&view_ref, IGNORE_ERRORS, TRUE,
NULL, &view_ref, IGNORE_ERRORS, TRUE,
FALSE);
if (!from_field)
from_field= (Field*) not_found_field;

View File

@ -2072,6 +2072,11 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
else
{
int res;
/*
Set the parent lex of 'sel' because it is needed by sel.init_query()
which is called inside make_table_list.
*/
sel.parent_lex= lex;
if (make_table_list(thd, &sel, base_name, file_name))
goto err;
TABLE_LIST *show_table_list= (TABLE_LIST*) sel.table_list.first;

View File

@ -555,7 +555,7 @@ bool mysql_prepare_update(THD *thd, TABLE_LIST *table_list,
tables.table= table;
tables.alias= table_list->alias;
if (setup_tables(thd, &select_lex->context,
if (setup_tables(thd, &select_lex->context, &select_lex->top_join_list,
table_list, conds, &select_lex->leaf_tables,
FALSE) ||
setup_conds(thd, table_list, select_lex->leaf_tables, conds) ||
@ -643,6 +643,7 @@ bool mysql_multi_update_prepare(THD *thd)
*/
if (setup_tables(thd, &lex->select_lex.context,
&lex->select_lex.top_join_list,
table_list, &lex->select_lex.where,
&lex->select_lex.leaf_tables, FALSE))
DBUG_RETURN(TRUE);
@ -761,6 +762,7 @@ bool mysql_multi_update_prepare(THD *thd)
tbl->cleanup_items();
if (setup_tables(thd, &lex->select_lex.context,
&lex->select_lex.top_join_list,
table_list, &lex->select_lex.where,
&lex->select_lex.leaf_tables, FALSE) ||
setup_fields_with_no_wrap(thd, 0, *fields, 1, 0, 0))

View File

@ -94,6 +94,71 @@ static void make_unique_view_field_name(Item *target,
target->set_name(buff, name_len, system_charset_info);
}
/*
Check if items with same names are present in list and possibly
generate unique names for them.
SYNOPSIS
item_list list of Items which should be checked for duplicates
gen_unique_view_name flag: generate unique name or return with error when
duplicate names are found.
DESCRIPTION
This function is used on view creation and preparation of derived tables.
It checks item_list for items with duplicate names. If it founds two
items with same name and conversion to unique names isn't allowed, or
names for both items are set by user - function fails.
Otherwise it generates unique name for one item with autogenerated name
using make_unique_view_field_name()
RETURN VALUE
FALSE no duplicate names found, or they are converted to unique ones
TRUE duplicate names are found and they can't be converted or conversion
isn't allowed
*/
bool check_duplicate_names(List<Item> &item_list, bool gen_unique_view_name)
{
DBUG_ENTER("check_duplicate_names");
/* Test absence of duplicates names */
{
Item *item;
List_iterator_fast<Item> it(item_list);
List_iterator_fast<Item> itc(item_list);
while ((item= it++))
{
Item *check;
/* treat underlying fields like set by user names */
if (item->real_item()->type() == Item::FIELD_ITEM)
item->is_autogenerated_name= FALSE;
itc.rewind();
while ((check= itc++) && check != item)
{
if (my_strcasecmp(system_charset_info, item->name, check->name) == 0)
{
if (!gen_unique_view_name)
{
my_error(ER_DUP_FIELDNAME, MYF(0), item->name);
DBUG_RETURN(TRUE);
}
else if (item->is_autogenerated_name)
make_unique_view_field_name(item, item_list, item);
else if (check->is_autogenerated_name)
make_unique_view_field_name(check, item_list, item);
else
{
my_error(ER_DUP_FIELDNAME, MYF(0), item->name);
DBUG_RETURN(TRUE);
}
}
}
}
}
DBUG_RETURN(FALSE);
}
/*
Creating/altering VIEW procedure
@ -308,35 +373,8 @@ bool mysql_create_view(THD *thd,
}
}
/* Test absence of duplicates names */
{
Item *item;
List_iterator_fast<Item> it(select_lex->item_list);
List_iterator_fast<Item> itc(select_lex->item_list);
while ((item= it++))
{
Item *check;
/* treat underlying fields like set by user names */
if (item->real_item()->type() == Item::FIELD_ITEM)
item->is_autogenerated_name= FALSE;
itc.rewind();
while ((check= itc++) && check != item)
{
if (my_strcasecmp(system_charset_info, item->name, check->name) == 0)
{
if (item->is_autogenerated_name)
make_unique_view_field_name(item, select_lex->item_list, item);
else if (check->is_autogenerated_name)
make_unique_view_field_name(check, select_lex->item_list, item);
else
{
my_error(ER_DUP_FIELDNAME, MYF(0), item->name);
DBUG_RETURN(TRUE);
}
}
}
}
}
if (check_duplicate_names(select_lex->item_list, 1))
DBUG_RETURN(TRUE);
#ifndef NO_EMBEDDED_ACCESS_CHECKS
/*
@ -844,6 +882,9 @@ mysql_make_view(File_parser *parser, TABLE_LIST *table)
view_tables);
lex->select_lex.context.outer_context= 0;
lex->select_lex.context.select_lex= table->select_lex;
lex->select_lex.select_n_having_items+=
table->select_lex->select_n_having_items;
/* do not check privileges & hide errors for view underlyings */
for (SELECT_LEX *sl= lex->all_selects_list;
sl;
@ -864,7 +905,11 @@ mysql_make_view(File_parser *parser, TABLE_LIST *table)
{
if (view_tables->next_local)
{
table->multitable_view= TRUE;
if (table->belong_to_view)
table->belong_to_view->multitable_view= TRUE;
}
/* make nested join structure for view tables */
NESTED_JOIN *nested_join;
if (!(nested_join= table->nested_join=

View File

@ -33,5 +33,7 @@ int view_checksum(THD *thd, TABLE_LIST *view);
extern TYPELIB updatable_views_with_limit_typelib;
bool check_duplicate_names(List<Item>& item_list, bool gen_unique_view_names);
#define VIEW_ANY_ACL (SELECT_ACL | UPDATE_ACL | INSERT_ACL | DELETE_ACL)

View File

@ -717,7 +717,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
bool_term bool_factor bool_test bool_pri
predicate bit_expr bit_term bit_factor value_expr term factor
table_wild simple_expr udf_expr
using_list expr_or_default set_expr_or_default interval_expr
expr_or_default set_expr_or_default interval_expr
param_marker singlerow_subselect singlerow_subselect_init
exists_subselect exists_subselect_init geometry_function
signed_literal now_or_signed_literal opt_escape
@ -739,7 +739,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
key_alg opt_btree_or_rtree
%type <string_list>
key_usage_list
key_usage_list using_list
%type <key_part>
key_part
@ -4425,10 +4425,10 @@ simple_expr:
my_error(ER_WRONG_COLUMN_NAME, MYF(0), name->str);
YYABORT;
}
$$= new Item_default_value(&Select->context, $3);
$$= new Item_default_value(Lex->current_context(), $3);
}
| VALUES '(' simple_ident ')'
{ $$= new Item_insert_value(&Select->context, $3); }
{ $$= new Item_insert_value(Lex->current_context(), $3); }
| FUNC_ARG0 '(' ')'
{
if (!$1.symbol->create_func)
@ -4719,9 +4719,9 @@ simple_expr:
name->init_qname(YYTHD);
sp_add_used_routine(lex, YYTHD, name, TYPE_ENUM_FUNCTION);
if ($5)
$$= new Item_func_sp(&lex->current_select->context, name, *$5);
$$= new Item_func_sp(Lex->current_context(), name, *$5);
else
$$= new Item_func_sp(&lex->current_select->context, name);
$$= new Item_func_sp(Lex->current_context(), name);
lex->safe_to_cache_query=0;
}
| IDENT_sys '(' udf_expr_list ')'
@ -4809,9 +4809,9 @@ simple_expr:
sp_add_used_routine(lex, YYTHD, name, TYPE_ENUM_FUNCTION);
if ($3)
$$= new Item_func_sp(&lex->current_select->context, name, *$3);
$$= new Item_func_sp(Lex->current_context(), name, *$3);
else
$$= new Item_func_sp(&lex->current_select->context, name);
$$= new Item_func_sp(Lex->current_context(), name);
lex->safe_to_cache_query=0;
}
}
@ -5015,7 +5015,7 @@ sum_expr:
{
SELECT_LEX *sel= Select;
sel->in_sum_expr--;
$$=new Item_func_group_concat(&sel->context, $3, $5,
$$=new Item_func_group_concat(Lex->current_context(), $3, $5,
sel->gorder_list, $7);
$5->empty();
};
@ -5151,68 +5151,116 @@ join_table:
table_ref normal_join table_ref { YYERROR_UNLESS($1 && ($$=$3)); }
| table_ref STRAIGHT_JOIN table_factor
{ YYERROR_UNLESS($1 && ($$=$3)); $3->straight=1; }
| table_ref normal_join table_ref ON expr
{ YYERROR_UNLESS($1 && ($$=$3)); add_join_on($3,$5); }
| table_ref STRAIGHT_JOIN table_factor ON expr
{ YYERROR_UNLESS($1 && ($$=$3)); $3->straight=1; add_join_on($3,$5); }
| table_ref normal_join table_ref
ON
{
YYERROR_UNLESS($1 && ($$=$3));
/* Change the current name resolution context to a local context. */
Name_resolution_context *on_context;
if (!(on_context= make_join_on_context(YYTHD,$1,$3)))
YYABORT;
Lex->push_context(on_context);
}
expr
{
add_join_on($3,$6);
Lex->pop_context();
}
| table_ref STRAIGHT_JOIN table_factor
ON
{
YYERROR_UNLESS($1 && ($$=$3));
/* Change the current name resolution context to a local context. */
Name_resolution_context *on_context;
if (!(on_context= make_join_on_context(YYTHD,$1,$3)))
YYABORT;
Lex->push_context(on_context);
}
expr
{
$3->straight=1;
add_join_on($3,$6);
Lex->pop_context();
}
| table_ref normal_join table_ref
USING
{
SELECT_LEX *sel= Select;
YYERROR_UNLESS($1 && $3);
sel->save_names_for_using_list($1, $3);
}
'(' using_list ')'
{ add_join_on($3,$7); $$=$3; }
| table_ref LEFT opt_outer JOIN_SYM table_ref ON expr
{ YYERROR_UNLESS($1 && $5); add_join_on($5,$7); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; }
{ add_join_natural($1,$3,$7); $$=$3; }
| table_ref LEFT opt_outer JOIN_SYM table_ref
ON
{
/* Change the current name resolution context to a local context. */
Name_resolution_context *on_context;
if (!(on_context= make_join_on_context(YYTHD,$1,$5)))
YYABORT;
Lex->push_context(on_context);
}
expr
{
YYERROR_UNLESS($1 && $5);
add_join_on($5,$8);
Lex->pop_context();
$5->outer_join|=JOIN_TYPE_LEFT;
$$=$5;
}
| table_ref LEFT opt_outer JOIN_SYM table_factor
{
SELECT_LEX *sel= Select;
YYERROR_UNLESS($1 && $5);
sel->save_names_for_using_list($1, $5);
}
USING '(' using_list ')'
{ add_join_on($5,$9); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; }
{ add_join_natural($1,$5,$9); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; }
| table_ref NATURAL LEFT opt_outer JOIN_SYM table_factor
{
YYERROR_UNLESS($1 && $6);
add_join_natural($1,$6);
add_join_natural($1,$6,NULL);
$6->outer_join|=JOIN_TYPE_LEFT;
$$=$6;
}
| table_ref RIGHT opt_outer JOIN_SYM table_ref ON expr
| table_ref RIGHT opt_outer JOIN_SYM table_ref
ON
{
/* Change the current name resolution context to a local context. */
Name_resolution_context *on_context;
if (!(on_context= make_join_on_context(YYTHD,$1,$5)))
YYABORT;
Lex->push_context(on_context);
}
expr
{
LEX *lex= Lex;
YYERROR_UNLESS($1 && $5);
if (!($$= lex->current_select->convert_right_join()))
YYABORT;
add_join_on($$, $7);
add_join_on($$, $8);
Lex->pop_context();
}
| table_ref RIGHT opt_outer JOIN_SYM table_factor
{
SELECT_LEX *sel= Select;
YYERROR_UNLESS($1 && $5);
sel->save_names_for_using_list($1, $5);
}
USING '(' using_list ')'
{
LEX *lex= Lex;
if (!($$= lex->current_select->convert_right_join()))
YYABORT;
add_join_on($$, $9);
add_join_natural($$,$5,$9);
}
| table_ref NATURAL RIGHT opt_outer JOIN_SYM table_factor
{
YYERROR_UNLESS($1 && $6);
add_join_natural($6,$1);
add_join_natural($6,$1,NULL);
LEX *lex= Lex;
if (!($$= lex->current_select->convert_right_join()))
YYABORT;
}
| table_ref NATURAL JOIN_SYM table_factor
{ YYERROR_UNLESS($1 && ($$=$4)); add_join_natural($1,$4); };
{ YYERROR_UNLESS($1 && ($$=$4)); add_join_natural($1,$4,NULL); };
normal_join:
@ -5240,8 +5288,23 @@ table_factor:
YYABORT;
sel->add_joined_table($$);
}
| '{' ident table_ref LEFT OUTER JOIN_SYM table_ref ON expr '}'
{ YYERROR_UNLESS($3 && $7); add_join_on($7,$9); $7->outer_join|=JOIN_TYPE_LEFT; $$=$7; }
| '{' ident table_ref LEFT OUTER JOIN_SYM table_ref
ON
{
/* Change the current name resolution context to a local context. */
Name_resolution_context *on_context;
if (!(on_context= make_join_on_context(YYTHD,$3,$7)))
YYABORT;
Lex->push_context(on_context);
}
expr '}'
{
YYERROR_UNLESS($3 && $7);
add_join_on($7,$10);
Lex->pop_context();
$7->outer_join|=JOIN_TYPE_LEFT;
$$=$7;
}
| select_derived_init get_select_lex select_derived2
{
LEX *lex= Lex;
@ -5295,6 +5358,7 @@ table_factor:
YYABORT;
sel->add_joined_table($$);
lex->pop_context();
}
else
if ($4 || $6)
@ -5434,32 +5498,18 @@ key_usage_list2:
using_list:
ident
{
SELECT_LEX *sel= Select;
if (!($$= new Item_func_eq(new Item_field(&sel->context,
sel->db1, sel->table1,
$1.str),
new Item_field(&sel->context,
sel->db2, sel->table2,
$1.str))))
if (!($$= new List<String>))
YYABORT;
$$->push_back(new (YYTHD->mem_root)
String((const char *) $1.str, $1.length,
system_charset_info));
}
| using_list ',' ident
{
SELECT_LEX *sel= Select;
if (!($$=
new Item_cond_and(new
Item_func_eq(new
Item_field(&sel->context,
sel->db1,
sel->table1,
$3.str),
new
Item_field(&sel->context,
sel->db2,
sel->table2,
$3.str)),
$1)))
YYABORT;
$1->push_back(new (YYTHD->mem_root)
String((const char *) $3.str, $3.length,
system_charset_info));
$$= $1;
};
interval:
@ -6100,7 +6150,7 @@ values:
expr_or_default:
expr { $$= $1;}
| DEFAULT {$$= new Item_default_value(&Select->context); }
| DEFAULT {$$= new Item_default_value(Lex->current_context()); }
;
opt_insert_update:
@ -7061,13 +7111,13 @@ table_wild:
ident '.' '*'
{
SELECT_LEX *sel= Select;
$$ = new Item_field(&sel->context, NullS, $1.str, "*");
$$ = new Item_field(Lex->current_context(), NullS, $1.str, "*");
sel->with_wild++;
}
| ident '.' ident '.' '*'
{
SELECT_LEX *sel= Select;
$$ = new Item_field(&sel->context, (YYTHD->client_capabilities &
$$ = new Item_field(Lex->current_context(), (YYTHD->client_capabilities &
CLIENT_NO_SCHEMA ? NullS : $1.str),
$3.str,"*");
sel->with_wild++;
@ -7095,8 +7145,8 @@ simple_ident:
SELECT_LEX *sel=Select;
$$= (sel->parsing_place != IN_HAVING ||
sel->get_in_sum_expr() > 0) ?
(Item*) new Item_field(&sel->context, NullS, NullS, $1.str) :
(Item*) new Item_ref(&sel->context, NullS, NullS, $1.str);
(Item*) new Item_field(Lex->current_context(), NullS, NullS, $1.str) :
(Item*) new Item_ref(Lex->current_context(), NullS, NullS, $1.str);
}
}
| simple_ident_q { $$= $1; }
@ -7108,8 +7158,8 @@ simple_ident_nospvar:
SELECT_LEX *sel=Select;
$$= (sel->parsing_place != IN_HAVING ||
sel->get_in_sum_expr() > 0) ?
(Item*) new Item_field(&sel->context, NullS, NullS, $1.str) :
(Item*) new Item_ref(&sel->context, NullS, NullS, $1.str);
(Item*) new Item_field(Lex->current_context(), NullS, NullS, $1.str) :
(Item*) new Item_ref(Lex->current_context(), NullS, NullS, $1.str);
}
| simple_ident_q { $$= $1; }
;
@ -7146,7 +7196,7 @@ simple_ident_q:
YYABORT;
}
if (!(trg_fld= new Item_trigger_field(&lex->current_select->context,
if (!(trg_fld= new Item_trigger_field(Lex->current_context(),
new_row ?
Item_trigger_field::NEW_ROW:
Item_trigger_field::OLD_ROW,
@ -7172,8 +7222,8 @@ simple_ident_q:
}
$$= (sel->parsing_place != IN_HAVING ||
sel->get_in_sum_expr() > 0) ?
(Item*) new Item_field(&sel->context, NullS, $1.str, $3.str) :
(Item*) new Item_ref(&sel->context, NullS, $1.str, $3.str);
(Item*) new Item_field(Lex->current_context(), NullS, $1.str, $3.str) :
(Item*) new Item_ref(Lex->current_context(), NullS, $1.str, $3.str);
}
}
| '.' ident '.' ident
@ -7188,8 +7238,8 @@ simple_ident_q:
}
$$= (sel->parsing_place != IN_HAVING ||
sel->get_in_sum_expr() > 0) ?
(Item*) new Item_field(&sel->context, NullS, $2.str, $4.str) :
(Item*) new Item_ref(&sel->context, NullS, $2.str, $4.str);
(Item*) new Item_field(Lex->current_context(), NullS, $2.str, $4.str) :
(Item*) new Item_ref(Lex->current_context(), NullS, $2.str, $4.str);
}
| ident '.' ident '.' ident
{
@ -7203,11 +7253,11 @@ simple_ident_q:
}
$$= (sel->parsing_place != IN_HAVING ||
sel->get_in_sum_expr() > 0) ?
(Item*) new Item_field(&sel->context,
(Item*) new Item_field(Lex->current_context(),
(YYTHD->client_capabilities &
CLIENT_NO_SCHEMA ? NullS : $1.str),
$3.str, $5.str) :
(Item*) new Item_ref(&sel->context,
(Item*) new Item_ref(Lex->current_context(),
(YYTHD->client_capabilities &
CLIENT_NO_SCHEMA ? NullS : $1.str),
$3.str, $5.str);
@ -7772,8 +7822,7 @@ sys_option_value:
it= new Item_null();
}
if (!(trg_fld= new Item_trigger_field(&lex->current_select->
context,
if (!(trg_fld= new Item_trigger_field(Lex->current_context(),
Item_trigger_field::NEW_ROW,
$2.base_name.str)) ||
!(sp_fld= new sp_instr_set_trigger_field(lex->sphead->
@ -8630,7 +8679,12 @@ union_list:
lex->current_select->master_unit()->union_distinct=
lex->current_select;
}
select_init {}
select_init
{
/* Remove from the name resolution context stack the context of the
last select in the union. */
Lex->pop_context();
}
;
union_opt:
@ -8734,6 +8788,7 @@ subselect_end:
')'
{
LEX *lex=Lex;
lex->pop_context();
lex->current_select = lex->current_select->return_after_parsing();
};

Some files were not shown because too many files have changed in this diff Show More