List:Internals« Previous MessageNext Message »
From:Heikki Tuuri Date:August 24 2005 2:27pm
Subject:bk commit into 4.0 tree (heikki:1.2137) BUG#12779
View as plain text  
Below is the list of changes that have just been committed into a local
4.0 repository of heikki. When heikki does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.2137 05/08/24 17:27:46 heikki@stripped +1 -0
  ha_innodb.cc:
    Fix bug #12779 : never give a row count estimate of 0 to the MySQL query optimizer, as then left join optimizer may beleive it KNOWS that the table is empty; note that this fix may change query optimization of many other queries where one table is empty; note that the proper fix would be to make the query optimizer to know that the row count estimates it receives really are just estimates, it cannot assume they are certain

  sql/ha_innodb.cc
    1.235 05/08/24 17:27:34 heikki@stripped +25 -1
    Fix bug #12779 : never give a row count estimate of 0 to the MySQL query optimizer, as then left join optimizer may beleive it KNOWS that the table is empty; note that this fix may change query optimization of many other queries where one table is empty; note that the proper fix would be to make the query optimizer to know that the row count estimates it receives really are just estimates, it cannot assume they are certain

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	heikki
# Host:	hundin.mysql.fi
# Root:	/home/heikki/mysql-4.0

--- 1.234/sql/ha_innodb.cc	2005-08-03 18:47:31 +03:00
+++ 1.235/sql/ha_innodb.cc	2005-08-24 17:27:34 +03:00
@@ -4109,6 +4109,7 @@
 	dict_table_t*	ib_table;
 	dict_index_t*	index;
 	ha_rows		rec_per_key;
+	ib_longlong	n_rows;
 	ulong		j;
 	ulong		i;
 
@@ -4151,7 +4152,30 @@
  	}
 
 	if (flag & HA_STATUS_VARIABLE) {
-    		records = (ha_rows)ib_table->stat_n_rows;
+		n_rows = ib_table->stat_n_rows;
+
+		/* Because we do not protect stat_n_rows by any mutex in a
+		delete, it is theoretically possible that the value can be
+		smaller than zero! TODO: fix this race.
+
+		The MySQL optimizer seems to assume in a left join that n_rows
+		is an accurate estimate if it is zero. Of course, it is not,
+		since we do not have any locks on the rows yet at this phase.
+		Since SHOW TABLE STATUS seems to call this function with the
+		HA_STATUS_TIME flag set, while the left join optizer does not
+		set that flag, we add one to a zero value if the flag is not
+		set. That way SHOW TABLE STATUS will show the best estimate,
+		while the optimizer never sees the table empty. */
+
+		if (n_rows < 0) {
+			n_rows = 0;
+		}
+
+		if (n_rows == 0 && !(flag & HA_STATUS_TIME)) {
+			n_rows++;
+		}
+
+    		records = (ha_rows)n_rows;
     		deleted = 0;
     		data_file_length = ((ulonglong)
 				ib_table->stat_clustered_index_size)
Thread
bk commit into 4.0 tree (heikki:1.2137) BUG#12779Heikki Tuuri24 Aug