Skip to content

Commit 8bfda2f

Browse files
montywivuvova
authored andcommitted
Simplify test if we can use table in query cache
- 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
1 parent 1ed605e commit 8bfda2f

File tree

8 files changed

+54
-63
lines changed

8 files changed

+54
-63
lines changed

sql/handler.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5683,7 +5683,7 @@ bool handler::check_table_binlog_row_based_internal(bool binlog_row)
56835683
}
56845684
#endif
56855685

5686-
return (table->s->cached_row_logging_check &&
5686+
return (table->s->can_do_row_logging &&
56875687
thd->is_current_stmt_binlog_format_row() &&
56885688
/*
56895689
Wsrep partially enables binary logging if it have not been

sql/sql_base.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8642,7 +8642,7 @@ open_log_table(THD *thd, TABLE_LIST *one_table, Open_tables_backup *backup)
86428642
DBUG_ASSERT(table->s->table_category == TABLE_CATEGORY_LOG);
86438643
/* Make sure all columns get assigned to a default value */
86448644
table->use_all_columns();
8645-
DBUG_ASSERT(table->no_replicate);
8645+
DBUG_ASSERT(table->s->no_replicate);
86468646
}
86478647
else
86488648
thd->restore_backup_open_tables_state(backup);

sql/sql_cache.cc

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4050,41 +4050,35 @@ Query_cache::process_and_count_tables(THD *thd, TABLE_LIST *tables_used,
40504050
tables_used->view_name.str,
40514051
tables_used->view_db.str));
40524052
*tables_type|= HA_CACHE_TBL_NONTRANSACT;
4053+
continue;
40534054
}
4054-
else
4055+
if (tables_used->derived)
40554056
{
4056-
if (tables_used->derived)
4057-
{
4058-
DBUG_PRINT("qcache", ("table: %s", tables_used->alias));
4059-
table_count--;
4060-
DBUG_PRINT("qcache", ("derived table skipped"));
4061-
continue;
4062-
}
4063-
DBUG_PRINT("qcache", ("table: %s db: %s type: %u",
4064-
tables_used->table->s->table_name.str,
4065-
tables_used->table->s->db.str,
4066-
tables_used->table->s->db_type()->db_type));
4067-
*tables_type|= tables_used->table->file->table_cache_type();
4057+
DBUG_PRINT("qcache", ("table: %s", tables_used->alias));
4058+
table_count--;
4059+
DBUG_PRINT("qcache", ("derived table skipped"));
4060+
continue;
4061+
}
40684062

4069-
/*
4070-
table_alias_charset used here because it depends of
4071-
lower_case_table_names variable
4072-
*/
4073-
table_count+= tables_used->table->file->
4074-
count_query_cache_dependant_tables(tables_type);
4075-
4076-
if (tables_used->table->s->tmp_table != NO_TMP_TABLE ||
4077-
(*tables_type & HA_CACHE_TBL_NOCACHE) ||
4078-
(tables_used->db_length == 5 &&
4079-
my_strnncoll(table_alias_charset,
4080-
(uchar*)tables_used->table->s->table_cache_key.str, 6,
4081-
(uchar*)"mysql",6) == 0))
4082-
{
4083-
DBUG_PRINT("qcache",
4084-
("select not cacheable: temporary, system or "
4085-
"other non-cacheable table(s)"));
4086-
DBUG_RETURN(0);
4087-
}
4063+
DBUG_PRINT("qcache", ("table: %s db: %s type: %u",
4064+
tables_used->table->s->table_name.str,
4065+
tables_used->table->s->db.str,
4066+
tables_used->table->s->db_type()->db_type));
4067+
*tables_type|= tables_used->table->file->table_cache_type();
4068+
4069+
/*
4070+
table_alias_charset used here because it depends of
4071+
lower_case_table_names variable
4072+
*/
4073+
table_count+= tables_used->table->file->
4074+
count_query_cache_dependant_tables(tables_type);
4075+
4076+
if (tables_used->table->s->not_usable_by_query_cache)
4077+
{
4078+
DBUG_PRINT("qcache",
4079+
("select not cacheable: temporary, system or "
4080+
"other non-cacheable table(s)"));
4081+
DBUG_RETURN(0);
40884082
}
40894083
}
40904084
DBUG_RETURN(table_count);

sql/sql_class.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5895,7 +5895,7 @@ int THD::decide_logging_format(TABLE_LIST *tables)
58955895
DBUG_PRINT("info", ("table: %s; ha_table_flags: 0x%llx",
58965896
table->table_name, flags));
58975897

5898-
if (table->table->no_replicate)
5898+
if (table->table->s->no_replicate)
58995899
{
59005900
/*
59015901
The statement uses a table that is not replicated.

sql/table.cc

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,13 @@ TABLE_SHARE *alloc_table_share(const char *db, const char *table_name,
328328
share->normalized_path.length= path_length;
329329
share->table_category= get_table_category(& share->db, & share->table_name);
330330
share->open_errno= ENOENT;
331-
/* The following will be fixed in open_table_from_share */
332-
share->cached_row_logging_check= 1;
331+
/* The following will be updated in open_table_from_share */
332+
share->can_do_row_logging= 1;
333+
if (share->table_category == TABLE_CATEGORY_LOG)
334+
share->no_replicate= 1;
335+
if (my_strnncoll(table_alias_charset, (uchar*) db, 6,
336+
(const uchar*) "mysql", 6) == 0)
337+
share->not_usable_by_query_cache= 1;
333338

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

@@ -402,8 +407,8 @@ void init_tmp_table_share(THD *thd, TABLE_SHARE *share, const char *key,
402407
share->normalized_path.str= (char*) path;
403408
share->path.length= share->normalized_path.length= strlen(path);
404409
share->frm_version= FRM_VER_CURRENT;
405-
406-
share->cached_row_logging_check= 0; // No row logging
410+
share->not_usable_by_query_cache= 1;
411+
share->can_do_row_logging= 0; // No row logging
407412

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

33803385
outparam->mark_columns_used_by_check_constraints();
33813386

3382-
if (share->table_category == TABLE_CATEGORY_LOG)
3383-
{
3384-
outparam->no_replicate= TRUE;
3385-
}
3386-
else if (outparam->file)
3387+
if (db_stat)
33873388
{
3389+
/* Set some flags in share on first open of the table */
33883390
handler::Table_flags flags= outparam->file->ha_table_flags();
3389-
outparam->no_replicate= ! MY_TEST(flags & (HA_BINLOG_STMT_CAPABLE
3390-
| HA_BINLOG_ROW_CAPABLE))
3391-
|| MY_TEST(flags & HA_HAS_OWN_BINLOGGING);
3392-
}
3393-
else
3394-
{
3395-
outparam->no_replicate= FALSE;
3391+
if (! MY_TEST(flags & (HA_BINLOG_STMT_CAPABLE |
3392+
HA_BINLOG_ROW_CAPABLE)) ||
3393+
MY_TEST(flags & HA_HAS_OWN_BINLOGGING))
3394+
share->no_replicate= TRUE;
3395+
if (outparam->file->table_cache_type() & HA_CACHE_TBL_NOCACHE)
3396+
share->not_usable_by_query_cache= TRUE;
33963397
}
33973398

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

34013402
/* Increment the opened_tables counter, only when open flags set. */
34023403
if (db_stat)

sql/table.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,8 @@ struct TABLE_SHARE
693693
bool use_ext_keys; /* Extended keys can be used */
694694
bool null_field_first;
695695
bool system; /* Set if system table (one record) */
696+
bool not_usable_by_query_cache;
697+
bool no_replicate;
696698
bool crypted; /* If .frm file is crypted */
697699
bool crashed;
698700
bool is_view;
@@ -702,6 +704,8 @@ struct TABLE_SHARE
702704
bool vcols_need_refixing;
703705
bool check_set_initialized;
704706
bool has_update_default_function;
707+
bool can_do_row_logging; /* 1 if table supports RBR */
708+
705709
ulong table_map_id; /* for row-based replication */
706710

707711
/*
@@ -720,14 +724,6 @@ struct TABLE_SHARE
720724
/* For sequence tables, the current sequence state */
721725
SEQUENCE *sequence;
722726

723-
/*
724-
Cache for row-based replication table share checks that does not
725-
need to be repeated. Possible values are: -1 when cache value is
726-
not calculated yet, 0 when table *shall not* be replicated, 1 when
727-
table *may* be replicated.
728-
*/
729-
int cached_row_logging_check;
730-
731727
/* Name of the tablespace used for this table */
732728
char *tablespace;
733729

@@ -1254,7 +1250,6 @@ struct TABLE
12541250
If set, indicate that the table is not replicated by the server.
12551251
*/
12561252
bool locked_by_logger;
1257-
bool no_replicate;
12581253
bool locked_by_name;
12591254
bool fulltext_searched;
12601255
bool no_cache;

sql/temporary_tables.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,7 @@ TABLE *THD::open_temporary_table(TMP_TABLE_SHARE *share,
11191119
table->grant.privilege= TMP_TABLE_ACLS;
11201120
share->tmp_table= (table->file->has_transaction_manager() ?
11211121
TRANSACTIONAL_TMP_TABLE : NON_TRANSACTIONAL_TMP_TABLE);
1122+
share->not_usable_by_query_cache= 1;
11221123

11231124
table->pos_in_table_list= 0;
11241125
table->query_id= query_id;

storage/spider/spd_sys_table.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ TABLE *spider_sys_open_table(
276276
MYSQL_OPEN_IGNORE_FLUSH | MYSQL_LOCK_IGNORE_TIMEOUT | MYSQL_LOCK_LOG_TABLE
277277
))) {
278278
table->use_all_columns();
279-
table->no_replicate = 1;
279+
table->s->no_replicate = 1;
280280
} else
281281
thd->restore_backup_open_tables_state(open_tables_backup);
282282
thd->utime_after_lock = utime_after_lock_backup;

0 commit comments

Comments
 (0)