summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorIgor Babaev <igor@askmonty.org>2013-01-13 02:11:22 -0800
committerIgor Babaev <igor@askmonty.org>2013-01-13 02:11:22 -0800
commit557303b831751e6b063fc6eef9814078e526214d (patch)
treea94144b2e1c2f9c4bafc741b768823657a5d492f /sql
parentbc75820fb7fa4c945c164dea9eac8e19058d7605 (diff)
parent7d5c56cb410bd0363e1c66c31149a79086584bbb (diff)
downloadmariadb-git-557303b831751e6b063fc6eef9814078e526214d.tar.gz
Merged the fix for bug mdev-4019.
Diffstat (limited to 'sql')
-rw-r--r--sql/sql_base.cc1
-rw-r--r--sql/sql_statistics.cc10
-rw-r--r--sql/sql_update.cc2
-rw-r--r--sql/table.h1
4 files changed, 12 insertions, 2 deletions
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index ca6b4e5430c..9f21b7f006b 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -4659,6 +4659,7 @@ open_and_process_table(THD *thd, LEX *lex, TABLE_LIST *tables,
Field **table_field_ptr= tables->table->field;
for ( ; *field_ptr; field_ptr++, table_field_ptr++)
(*table_field_ptr)->read_stats= (*field_ptr)->read_stats;
+ tables->table->stats_is_read= table_share->stats_cb.stats_is_read;
}
}
}
diff --git a/sql/sql_statistics.cc b/sql/sql_statistics.cc
index 618fd9b7799..70ba6897333 100644
--- a/sql/sql_statistics.cc
+++ b/sql/sql_statistics.cc
@@ -2499,6 +2499,8 @@ int read_statistics_for_table(THD *thd, TABLE *table, TABLE_LIST *stat_tables)
}
}
+ table->stats_is_read= TRUE;
+
DBUG_RETURN(0);
}
@@ -2557,6 +2559,8 @@ bool statistics_for_tables_is_needed(THD *thd, TABLE_LIST *tables)
table_share->stats_cb.stats_can_be_read &&
!table_share->stats_cb.stats_is_read)
return TRUE;
+ if (table_share->stats_cb.stats_is_read)
+ tl->table->stats_is_read= TRUE;
}
}
@@ -2616,6 +2620,8 @@ int read_statistics_for_tables_if_needed(THD *thd, TABLE_LIST *tables)
(void) read_statistics_for_table(thd, tl->table, stat_tables);
table_share->stats_cb.stats_is_read= TRUE;
}
+ if (table_share->stats_cb.stats_is_read)
+ tl->table->stats_is_read= TRUE;
}
}
@@ -3034,7 +3040,7 @@ void set_statistics_for_table(THD *thd, TABLE *table)
Use_stat_tables_mode use_stat_table_mode= get_use_stat_tables_mode(thd);
table->used_stat_records=
(use_stat_table_mode <= COMPLEMENTARY ||
- !stats_cb->stats_is_read || read_stats->cardinality_is_null) ?
+ !table->stats_is_read || read_stats->cardinality_is_null) ?
table->file->stats.records : read_stats->cardinality;
KEY *key_info, *key_info_end;
for (key_info= table->key_info, key_info_end= key_info+table->s->keys;
@@ -3042,7 +3048,7 @@ void set_statistics_for_table(THD *thd, TABLE *table)
{
key_info->is_statistics_from_stat_tables=
(use_stat_table_mode > COMPLEMENTARY &&
- stats_cb->stats_is_read &&
+ table->stats_is_read &&
key_info->read_stats->avg_frequency_is_inited() &&
key_info->read_stats->get_avg_frequency(0) > 0.5);
}
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index 518c2c70994..e320c1a3b86 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -32,6 +32,7 @@
#include "sql_view.h" // check_key_in_view
#include "sp_head.h"
#include "sql_trigger.h"
+#include "sql_statistics.h"
#include "probes_mysql.h"
#include "debug_sync.h"
#include "key.h" // is_key_used
@@ -393,6 +394,7 @@ int mysql_update(THD *thd,
#endif
/* Update the table->file->stats.records number */
table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);
+ set_statistics_for_table(thd, table);
select= make_select(table, 0, 0, conds, 0, &error);
if (error || !limit || thd->is_error() ||
diff --git a/sql/table.h b/sql/table.h
index ecad83cff22..0625d791b49 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -1196,6 +1196,7 @@ public:
bool no_partitions_used; /* If true, all partitions have been pruned away */
#endif
uint max_keys; /* Size of allocated key_info array. */
+ bool stats_is_read; /* Persistent statistics is read for the table */
MDL_ticket *mdl_ticket;
void init(THD *thd, TABLE_LIST *tl);