Skip to content

Commit

Permalink
Simplify test if we can use table in query cache
Browse files Browse the repository at this point in the history
- Added TABLE_SHARE->not_usable_by_query_cache
- Moved TABLE->no_replicate to TABLE_SHARE->no_replicate as it's same for
  all TABLE instances
- Renamed TABLE_SHARE->cached_row_logging_check to can_do_row_logging
  • Loading branch information
montywi authored and vuvova committed Aug 23, 2017
1 parent 1ed605e commit 8bfda2f
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 63 deletions.
2 changes: 1 addition & 1 deletion sql/handler.cc
Expand Up @@ -5683,7 +5683,7 @@ bool handler::check_table_binlog_row_based_internal(bool binlog_row)
}
#endif

return (table->s->cached_row_logging_check &&
return (table->s->can_do_row_logging &&
thd->is_current_stmt_binlog_format_row() &&
/*
Wsrep partially enables binary logging if it have not been
Expand Down
2 changes: 1 addition & 1 deletion sql/sql_base.cc
Expand Up @@ -8642,7 +8642,7 @@ open_log_table(THD *thd, TABLE_LIST *one_table, Open_tables_backup *backup)
DBUG_ASSERT(table->s->table_category == TABLE_CATEGORY_LOG);
/* Make sure all columns get assigned to a default value */
table->use_all_columns();
DBUG_ASSERT(table->no_replicate);
DBUG_ASSERT(table->s->no_replicate);
}
else
thd->restore_backup_open_tables_state(backup);
Expand Down
58 changes: 26 additions & 32 deletions sql/sql_cache.cc
Expand Up @@ -4050,41 +4050,35 @@ Query_cache::process_and_count_tables(THD *thd, TABLE_LIST *tables_used,
tables_used->view_name.str,
tables_used->view_db.str));
*tables_type|= HA_CACHE_TBL_NONTRANSACT;
continue;
}
else
if (tables_used->derived)
{
if (tables_used->derived)
{
DBUG_PRINT("qcache", ("table: %s", tables_used->alias));
table_count--;
DBUG_PRINT("qcache", ("derived table skipped"));
continue;
}
DBUG_PRINT("qcache", ("table: %s db: %s type: %u",
tables_used->table->s->table_name.str,
tables_used->table->s->db.str,
tables_used->table->s->db_type()->db_type));
*tables_type|= tables_used->table->file->table_cache_type();
DBUG_PRINT("qcache", ("table: %s", tables_used->alias));
table_count--;
DBUG_PRINT("qcache", ("derived table skipped"));
continue;
}

/*
table_alias_charset used here because it depends of
lower_case_table_names variable
*/
table_count+= tables_used->table->file->
count_query_cache_dependant_tables(tables_type);

if (tables_used->table->s->tmp_table != NO_TMP_TABLE ||
(*tables_type & HA_CACHE_TBL_NOCACHE) ||
(tables_used->db_length == 5 &&
my_strnncoll(table_alias_charset,
(uchar*)tables_used->table->s->table_cache_key.str, 6,
(uchar*)"mysql",6) == 0))
{
DBUG_PRINT("qcache",
("select not cacheable: temporary, system or "
"other non-cacheable table(s)"));
DBUG_RETURN(0);
}
DBUG_PRINT("qcache", ("table: %s db: %s type: %u",
tables_used->table->s->table_name.str,
tables_used->table->s->db.str,
tables_used->table->s->db_type()->db_type));
*tables_type|= tables_used->table->file->table_cache_type();

/*
table_alias_charset used here because it depends of
lower_case_table_names variable
*/
table_count+= tables_used->table->file->
count_query_cache_dependant_tables(tables_type);

if (tables_used->table->s->not_usable_by_query_cache)
{
DBUG_PRINT("qcache",
("select not cacheable: temporary, system or "
"other non-cacheable table(s)"));
DBUG_RETURN(0);
}
}
DBUG_RETURN(table_count);
Expand Down
2 changes: 1 addition & 1 deletion sql/sql_class.cc
Expand Up @@ -5895,7 +5895,7 @@ int THD::decide_logging_format(TABLE_LIST *tables)
DBUG_PRINT("info", ("table: %s; ha_table_flags: 0x%llx",
table->table_name, flags));

