Commit bf6cfd29 authored by monty@mashka.mysql.fi's avatar monty@mashka.mysql.fi

Fix for -fbranch-probabilites (bug 268)

Fix for LEFT/RIGHT/MID with multi-byte-character sets (bug 314)
Fix for new bison 1.875
max_insert_delayed_threads and delayed_insert_timeout now works as documented (bug 211)
Don't show port in SHOW PROCESSLIST for system threads
Fix problem with ORDER BY being discarded for some DISTINCT queries (bug 275)
Fixed bug with NATURAL LEFT JOIN, NATURAL RIGHT JOIN and RIGHT JOIN when
using many joined tables (Bug 212)
parent ba5b57c6
......@@ -38,7 +38,7 @@ AC_LANG_SAVE
AC_LANG_CPLUSPLUS
if test "$ac_cv_prog_gxx" = "yes"
then
CXXFLAGS="$CXXFLAGS -Werror"
CXXFLAGS=`echo $CXXFLAGS -Werror | sed 's/-fbranch-probabilities//'`
fi
mysql_cv_btype_last_arg_accept=none
[AC_TRY_COMPILE([#if defined(inline)
......
......@@ -1862,7 +1862,7 @@ AC_LANG_SAVE
AC_LANG_CPLUSPLUS
if test "$ac_cv_prog_gxx" = "yes" -a "$with_other_libc" = "no"
then
CXXFLAGS="$CXXFLAGS -Werror"
CXXFLAGS=`echo "$CXXFLAGS -Werror" | sed 's/-fbranch-probabilities//'`
fi
AC_TRY_COMPILE(
[#undef inline
......@@ -1894,7 +1894,7 @@ AC_LANG_SAVE
AC_LANG_CPLUSPLUS
if test "$ac_cv_prog_gxx" = "yes" -a "$with_other_libc" = "no"
then
CXXFLAGS="$CXXFLAGS -Werror"
CXXFLAGS=`echo "$CXXFLAGS -Werror" | sed 's/-fbranch-probabilities//'`
fi
AC_TRY_COMPILE(
[#undef inline
......@@ -2341,7 +2341,7 @@ extern int mbcharlen_${c}(uint);"
mbcharlen_${c}"
else
CHARSET_COMP_CS_INIT="$CHARSET_COMP_CS_INIT
0, /* mbmaxlen */
1, /* mbmaxlen */
NULL, /* ismbchar */
NULL, /* ismbhead */
NULL /* mbcharlen */"
......
......@@ -183,8 +183,11 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
share->state_diff_length=len-MI_STATE_INFO_SIZE;
if (share->state.header.fulltext_keys)
fprintf(stderr, "Table file %s was created in MySQL 4.1+, use REPAIR TABLE ... USE_FRM to recreate it as a valid MySQL 4.0 table\n", name_buff);
{
/* Not supported in this version */
my_errno= HA_ERR_UNSUPPORTED;
goto err;
}
mi_state_info_read(disk_cache, &share->state);
len= mi_uint2korr(share->state.header.base_info_length);
if (len != MI_BASE_INFO_SIZE)
......
drop table if exists t1;
create table t1 (c text);
insert into t1 values (0xa4a2),(0xa4a3);
select hex(left(c,1)) from t1 group by c;
hex(left(c,1))
A4A2
A4A3
drop table t1;
......@@ -274,3 +274,90 @@ SELECT emp.rate_code, lr.base_rate FROM t1 AS emp LEFT JOIN t2 AS lr USING (site
rate_code base_rate
cust 20
drop table t1,t2;
create table t1 (i int);
create table t2 (i int);
create table t3 (i int);
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
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
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
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
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 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 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 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 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
1 2 2
2 NULL 4
2 2 2
drop table t1,t2,t3;
......@@ -351,12 +351,7 @@ select t1.name, t2.name, t2.id,t3.id from t1 right join t2 on (t1.id = t2.owner)
name name id id
Antonio Paz El Gato 1 1
Antonio Paz Perrito 2 1
NULL Happy 3 1
NULL El Gato 1 2
NULL Perrito 2 2
NULL Happy 3 2
NULL El Gato 1 3
NULL Perrito 2 3
NULL NULL NULL 2
Thimble Smith Happy 3 3
select t1.name, t2.name, t2.id, t2.owner, t3.id from t1 left join t2 on (t1.id = t2.owner) right join t1 as t3 on t3.id=t2.owner;
name name id owner id
......
......@@ -3402,13 +3402,7 @@ a a a
select * from t1 natural left join (t1 as t2 left join t1 as t3 using (a));
a a a
1 1 1
2 1 NULL
3 1 NULL
1 2 NULL
2 2 2
3 2 NULL
1 3 NULL
2 3 NULL
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
......@@ -3464,13 +3458,7 @@ a a a
select * from t1 natural join (t1 as t2 left join t1 as t3 using (a));
a a a
1 1 1
2 1 NULL
3 1 NULL
1 2 NULL
2 2 2
3 2 NULL
1 3 NULL
2 3 NULL
3 3 3
select * from (t1 as t2 left join t1 as t3 using (a)) natural join t1;
a a a
......
--default-character-set=ujis
#
# Tests with the ujis character set
#
drop table if exists t1;
#
# Test problem with LEFT()
#
create table t1 (c text);
insert into t1 values (0xa4a2),(0xa4a3);
select hex(left(c,1)) from t1 group by c;
drop table t1;
......@@ -271,3 +271,35 @@ 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';
drop table t1,t2;
#
# Test combination of join methods
#
create table t1 (i int);
create table t2 (i int);
create table t3 (i int);
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;
select * from t1 left join t2 on (t1.i=t2.i);
select * from t1 natural left join t2 natural left join t3;
select * from t1 left join t2 on (t1.i=t2.i) left join t3 on (t2.i=t3.i);
select * from t3 natural right join t2;
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 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 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 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 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;
......@@ -899,7 +899,7 @@ void Item_str_func::left_right_max_length()
max_length=args[0]->max_length;
if (args[1]->const_item())
{
int length=(int) args[1]->val_int();
int length=(int) args[1]->val_int()*default_charset_info->mbmaxlen;
if (length <= 0)
max_length=0;
else
......@@ -992,7 +992,7 @@ void Item_func_substr::fix_length_and_dec()
}
if (arg_count == 3 && args[2]->const_item())
{
int32 length= (int32) args[2]->val_int();
int32 length= (int32) args[2]->val_int() * default_charset_info->mbmaxlen;
if (length <= 0)
max_length=0; /* purecov: inspected */
else
......
......@@ -1233,7 +1233,7 @@ void yyerror(const char *s)
{
NET *net=my_pthread_getspecific_ptr(NET*,THR_NET);
char *yytext=(char*) current_lex->tok_start;
if (!strcmp(s,"parse error"))
if (!strcmp(s,"parse error") || !strcmp(s,"syntax error"))
s=ER(ER_SYNTAX_ERROR);
net_printf(net,ER_PARSE_ERROR, s, yytext ? (char*) yytext : "",
current_lex->yylineno);
......@@ -3787,7 +3787,7 @@ replicating a LOAD DATA INFILE command",
(gptr*) &max_connect_errors, (gptr*) &max_connect_errors, 0, GET_ULONG,
REQUIRED_ARG, MAX_CONNECT_ERRORS, 1, ~0L, 0, 1, 0},
{"max_delayed_threads", OPT_MAX_DELAYED_THREADS,
"Don't start more than this number of threads to handle INSERT DELAYED statements. This option does not yet have effect (on TODO), unless it is set to zero, which means INSERT DELAYED is not used.",
"Don't start more than this number of threads to handle INSERT DELAYED statements. If set to zero, which means INSERT DELAYED is not used.",
(gptr*) &max_insert_delayed_threads, (gptr*) &max_insert_delayed_threads,
0, GET_ULONG, REQUIRED_ARG, 20, 0, 16384, 0, 1, 0},
{"max_heap_table_size", OPT_MAX_HEP_TABLE_SIZE,
......
......@@ -110,6 +110,7 @@ THD::THD():user_time(0),fatal_error(0),last_insert_id_used(0),
net.last_error[0]=0; // If error on boot
ull=0;
system_thread=cleanup_done=0;
peer_port= 0; // For SHOW PROCESSLIST
transaction.changed_tables = 0;
#ifdef __WIN__
real_id = 0;
......
......@@ -643,6 +643,9 @@ static TABLE *delayed_get_table(THD *thd,TABLE_LIST *table_list)
/* no match; create a new thread to handle the table */
if (!(tmp=find_handler(thd,table_list)))
{
/* Don't create more than max_insert_delayed_threads */
if (delayed_insert_threads >= max_insert_delayed_threads)
DBUG_RETURN(0);
thd->proc_info="Creating delayed handler";
pthread_mutex_lock(&LOCK_delayed_create);
if (!(tmp=find_handler(thd,table_list))) // Was just created
......@@ -1021,7 +1024,7 @@ extern "C" pthread_handler_decl(handle_delayed_insert,arg)
while (!thd->killed)
{
int error;
#if (defined(HAVE_BROKEN_COND_TIMEDWAIT) || defined(HAVE_LINUXTHREADS))
#if defined(HAVE_BROKEN_COND_TIMEDWAIT)
error=pthread_cond_wait(&di->cond,&di->mutex);
#else
error=pthread_cond_timedwait(&di->cond,&di->mutex,&abstime);
......
......@@ -210,9 +210,9 @@ static bool check_user(THD *thd,enum_server_command command, const char *user,
!(thd->client_capabilities &
CLIENT_LONG_PASSWORD),&ur);
DBUG_PRINT("info",
("Capabilities: %d packet_length: %ld Host: '%s' User: '%s' Using password: %s Access: %u db: '%s'",
("Capabilities: %d packet_length: %ld Host: '%s' Login user: '%s' Priv_user: '%s' Using password: %s Access: %u db: '%s'",
thd->client_capabilities, thd->max_client_packet_length,
thd->host_or_ip, thd->priv_user,
thd->host_or_ip, thd->user, thd->priv_user,
passwd[0] ? "yes": "no",
thd->master_access, thd->db ? thd->db : "*none*"));
if (thd->master_access & NO_ACCESS)
......@@ -517,7 +517,6 @@ check_connections(THD *thd)
DBUG_PRINT("info",("Host: %s",thd->host));
thd->host_or_ip= thd->host;
thd->ip= 0;
thd->peer_port= 0;
bzero((char*) &thd->remote,sizeof(struct sockaddr));
}
/* Ensure that wrong hostnames doesn't cause buffer overflows */
......@@ -3419,6 +3418,24 @@ void add_join_on(TABLE_LIST *b,Item *expr)
}
/*
Mark that we have a NATURAL JOIN between two tables
SYNOPSIS
add_join_natural()
a Table to do normal join with
b Do normal join with this table
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.
SELECT * FROM t1 NATURAL LEFT JOIN t2
<=>
SELECT * FROM t1 LEFT JOIN t2 ON (t1.i=t2.i and t1.j=t2.j ... )
*/
void add_join_natural(TABLE_LIST *a,TABLE_LIST *b)
{
b->natural_join=a;
......
......@@ -556,7 +556,17 @@ mysql_select(THD *thd,TABLE_LIST *tables,List<Item> &fields,COND *conds,
select_distinct= 0;
no_order= !order;
if (all_order_fields_used)
{
if (order && skip_sort_order)
{
/*
Force MySQL to read the table in sorted order to get result in
ORDER BY order.
*/
join.tmp_table_param.quick_group=0;
}
order=0;
}
join.group=1; // For end_write_group
}
else
......
......@@ -492,12 +492,6 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%right NOT
%right BINARY
/* These don't actually affect the way the query is really evaluated, but
they silence a few warnings for shift/reduce conflicts. */
%left ','
%left STRAIGHT_JOIN JOIN_SYM
%nonassoc CROSS INNER_SYM NATURAL LEFT RIGHT
%type <lex_str>
IDENT TEXT_STRING REAL_NUM FLOAT_NUM NUM LONG_NUM HEX_NUM LEX_HOSTNAME
ULONGLONG_NUM field_ident select_alias ident ident_or_text
......@@ -2116,7 +2110,7 @@ join_table_list:
| join_table_list ',' join_table_list { $$=$3; }
| join_table_list normal_join join_table_list { $$=$3; }
| join_table_list STRAIGHT_JOIN join_table_list
{ $$=$3 ; $$->straight=1; }
{ $$=$3 ; $1->next->straight=1; }
| join_table_list normal_join join_table_list ON expr
{ add_join_on($3,$5); $$=$3; }
| join_table_list normal_join join_table_list
......@@ -2140,9 +2134,13 @@ join_table_list:
USING '(' using_list ')'
{ add_join_on($5,$9); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; }
| join_table_list NATURAL LEFT opt_outer JOIN_SYM join_table_list
{ add_join_natural($1,$6); $6->outer_join|=JOIN_TYPE_LEFT; $$=$6; }
{
add_join_natural($1,$1->next);
$1->next->outer_join|=JOIN_TYPE_LEFT;
$$=$6;
}
| join_table_list RIGHT opt_outer JOIN_SYM join_table_list ON expr
{ add_join_on($1,$7); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$1; }
{ add_join_on($1,$7); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$5; }
| join_table_list RIGHT opt_outer JOIN_SYM join_table_list
{
SELECT_LEX *sel=Select;
......@@ -2150,11 +2148,15 @@ join_table_list:
sel->db2=$5->db; sel->table2=$5->alias;
}
USING '(' using_list ')'
{ add_join_on($1,$9); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$1; }
{ add_join_on($1,$9); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$5; }
| join_table_list NATURAL RIGHT opt_outer JOIN_SYM join_table_list
{ add_join_natural($6,$1); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$1; }
{
add_join_natural($1->next,$1);
$1->outer_join|=JOIN_TYPE_RIGHT;
$$=$6;
}
| join_table_list NATURAL JOIN_SYM join_table_list
{ add_join_natural($1,$4); $$=$4; };
{ add_join_natural($1,$1->next); $$=$4; };
normal_join:
JOIN_SYM {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment