Commit 0edc02d6 authored by unknown's avatar unknown

Fixed bug in counting open files when using many files

Fixed bug in JOIN


Docs/manual.texi:
  Changlog
mysql-test/r/join.result:
  New test for join bug
mysql-test/r/null_key.result:
  Fix result after fixing join bug
mysql-test/t/join.test:
  New test for join bug
mysys/my_open.c:
  Fixed bug in counting open files when using many files.
sql/sql_select.cc:
  Fixed join bug
parent e47b763f
......@@ -46853,6 +46853,9 @@ not yet 100% confident in this code.
@appendixsubsec Changes in release 3.23.43
@itemize @bullet
@item
Fixed unlikely bug, which returned not matching rows, in SELECT with
many tables and multi-column indexes and 'range' type.
@item
Fixed a unlikely core-dump bug when doing @code{EXPLAIN SELECT} when using
many tables and @code{ORDER BY}.
@item
......@@ -20,3 +20,5 @@ id catid stateid countyid
a
1
2
a a b
2 2 3
......@@ -11,7 +11,7 @@ t1 index NULL a 9 NULL 12 where used; Using index
table type possible_keys key key_len ref rows Extra
t1 range a,b a 9 NULL 3 where used; Using index
table type possible_keys key key_len ref rows Extra
t1 ref a,b b 4 const 2 where used
t1 range a,b a 9 NULL 2 where used; Using index
table type possible_keys key key_len ref rows Extra
t1 ref a,b a 5 const 3 where used; Using index
table type possible_keys key key_len ref rows Extra
......
......@@ -89,3 +89,26 @@ select t1.a from t1 as t1 left join t1 as t2 using (a) left join t1 as t3 using
--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);
drop table t1;
#
# Simple join test. This failed in 3.23.42, there should have been
# no matches, still three matches were found.
#
CREATE TABLE t1 (
a int(11) NOT NULL,
b int(11) NOT NULL,
PRIMARY KEY (a,b)
) TYPE=MyISAM;
INSERT INTO t1 VALUES (1,1),(1,2),(1,3),(1,4),(1,5),(1,6),(1,7),(2,3);
CREATE TABLE t2 (
a int(11) default NULL
) TYPE=MyISAM;
INSERT INTO t2 VALUES (2),(3);
SELECT t1.a,t2.a,b FROM t1,t2 WHERE t1.a=t2.a AND (t1.a=1 OR t1.a=2) AND b>=1 AND b<=3;
DROP TABLE t1, t2;
......@@ -75,8 +75,8 @@ int my_close(File fd, myf MyFlags)
pthread_mutex_destroy(&my_file_info[fd].mutex);
#endif
my_file_info[fd].type = UNOPEN;
my_file_opened--;
}
my_file_opened--;
pthread_mutex_unlock(&THR_LOCK_open);
DBUG_RETURN(err);
} /* my_close */
......@@ -96,9 +96,8 @@ File my_register_filename(File fd, const char *FileName, enum file_type
my_error(EE_OUT_OF_FILERESOURCES, MYF(ME_BELL+ME_WAITTANG),
FileName, my_errno);
return(-1);
#else
thread_safe_increment(my_file_opened,&THR_LOCK_open);
#endif
thread_safe_increment(my_file_opened,&THR_LOCK_open);
return(fd); /* safeguard */
}
pthread_mutex_lock(&THR_LOCK_open);
......
......@@ -2258,7 +2258,20 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
{
JOIN_TAB *tab=join->join_tab+i;
table_map current_map= tab->table->map;
bool use_quick_range=0;
used_tables|=current_map;
if (tab->type == JT_REF && tab->quick &&
tab->ref.key_length < tab->quick->max_used_key_length)
{
/* Range uses longer key; Use this instead of ref on key */
tab->type=JT_ALL;
use_quick_range=1;
tab->use_quick=1;
tab->ref.key_parts=0; // Don't use ref key.
join->best_positions[i].records_read=tab->quick->records;
}
COND *tmp=make_cond_for_table(cond,used_tables,current_map);
if (!tmp && tab->quick)
{ // Outer join
......@@ -2301,7 +2314,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
if (tab->const_keys && tab->table->reginfo.impossible_range)
DBUG_RETURN(1);
}
else if (tab->type == JT_ALL)
else if (tab->type == JT_ALL && ! use_quick_range)
{
if (tab->const_keys &&
tab->table->reginfo.impossible_range)
......@@ -2356,15 +2369,6 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
}
}
}
if (tab->type == JT_REF && sel->quick &&
tab->ref.key_length < sel->quick->max_used_key_length)
{
/* Range uses longer key; Use this instead of ref on key */
tab->type=JT_ALL;
tab->use_quick=1;
tab->ref.key_parts=0; // Don't use ref key.
join->best_positions[i].records_read=sel->quick->records;
}
}
}
}
......
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