2011-03-31 16:26:51 +03:00
|
|
|
/* Copyright (C) 2010-2011 Monty Program Ab & Oleksandr Byelkin
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; version 2 of the License.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
Update FSF address
This commit is based on the work of Michal Schorm, rebased on the
earliest MariaDB version.
Th command line used to generate this diff was:
find ./ -type f \
-exec sed -i -e 's/Foundation, Inc., 59 Temple Place, Suite 330, Boston, /Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, /g' {} \; \
-exec sed -i -e 's/Foundation, Inc. 59 Temple Place.* Suite 330, Boston, /Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, /g' {} \; \
-exec sed -i -e 's/MA.*.....-1307.*USA/MA 02110-1335 USA/g' {} \; \
-exec sed -i -e 's/Foundation, Inc., 59 Temple/Foundation, Inc., 51 Franklin/g' {} \; \
-exec sed -i -e 's/Place, Suite 330, Boston, MA.*02111-1307.*USA/Street, Fifth Floor, Boston, MA 02110-1335 USA/g' {} \; \
-exec sed -i -e 's/MA.*.....-1307/MA 02110-1335/g' {} \;
2019-05-10 20:49:46 +03:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
|
2010-07-10 13:37:30 +03:00
|
|
|
|
2017-06-18 06:42:16 +03:00
|
|
|
#include "mariadb.h"
|
2011-04-25 17:22:25 +02:00
|
|
|
#include "sql_base.h"
|
2010-07-10 13:37:30 +03:00
|
|
|
#include "sql_select.h"
|
2011-04-25 17:22:25 +02:00
|
|
|
#include "sql_expression_cache.h"
|
2010-07-10 13:37:30 +03:00
|
|
|
|
2011-07-28 17:10:29 +03:00
|
|
|
/**
|
|
|
|
Minimum hit ration to proceed on disk if in memory table overflowed.
|
|
|
|
hit_rate = hit / (miss + hit);
|
|
|
|
*/
|
|
|
|
#define EXPCACHE_MIN_HIT_RATE_FOR_DISK_TABLE 0.7
|
|
|
|
/**
|
|
|
|
Minimum hit ratio to keep in memory table (do not switch cache off)
|
|
|
|
hit_rate = hit / (miss + hit);
|
|
|
|
*/
|
|
|
|
#define EXPCACHE_MIN_HIT_RATE_FOR_MEM_TABLE 0.2
|
2011-08-12 13:54:41 +03:00
|
|
|
/**
|
|
|
|
Number of cache miss to check hit ratio (maximum cache performance
|
|
|
|
impact in the case when the cache is not applicable)
|
|
|
|
*/
|
|
|
|
#define EXPCACHE_CHECK_HIT_RATIO_AFTER 200
|
2011-07-28 17:10:29 +03:00
|
|
|
|
2010-07-10 13:37:30 +03:00
|
|
|
/*
|
|
|
|
Expression cache is used only for caching subqueries now, so its statistic
|
|
|
|
variables we call subquery_cache*.
|
|
|
|
*/
|
2010-10-27 06:03:59 +03:00
|
|
|
ulong subquery_cache_miss, subquery_cache_hit;
|
2010-07-10 13:37:30 +03:00
|
|
|
|
|
|
|
Expression_cache_tmptable::Expression_cache_tmptable(THD *thd,
|
2011-07-19 23:19:10 +03:00
|
|
|
List<Item> &dependants,
|
|
|
|
Item *value)
|
2015-07-01 20:03:29 +03:00
|
|
|
:cache_table(NULL), table_thd(thd), tracker(NULL), items(dependants), val(value),
|
2011-07-28 17:10:29 +03:00
|
|
|
hit(0), miss(0), inited (0)
|
2010-07-10 13:37:30 +03:00
|
|
|
{
|
|
|
|
DBUG_ENTER("Expression_cache_tmptable::Expression_cache_tmptable");
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-08-12 13:54:41 +03:00
|
|
|
/**
|
|
|
|
Disable cache
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Expression_cache_tmptable::disable_cache()
|
|
|
|
{
|
2011-10-19 22:52:43 +02:00
|
|
|
if (cache_table->file->inited)
|
|
|
|
cache_table->file->ha_index_end();
|
2011-08-12 13:54:41 +03:00
|
|
|
free_tmp_table(table_thd, cache_table);
|
|
|
|
cache_table= NULL;
|
2015-07-01 20:03:29 +03:00
|
|
|
update_tracker();
|
|
|
|
if (tracker)
|
2022-04-26 23:03:34 +03:00
|
|
|
tracker->detach_from_cache();
|
2011-08-12 13:54:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-10 13:37:30 +03:00
|
|
|
/**
|
|
|
|
Field enumerator for TABLE::add_tmp_key
|
|
|
|
|
|
|
|
@param arg reference variable with current field number
|
|
|
|
|
|
|
|
@return field number
|
|
|
|
*/
|
|
|
|
|
|
|
|
static uint field_enumerator(uchar *arg)
|
|
|
|
{
|
|
|
|
return ((uint*)arg)[0]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Initialize temporary table and auxiliary structures for the expression
|
|
|
|
cache
|
|
|
|
|
|
|
|
@details
|
|
|
|
The function creates a temporary table for the expression cache, defines
|
|
|
|
the search index and initializes auxiliary search structures used to check
|
|
|
|
whether a given set of of values of the expression parameters is in some
|
|
|
|
cache entry.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Expression_cache_tmptable::init()
|
|
|
|
{
|
2011-07-19 23:19:10 +03:00
|
|
|
List_iterator<Item> li(items);
|
|
|
|
Item_iterator_list it(li);
|
2010-07-10 13:37:30 +03:00
|
|
|
uint field_counter;
|
2018-01-07 18:03:44 +02:00
|
|
|
LEX_CSTRING cache_table_name= { STRING_WITH_LEN("subquery-cache-table") };
|
2010-07-10 13:37:30 +03:00
|
|
|
DBUG_ENTER("Expression_cache_tmptable::init");
|
|
|
|
DBUG_ASSERT(!inited);
|
|
|
|
inited= TRUE;
|
2010-08-09 13:00:58 +03:00
|
|
|
cache_table= NULL;
|
2010-07-10 13:37:30 +03:00
|
|
|
|
2011-07-19 23:19:10 +03:00
|
|
|
if (items.elements == 0)
|
2010-08-09 13:00:58 +03:00
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("All parameters were removed by optimizer."));
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
2010-07-10 13:37:30 +03:00
|
|
|
|
2011-07-19 23:19:10 +03:00
|
|
|
/* add result field */
|
|
|
|
items.push_front(val);
|
|
|
|
|
2010-07-10 13:37:30 +03:00
|
|
|
cache_table_param.init();
|
|
|
|
/* dependent items and result */
|
2023-02-26 18:33:10 +02:00
|
|
|
cache_table_param.field_count= cache_table_param.func_count= items.elements;
|
2010-07-10 13:37:30 +03:00
|
|
|
/* postpone table creation to index description */
|
|
|
|
cache_table_param.skip_create_table= 1;
|
|
|
|
|
|
|
|
if (!(cache_table= create_tmp_table(table_thd, &cache_table_param,
|
|
|
|
items, (ORDER*) NULL,
|
2011-07-19 23:19:10 +03:00
|
|
|
FALSE, TRUE,
|
2011-04-25 17:22:25 +02:00
|
|
|
((table_thd->variables.option_bits |
|
2010-07-10 13:37:30 +03:00
|
|
|
TMP_TABLE_ALL_COLUMNS) &
|
2011-04-25 17:22:25 +02:00
|
|
|
~TMP_TABLE_FORCE_MYISAM),
|
2010-07-10 13:37:30 +03:00
|
|
|
HA_POS_ERROR,
|
2018-01-07 18:03:44 +02:00
|
|
|
&cache_table_name,
|
2011-05-30 21:35:32 +03:00
|
|
|
TRUE)))
|
2010-07-10 13:37:30 +03:00
|
|
|
{
|
|
|
|
DBUG_PRINT("error", ("create_tmp_table failed, caching switched off"));
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cache_table->s->db_type() != heap_hton)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("error", ("we need only heap table"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2011-07-19 23:19:10 +03:00
|
|
|
field_counter= 1;
|
2010-07-10 13:37:30 +03:00
|
|
|
|
|
|
|
if (cache_table->alloc_keys(1) ||
|
2010-11-02 10:47:36 +01:00
|
|
|
cache_table->add_tmp_key(0, items.elements - 1, &field_enumerator,
|
|
|
|
(uchar*)&field_counter, TRUE) ||
|
2010-07-10 13:37:30 +03:00
|
|
|
ref.tmp_table_index_lookup_init(table_thd, cache_table->key_info, it,
|
2011-07-19 23:19:10 +03:00
|
|
|
TRUE, 1 /* skip result field*/))
|
2010-07-10 13:37:30 +03:00
|
|
|
{
|
|
|
|
DBUG_PRINT("error", ("creating index failed"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
cache_table->s->keys= 1;
|
|
|
|
ref.null_rejecting= 1;
|
2023-10-24 23:50:26 +02:00
|
|
|
ref.const_ref_part_map= 0;
|
2010-07-10 13:37:30 +03:00
|
|
|
ref.disable_cache= FALSE;
|
|
|
|
ref.has_record= 0;
|
|
|
|
ref.use_count= 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (open_tmp_table(cache_table))
|
|
|
|
{
|
|
|
|
DBUG_PRINT("error", ("Opening (creating) temporary table failed"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2015-08-20 15:24:13 +03:00
|
|
|
if (!(cached_result= new (table_thd->mem_root)
|
|
|
|
Item_field(table_thd, cache_table->field[0])))
|
2010-07-10 13:37:30 +03:00
|
|
|
{
|
|
|
|
DBUG_PRINT("error", ("Creating Item_field failed"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2015-07-01 20:03:29 +03:00
|
|
|
update_tracker();
|
2010-07-10 13:37:30 +03:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
|
|
|
|
error:
|
2011-08-12 13:54:41 +03:00
|
|
|
disable_cache();
|
2010-07-10 13:37:30 +03:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Expression_cache_tmptable::~Expression_cache_tmptable()
|
|
|
|
{
|
2011-08-12 11:23:50 +03:00
|
|
|
/* Add accumulated statistics */
|
|
|
|
statistic_add(subquery_cache_miss, miss, &LOCK_status);
|
|
|
|
statistic_add(subquery_cache_hit, hit, &LOCK_status);
|
|
|
|
|
2010-07-10 13:37:30 +03:00
|
|
|
if (cache_table)
|
2011-08-12 13:54:41 +03:00
|
|
|
disable_cache();
|
2015-03-25 18:27:10 +01:00
|
|
|
else
|
|
|
|
{
|
2015-07-01 20:03:29 +03:00
|
|
|
update_tracker();
|
2022-04-26 23:03:34 +03:00
|
|
|
if (tracker)
|
|
|
|
tracker->detach_from_cache();
|
2015-07-01 20:03:29 +03:00
|
|
|
tracker= NULL;
|
2015-03-25 18:27:10 +01:00
|
|
|
}
|
2010-07-10 13:37:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Check if a given set of parameters of the expression is in the cache
|
|
|
|
|
|
|
|
@param [out] value the expression value found in the cache if any
|
|
|
|
|
|
|
|
@details
|
|
|
|
For a given set of the parameters of the expression the function
|
|
|
|
checks whether it can be found in some entry of the cache. If so
|
|
|
|
the function returns the result of the expression extracted from
|
|
|
|
the cache.
|
|
|
|
|
|
|
|
@retval Expression_cache::HIT if the set of parameters is in the cache
|
|
|
|
@retval Expression_cache::MISS - otherwise
|
|
|
|
*/
|
|
|
|
|
|
|
|
Expression_cache::result Expression_cache_tmptable::check_value(Item **value)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
DBUG_ENTER("Expression_cache_tmptable::check_value");
|
|
|
|
|
|
|
|
if (cache_table)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("status: %u has_record %u",
|
|
|
|
(uint)cache_table->status, (uint)ref.has_record));
|
|
|
|
if ((res= join_read_key2(table_thd, NULL, cache_table, &ref)) == 1)
|
|
|
|
DBUG_RETURN(ERROR);
|
2011-08-12 11:23:50 +03:00
|
|
|
|
2010-09-08 09:26:17 +03:00
|
|
|
if (res)
|
2010-07-10 13:37:30 +03:00
|
|
|
{
|
2011-08-12 13:54:41 +03:00
|
|
|
if (((++miss) == EXPCACHE_CHECK_HIT_RATIO_AFTER) &&
|
|
|
|
((double)hit / ((double)hit + miss)) <
|
|
|
|
EXPCACHE_MIN_HIT_RATE_FOR_MEM_TABLE)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info",
|
|
|
|
("Early check: hit rate is not so good to keep the cache"));
|
|
|
|
disable_cache();
|
|
|
|
}
|
|
|
|
|
2010-07-10 13:37:30 +03:00
|
|
|
DBUG_RETURN(MISS);
|
|
|
|
}
|
|
|
|
|
2011-07-28 17:10:29 +03:00
|
|
|
hit++;
|
2010-07-10 13:37:30 +03:00
|
|
|
*value= cached_result;
|
|
|
|
DBUG_RETURN(Expression_cache::HIT);
|
|
|
|
}
|
|
|
|
DBUG_RETURN(Expression_cache::MISS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Put a new entry into the expression cache
|
|
|
|
|
|
|
|
@param value the result of the expression to be put into the cache
|
|
|
|
|
|
|
|
@details
|
|
|
|
The function evaluates 'value' and puts the result into the cache as the
|
|
|
|
result of the expression for the current set of parameters.
|
|
|
|
|
|
|
|
@retval FALSE OK
|
|
|
|
@retval TRUE Error
|
|
|
|
*/
|
|
|
|
|
|
|
|
my_bool Expression_cache_tmptable::put_value(Item *value)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
DBUG_ENTER("Expression_cache_tmptable::put_value");
|
|
|
|
DBUG_ASSERT(inited);
|
|
|
|
|
|
|
|
if (!cache_table)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("No table so behave as we successfully put value"));
|
|
|
|
DBUG_RETURN(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
*(items.head_ref())= value;
|
2024-02-08 12:17:02 +07:00
|
|
|
fill_record(table_thd, cache_table, cache_table->field, items, true, true,
|
|
|
|
true);
|
2018-04-04 12:16:12 +03:00
|
|
|
if (unlikely(table_thd->is_error()))
|
MDEV-9101 Limit size of created disk temporary files and tables
Two new variables added:
- max_tmp_space_usage : Limits the the temporary space allowance per user
- max_total_tmp_space_usage: Limits the temporary space allowance for
all users.
New status variables: tmp_space_used & max_tmp_space_used
New field in information_schema.process_list: TMP_SPACE_USED
The temporary space is counted for:
- All SQL level temporary files. This includes files for filesort,
transaction temporary space, analyze, binlog_stmt_cache etc.
It does not include engine internal temporary files used for repair,
alter table, index pre sorting etc.
- All internal on disk temporary tables created as part of resolving a
SELECT, multi-source update etc.
Special cases:
- When doing a commit, the last flush of the binlog_stmt_cache
will not cause an error even if the temporary space limit is exceeded.
This is to avoid giving errors on commit. This means that a user
can temporary go over the limit with up to binlog_stmt_cache_size.
Noteworthy issue:
- One has to be careful when using small values for max_tmp_space_limit
together with binary logging and with non transactional tables.
If a the binary log entry for the query is bigger than
binlog_stmt_cache_size and one hits the limit of max_tmp_space_limit
when flushing the entry to disk, the query will abort and the
binary log will not contain the last changes to the table.
This will also stop the slave!
This is also true for all Aria tables as Aria cannot do rollback
(except in case of crashes)!
One way to avoid it is to use @@binlog_format=statement for
queries that updates a lot of rows.
Implementation:
- All writes to temporary files or internal temporary tables, that
increases the file size, are routed through temp_file_size_cb_func()
which updates and checks the temp space usage.
- Most of the temporary file monitoring is done inside IO_CACHE.
Temporary file monitoring is done inside the Aria engine.
- MY_TRACK and MY_TRACK_WITH_LIMIT are new flags for ini_io_cache().
MY_TRACK means that we track the file usage. TRACK_WITH_LIMIT means
that we track the file usage and we give an error if the limit is
breached. This is used to not give an error on commit when
binlog_stmp_cache is flushed.
- global_tmp_space_used contains the total tmp space used so far.
This is needed quickly check against max_total_tmp_space_usage.
- Temporary space errors are using EE_LOCAL_TMP_SPACE_FULL and
handler errors are using HA_ERR_LOCAL_TMP_SPACE_FULL.
This is needed until we move general errors to it's own error space
so that they cannot conflict with system error numbers.
- Return value of my_chsize() and mysql_file_chsize() has changed
so that -1 is returned in the case my_chsize() could not decrease
the file size (very unlikely and will not happen on modern systems).
All calls to _chsize() are updated to check for > 0 as the error
condition.
- At the destruction of THD we check that THD::tmp_file_space == 0
- At server end we check that global_tmp_space_used == 0
- As a precaution against errors in the tmp_space_used code, one can set
max_tmp_space_usage and max_total_tmp_space_usage to 0 to disable
the tmp space quota errors.
- truncate_io_cache() function added.
- Aria tables using static or dynamic row length are registered in 8K
increments to avoid some calls to update_tmp_file_size().
Other things:
- Ensure that all handler errors are registered. Before, some engine
errors could be printed as "Unknown error".
- Fixed bug in filesort() that causes a assert if there was an error
when writing to the temporay file.
- Fixed that compute_window_func() now takes into account write errors.
- In case of parallel replication, rpl_group_info::cleanup_context()
could call trans_rollback() with thd->error set, which would cause
an assert. Fixed by resetting the error before calling trans_rollback().
- Fixed bug in subselect3.inc which caused following test to use
heap tables with low value for max_heap_table_size
- Fixed bug in sql_expression_cache where it did not overflow
heap table to Aria table.
- Added Max_tmp_disk_space_used to slow query log.
- Fixed some bugs in log_slow_innodb.test
2024-03-14 17:59:00 +01:00
|
|
|
goto err2;
|
2010-07-10 13:37:30 +03:00
|
|
|
|
2018-04-04 12:16:12 +03:00
|
|
|
if (unlikely((error=
|
|
|
|
cache_table->file->ha_write_tmp_row(cache_table->record[0]))))
|
2010-07-10 13:37:30 +03:00
|
|
|
{
|
|
|
|
/* create_myisam_from_heap will generate error if needed */
|
MDEV-9101 Limit size of created disk temporary files and tables
Two new variables added:
- max_tmp_space_usage : Limits the the temporary space allowance per user
- max_total_tmp_space_usage: Limits the temporary space allowance for
all users.
New status variables: tmp_space_used & max_tmp_space_used
New field in information_schema.process_list: TMP_SPACE_USED
The temporary space is counted for:
- All SQL level temporary files. This includes files for filesort,
transaction temporary space, analyze, binlog_stmt_cache etc.
It does not include engine internal temporary files used for repair,
alter table, index pre sorting etc.
- All internal on disk temporary tables created as part of resolving a
SELECT, multi-source update etc.
Special cases:
- When doing a commit, the last flush of the binlog_stmt_cache
will not cause an error even if the temporary space limit is exceeded.
This is to avoid giving errors on commit. This means that a user
can temporary go over the limit with up to binlog_stmt_cache_size.
Noteworthy issue:
- One has to be careful when using small values for max_tmp_space_limit
together with binary logging and with non transactional tables.
If a the binary log entry for the query is bigger than
binlog_stmt_cache_size and one hits the limit of max_tmp_space_limit
when flushing the entry to disk, the query will abort and the
binary log will not contain the last changes to the table.
This will also stop the slave!
This is also true for all Aria tables as Aria cannot do rollback
(except in case of crashes)!
One way to avoid it is to use @@binlog_format=statement for
queries that updates a lot of rows.
Implementation:
- All writes to temporary files or internal temporary tables, that
increases the file size, are routed through temp_file_size_cb_func()
which updates and checks the temp space usage.
- Most of the temporary file monitoring is done inside IO_CACHE.
Temporary file monitoring is done inside the Aria engine.
- MY_TRACK and MY_TRACK_WITH_LIMIT are new flags for ini_io_cache().
MY_TRACK means that we track the file usage. TRACK_WITH_LIMIT means
that we track the file usage and we give an error if the limit is
breached. This is used to not give an error on commit when
binlog_stmp_cache is flushed.
- global_tmp_space_used contains the total tmp space used so far.
This is needed quickly check against max_total_tmp_space_usage.
- Temporary space errors are using EE_LOCAL_TMP_SPACE_FULL and
handler errors are using HA_ERR_LOCAL_TMP_SPACE_FULL.
This is needed until we move general errors to it's own error space
so that they cannot conflict with system error numbers.
- Return value of my_chsize() and mysql_file_chsize() has changed
so that -1 is returned in the case my_chsize() could not decrease
the file size (very unlikely and will not happen on modern systems).
All calls to _chsize() are updated to check for > 0 as the error
condition.
- At the destruction of THD we check that THD::tmp_file_space == 0
- At server end we check that global_tmp_space_used == 0
- As a precaution against errors in the tmp_space_used code, one can set
max_tmp_space_usage and max_total_tmp_space_usage to 0 to disable
the tmp space quota errors.
- truncate_io_cache() function added.
- Aria tables using static or dynamic row length are registered in 8K
increments to avoid some calls to update_tmp_file_size().
Other things:
- Ensure that all handler errors are registered. Before, some engine
errors could be printed as "Unknown error".
- Fixed bug in filesort() that causes a assert if there was an error
when writing to the temporay file.
- Fixed that compute_window_func() now takes into account write errors.
- In case of parallel replication, rpl_group_info::cleanup_context()
could call trans_rollback() with thd->error set, which would cause
an assert. Fixed by resetting the error before calling trans_rollback().
- Fixed bug in subselect3.inc which caused following test to use
heap tables with low value for max_heap_table_size
- Fixed bug in sql_expression_cache where it did not overflow
heap table to Aria table.
- Added Max_tmp_disk_space_used to slow query log.
- Fixed some bugs in log_slow_innodb.test
2024-03-14 17:59:00 +01:00
|
|
|
if (cache_table->file->is_fatal_error(error, HA_CHECK_DUP) &&
|
|
|
|
error != HA_ERR_RECORD_FILE_FULL)
|
2010-07-10 13:37:30 +03:00
|
|
|
goto err;
|
2011-07-28 17:10:29 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
double hit_rate= ((double)hit / ((double)hit + miss));
|
|
|
|
DBUG_ASSERT(miss > 0);
|
|
|
|
if (hit_rate < EXPCACHE_MIN_HIT_RATE_FOR_MEM_TABLE)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("hit rate is not so good to keep the cache"));
|
2011-08-12 13:54:41 +03:00
|
|
|
disable_cache();
|
2011-07-28 17:10:29 +03:00
|
|
|
DBUG_RETURN(FALSE);
|
|
|
|
}
|
|
|
|
else if (hit_rate < EXPCACHE_MIN_HIT_RATE_FOR_DISK_TABLE)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("hit rate is not so good to go to disk"));
|
|
|
|
if (cache_table->file->ha_delete_all_rows() ||
|
|
|
|
cache_table->file->ha_write_tmp_row(cache_table->record[0]))
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (create_internal_tmp_table_from_heap(table_thd, cache_table,
|
|
|
|
cache_table_param.start_recinfo,
|
|
|
|
&cache_table_param.recinfo,
|
2013-07-16 09:22:17 +04:00
|
|
|
error, 1, NULL))
|
2024-04-06 12:07:49 +03:00
|
|
|
goto err2;
|
2011-07-28 17:10:29 +03:00
|
|
|
}
|
|
|
|
}
|
2010-07-10 13:37:30 +03:00
|
|
|
}
|
|
|
|
cache_table->status= 0; /* cache_table->record contains an existed record */
|
|
|
|
ref.has_record= TRUE; /* the same as above */
|
|
|
|
DBUG_PRINT("info", ("has_record: TRUE status: 0"));
|
|
|
|
|
|
|
|
DBUG_RETURN(FALSE);
|
|
|
|
|
|
|
|
err:
|
2024-04-06 12:07:49 +03:00
|
|
|
cache_table->file->print_error(error, MYF(0));
|
|
|
|
err2:
|
2011-08-12 13:54:41 +03:00
|
|
|
disable_cache();
|
2010-07-10 13:37:30 +03:00
|
|
|
DBUG_RETURN(TRUE);
|
|
|
|
}
|
2010-09-06 15:34:24 +03:00
|
|
|
|
|
|
|
|
|
|
|
void Expression_cache_tmptable::print(String *str, enum_query_type query_type)
|
|
|
|
{
|
2011-07-19 23:19:10 +03:00
|
|
|
List_iterator<Item> li(items);
|
|
|
|
Item *item;
|
2010-09-06 15:34:24 +03:00
|
|
|
bool is_first= TRUE;
|
|
|
|
|
|
|
|
str->append('<');
|
2011-07-19 23:19:10 +03:00
|
|
|
li++; // skip result field
|
2010-09-06 15:34:24 +03:00
|
|
|
while ((item= li++))
|
|
|
|
{
|
|
|
|
if (!is_first)
|
|
|
|
str->append(',');
|
2011-07-19 23:19:10 +03:00
|
|
|
item->print(str, query_type);
|
2010-09-06 15:34:24 +03:00
|
|
|
is_first= FALSE;
|
|
|
|
}
|
|
|
|
str->append('>');
|
|
|
|
}
|
2015-03-25 18:27:10 +01:00
|
|
|
|
|
|
|
|
2015-07-01 20:03:29 +03:00
|
|
|
const char *Expression_cache_tracker::state_str[3]=
|
|
|
|
{"uninitialized", "disabled", "enabled"};
|