if (table->table->no_replicate)
if (table->table->s->no_replicate)
{
/*
The statement uses a table that is not replicated.
Expand Down
37 changes: 19 additions & 18 deletions sql/table.cc
Expand Up @@ -328,8 +328,13 @@ TABLE_SHARE *alloc_table_share(const char *db, const char *table_name,
share->normalized_path.length= path_length;
share->table_category= get_table_category(& share->db, & share->table_name);
share->open_errno= ENOENT;
/* The following will be fixed in open_table_from_share */
share->cached_row_logging_check= 1;
/* The following will be updated in open_table_from_share */
share->can_do_row_logging= 1;
if (share->table_category == TABLE_CATEGORY_LOG)
share->no_replicate= 1;
if (my_strnncoll(table_alias_charset, (uchar*) db, 6,
(const uchar*) "mysql", 6) == 0)
share->not_usable_by_query_cache= 1;

init_sql_alloc(&share->stats_cb.mem_root, TABLE_ALLOC_BLOCK_SIZE, 0, MYF(0));

Expand Down Expand Up @@ -402,8 +407,8 @@ void init_tmp_table_share(THD *thd, TABLE_SHARE *share, const char *key,
share->normalized_path.str= (char*) path;
share->path.length= share->normalized_path.length= strlen(path);
share->frm_version= FRM_VER_CURRENT;

share->cached_row_logging_check= 0; // No row logging
share->not_usable_by_query_cache= 1;
share->can_do_row_logging= 0; // No row logging

/*
table_map_id is also used for MERGE tables to suppress repeated
Expand Down Expand Up @@ -3379,24 +3384,20 @@ enum open_frm_error open_table_from_share(THD *thd, TABLE_SHARE *share,

outparam->mark_columns_used_by_check_constraints();

if (share->table_category == TABLE_CATEGORY_LOG)
{
outparam->no_replicate= TRUE;
}
else if (outparam->file)
if (db_stat)
{
/* Set some flags in share on first open of the table */
handler::Table_flags flags= outparam->file->ha_table_flags();
outparam->no_replicate= ! MY_TEST(flags & (HA_BINLOG_STMT_CAPABLE
| HA_BINLOG_ROW_CAPABLE))
|| MY_TEST(flags & HA_HAS_OWN_BINLOGGING);
}
else
{
outparam->no_replicate= FALSE;
if (! MY_TEST(flags & (HA_BINLOG_STMT_CAPABLE |
HA_BINLOG_ROW_CAPABLE)) ||
MY_TEST(flags & HA_HAS_OWN_BINLOGGING))
share->no_replicate= TRUE;
if (outparam->file->table_cache_type() & HA_CACHE_TBL_NOCACHE)
share->not_usable_by_query_cache= TRUE;
}

if (outparam->no_replicate || !binlog_filter->db_ok(outparam->s->db.str))
outparam->s->cached_row_logging_check= 0; // No row based replication
if (share->no_replicate || !binlog_filter->db_ok(share->db.str))
share->can_do_row_logging= 0; // No row based replication

/* Increment the opened_tables counter, only when open flags set. */
if (db_stat)
Expand Down
13 changes: 4 additions & 9 deletions sql/table.h
Expand Up @@ -693,6 +693,8 @@ struct TABLE_SHARE
bool use_ext_keys; /* Extended keys can be used */
bool null_field_first;
bool system; /* Set if system table (one record) */
bool not_usable_by_query_cache;
bool no_replicate;
bool crypted; /* If .frm file is crypted */
bool crashed;
bool is_view;
Expand All @@ -702,6 +704,8 @@ struct TABLE_SHARE
bool vcols_need_refixing;
bool check_set_initialized;
bool has_update_default_function;
bool can_do_row_logging; /* 1 if table supports RBR */

ulong table_map_id; /* for row-based replication */

/*
Expand All @@ -720,14 +724,6 @@ struct TABLE_SHARE
/* For sequence tables, the current sequence state */
SEQUENCE *sequence;

/*
Cache for row-based replication table share checks that does not
need to be repeated. Possible values are: -1 when cache value is
not calculated yet, 0 when table *shall not* be replicated, 1 when
table *may* be replicated.
*/
int cached_row_logging_check;

/* Name of the tablespace used for this table */
char *tablespace;

Expand Down Expand Up @@ -1254,7 +1250,6 @@ struct TABLE
If set, indicate that the table is not replicated by the server.
*/
bool locked_by_logger;
bool no_replicate;
bool locked_by_name;
bool fulltext_searched;
bool no_cache;
Expand Down
1 change: 1 addition & 0 deletions sql/temporary_tables.cc
Expand Up @@ -1119,6 +1119,7 @@ TABLE *THD::open_temporary_table(TMP_TABLE_SHARE *share,
table->grant.privilege= TMP_TABLE_ACLS;
share->tmp_table= (table->file->has_transaction_manager() ?
TRANSACTIONAL_TMP_TABLE : NON_TRANSACTIONAL_TMP_TABLE);
share->not_usable_by_query_cache= 1;

table->pos_in_table_list= 0;
table->query_id= query_id;
Expand Down
2 changes: 1 addition & 1 deletion storage/spider/spd_sys_table.cc
Expand Up @@ -276,7 +276,7 @@ TABLE *spider_sys_open_table(
MYSQL_OPEN_IGNORE_FLUSH | MYSQL_LOCK_IGNORE_TIMEOUT | MYSQL_LOCK_LOG_TABLE
))) {
table->use_all_columns();
table->no_replicate = 1;
table->s->no_replicate = 1;
} else
thd->restore_backup_open_tables_state(open_tables_backup);
thd->utime_after_lock = utime_after_lock_backup;
Expand Down

0 comments on commit 8bfda2f

Please sign in to comment.