1
0
mirror of https://github.com/MariaDB/server.git synced 2025-09-09 18:40:27 +03:00

MDEV-16249 CHECKSUM TABLE for a spider table is not parallel and saves all data in memory in the spider head by default (#1328)

add checksum_null for setting null value of checksum
This commit is contained in:
Kentoku SHIBA
2019-06-11 00:25:08 +09:00
committed by GitHub
parent 5e9090ef16
commit be5c432a42
50 changed files with 1303 additions and 472 deletions

View File

@@ -8200,6 +8200,7 @@ int ha_partition::info(uint flag)
stats.delete_length= 0;
stats.check_time= 0;
stats.checksum= 0;
stats.checksum_null= TRUE;
for (i= bitmap_get_first_set(&m_part_info->read_partitions);
i < m_tot_parts;
i= bitmap_get_next_set(&m_part_info->read_partitions, i))
@@ -8213,7 +8214,11 @@ int ha_partition::info(uint flag)
stats.delete_length+= file->stats.delete_length;
if (file->stats.check_time > stats.check_time)
stats.check_time= file->stats.check_time;
stats.checksum+= file->stats.checksum;
if (!file->stats.checksum_null)
{
stats.checksum+= file->stats.checksum;
stats.checksum_null= FALSE;
}
}
if (stats.records && stats.records < 2 &&
!(m_file[0]->ha_table_flags() & HA_STATS_RECORDS_IS_EXACT))
@@ -8370,6 +8375,7 @@ void ha_partition::get_dynamic_partition_info(PARTITION_STATS *stat_info,
stat_info->update_time= file->stats.update_time;
stat_info->check_time= file->stats.check_time;
stat_info->check_sum= file->stats.checksum;
stat_info->check_sum_null= file->stats.checksum_null;
}
@@ -10599,6 +10605,66 @@ void ha_partition::init_table_handle_for_HANDLER()
}
/**
Calculate the checksum of the table (all partitions)
*/
int ha_partition::pre_calculate_checksum()
{
int error;
DBUG_ENTER("ha_partition::pre_calculate_checksum");
m_pre_calling= TRUE;
if ((table_flags() & (HA_HAS_OLD_CHECKSUM | HA_HAS_NEW_CHECKSUM)))
{
handler **file= m_file;
do
{
if ((error= (*file)->pre_calculate_checksum()))
{
DBUG_RETURN(error);
}
} while (*(++file));
}
DBUG_RETURN(0);
}
int ha_partition::calculate_checksum()
{
int error;
stats.checksum= 0;
stats.checksum_null= TRUE;
DBUG_ENTER("ha_partition::calculate_checksum");
if (!m_pre_calling)
{
if ((error= pre_calculate_checksum()))
{
m_pre_calling= FALSE;
DBUG_RETURN(error);
}
}
m_pre_calling= FALSE;
if ((table_flags() & (HA_HAS_OLD_CHECKSUM | HA_HAS_NEW_CHECKSUM)))
{
handler **file= m_file;
do
{
if ((error= (*file)->calculate_checksum()))
{
DBUG_RETURN(error);
}
if (!(*file)->stats.checksum_null)
{
stats.checksum+= (*file)->stats.checksum;
stats.checksum_null= FALSE;
}
} while (*(++file));
}
DBUG_RETURN(0);
}
/****************************************************************************
MODULE enable/disable indexes
****************************************************************************/

View File

@@ -1443,6 +1443,9 @@ public:
void append_row_to_str(String &str);
public:
virtual int pre_calculate_checksum();
virtual int calculate_checksum();
/* Enabled keycache for performance reasons, WL#4571 */
virtual int assign_to_keycache(THD* thd, HA_CHECK_OPT *check_opt);
virtual int preload_keys(THD* thd, HA_CHECK_OPT* check_opt);

View File

@@ -4899,6 +4899,7 @@ void handler::get_dynamic_partition_info(PARTITION_STATS *stat_info,
stat_info->update_time= stats.update_time;
stat_info->check_time= stats.check_time;
stat_info->check_sum= stats.checksum;
stat_info->check_sum_null= stats.checksum_null;
}

View File

@@ -1922,6 +1922,7 @@ typedef struct {
time_t check_time;
time_t update_time;
ulonglong check_sum;
bool check_sum_null;
} PARTITION_STATS;
#define UNDEF_NODEGROUP 65535
@@ -2881,6 +2882,7 @@ public:
time_t update_time;
uint block_size; /* index block size */
ha_checksum checksum;
bool checksum_null;
/*
number of buffer bytes that native mrr implementation needs,
@@ -2892,7 +2894,7 @@ public:
index_file_length(0), max_index_file_length(0), delete_length(0),
auto_increment_value(0), records(0), deleted(0), mean_rec_length(0),
create_time(0), check_time(0), update_time(0), block_size(0),
mrr_length_per_rec(0)
checksum(0), checksum_null(FALSE), mrr_length_per_rec(0)
{}
};
@@ -3925,6 +3927,7 @@ public:
virtual uint max_supported_key_part_length() const { return 255; }
virtual uint min_record_length(uint options) const { return 1; }
virtual int pre_calculate_checksum() { return 0; }
virtual int calculate_checksum();
virtual bool is_crashed() const { return 0; }
virtual bool auto_repair(int error) const { return 0; }

View File

@@ -5668,7 +5668,9 @@ static int get_schema_tables_record(THD *thd, TABLE_LIST *tables,
table->field[16]->store_time(&time);
table->field[16]->set_notnull();
}
if (file->ha_table_flags() & (HA_HAS_OLD_CHECKSUM | HA_HAS_NEW_CHECKSUM))
if ((file->ha_table_flags() &
(HA_HAS_OLD_CHECKSUM | HA_HAS_NEW_CHECKSUM)) &&
!file->stats.checksum_null)
{
table->field[18]->store((longlong) file->stats.checksum, TRUE);
table->field[18]->set_notnull();

View File

@@ -10936,7 +10936,7 @@ bool mysql_checksum_table(THD *thd, TABLE_LIST *tables,
(((t->file->ha_table_flags() & HA_HAS_OLD_CHECKSUM) && thd->variables.old_mode) ||
((t->file->ha_table_flags() & HA_HAS_NEW_CHECKSUM) && !thd->variables.old_mode)))
{
if (t->file->info(HA_STATUS_VARIABLE))
if (t->file->info(HA_STATUS_VARIABLE) || t->file->stats.checksum_null)
protocol->store_null();
else
protocol->store((longlong)t->file->stats.checksum);
@@ -10956,7 +10956,7 @@ bool mysql_checksum_table(THD *thd, TABLE_LIST *tables,
thd->protocol->remove_last_row();
goto err;
}
if (error)
if (error || t->file->stats.checksum_null)
protocol->store_null();
else
protocol->store((longlong)t->file->stats.checksum);

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2008-2018 Kentoku Shiba
/* Copyright (C) 2008-2019 Kentoku Shiba
Copyright (C) 2019 MariaDB corp
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
@@ -116,7 +117,7 @@ ha_spider::ha_spider(
use_fields = FALSE;
#endif
use_pre_call = FALSE;
use_pre_records = FALSE;
use_pre_action = FALSE;
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
do_direct_update = FALSE;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
@@ -228,7 +229,7 @@ ha_spider::ha_spider(
use_fields = FALSE;
#endif
use_pre_call = FALSE;
use_pre_records = FALSE;
use_pre_action = FALSE;
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
do_direct_update = FALSE;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
@@ -1805,7 +1806,7 @@ int ha_spider::reset()
high_priority = FALSE;
insert_delayed = FALSE;
use_pre_call = FALSE;
use_pre_records = FALSE;
use_pre_action = FALSE;
pre_bitmap_checked = FALSE;
bulk_insert = FALSE;
clone_bitmap_init = FALSE;
@@ -8760,22 +8761,24 @@ int ha_spider::info(
}
if (flag & HA_STATUS_TIME)
stats.update_time = (ulong) share->update_time;
stats.update_time = (ulong) share->stat.update_time;
if (flag & (HA_STATUS_CONST | HA_STATUS_VARIABLE))
{
stats.max_data_file_length = share->max_data_file_length;
stats.create_time = (ulong) share->create_time;
stats.max_data_file_length = share->stat.max_data_file_length;
stats.create_time = share->stat.create_time;
stats.block_size = spider_param_block_size(thd);
}
if (flag & HA_STATUS_VARIABLE)
{
stats.data_file_length = share->data_file_length;
stats.index_file_length = share->index_file_length;
stats.records = share->records;
stats.mean_rec_length = share->mean_rec_length;
stats.check_time = (ulong) share->check_time;
stats.data_file_length = share->stat.data_file_length;
stats.index_file_length = share->stat.index_file_length;
stats.records = share->stat.records;
stats.mean_rec_length = share->stat.mean_rec_length;
stats.check_time = share->stat.check_time;
if (stats.records <= 1 /* && (flag & HA_STATUS_NO_LOCK) */ )
stats.records = 2;
stats.checksum = share->stat.checksum;
stats.checksum_null = share->stat.checksum_null;
}
if (flag & HA_STATUS_AUTO)
{
@@ -9014,7 +9017,7 @@ ha_rows ha_spider::records_in_range(
key_part_map tgt_key_part_map;
KEY_PART_INFO *key_part;
Field *field = NULL;
double rows = (double) share->records;
double rows = (double) share->stat.records;
double weight, rate;
DBUG_PRINT("info",("spider rows1=%f", rows));
if (start_key)
@@ -9323,11 +9326,12 @@ int ha_spider::pre_records()
result_list.casual_read[search_link_idx] =
spider_param_casual_read(thd, share->casual_read);
}
if ((error_num = spider_db_show_records(this, search_link_idx, TRUE)))
if ((error_num = spider_db_simple_action(SPIDER_SIMPLE_RECORDS, this,
search_link_idx, TRUE)))
{
DBUG_RETURN(check_error_mode(error_num));
}
use_pre_records = TRUE;
use_pre_action = TRUE;
DBUG_RETURN(0);
}
@@ -9339,14 +9343,14 @@ ha_rows ha_spider::records()
DBUG_PRINT("info",("spider this=%p", this));
if (sql_command == SQLCOM_ALTER_TABLE)
{
use_pre_records = FALSE;
use_pre_action = FALSE;
DBUG_RETURN(0);
}
if (!(share->additional_table_flags & HA_HAS_RECORDS) && !this->result_list.direct_limit_offset)
{
DBUG_RETURN(handler::records());
}
if (!use_pre_records && !this->result_list.direct_limit_offset)
if (!use_pre_action && !this->result_list.direct_limit_offset)
{
THD *thd = trx->thd;
if (
@@ -9357,17 +9361,84 @@ ha_rows ha_spider::records()
spider_param_casual_read(thd, share->casual_read);
}
}
if ((error_num = spider_db_show_records(this, search_link_idx, FALSE)))
if ((error_num = spider_db_simple_action(SPIDER_SIMPLE_RECORDS, this,
search_link_idx, FALSE)))
{
use_pre_records = FALSE;
use_pre_action = FALSE;
check_error_mode(error_num);
DBUG_RETURN(HA_POS_ERROR);
}
use_pre_records = FALSE;
share->records = table_rows;
use_pre_action = FALSE;
share->stat.records = table_rows;
DBUG_RETURN(table_rows);
}
#ifdef HA_HAS_CHECKSUM_EXTENDED
int ha_spider::pre_calculate_checksum()
{
int error_num;
backup_error_status();
DBUG_ENTER("ha_spider::pre_calculate_checksum");
DBUG_PRINT("info",("spider this=%p", this));
THD *thd = trx->thd;
if (
spider_param_sync_autocommit(thd) &&
(!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
) {
result_list.casual_read[search_link_idx] =
spider_param_casual_read(thd, share->casual_read);
}
action_flags = T_EXTEND;
if ((error_num = spider_db_simple_action(SPIDER_SIMPLE_CHECKSUM_TABLE, this,
search_link_idx, TRUE)))
{
DBUG_RETURN(check_error_mode(error_num));
}
use_pre_action = TRUE;
DBUG_RETURN(0);
}
int ha_spider::calculate_checksum()
{
int error_num;
backup_error_status();
DBUG_ENTER("ha_spider::calculate_checksum");
DBUG_PRINT("info",("spider this=%p", this));
if (!use_pre_action && !this->result_list.direct_limit_offset)
{
THD *thd = trx->thd;
if (
spider_param_sync_autocommit(thd) &&
(!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
) {
result_list.casual_read[search_link_idx] =
spider_param_casual_read(thd, share->casual_read);
}
}
action_flags = T_EXTEND;
if ((error_num = spider_db_simple_action(SPIDER_SIMPLE_CHECKSUM_TABLE, this,
search_link_idx, FALSE)))
{
use_pre_action = FALSE;
DBUG_RETURN(check_error_mode(error_num));
}
use_pre_action = FALSE;
if (checksum_null)
{
share->stat.checksum_null = TRUE;
share->stat.checksum = 0;
stats.checksum_null = TRUE;
stats.checksum = 0;
} else {
share->stat.checksum_null = FALSE;
share->stat.checksum = checksum_val;
stats.checksum_null = FALSE;
stats.checksum = checksum_val;
}
DBUG_RETURN(0);
}
#endif
const char *ha_spider::table_type() const
{
DBUG_ENTER("ha_spider::table_type");
@@ -11172,8 +11243,9 @@ double ha_spider::scan_time()
DBUG_ENTER("ha_spider::scan_time");
DBUG_PRINT("info",("spider this=%p", this));
DBUG_PRINT("info",("spider scan_time = %.6f",
share->scan_rate * share->records * share->mean_rec_length + 2));
DBUG_RETURN(share->scan_rate * share->records * share->mean_rec_length + 2);
share->scan_rate * share->stat.records * share->stat.mean_rec_length + 2));
DBUG_RETURN(share->scan_rate * share->stat.records *
share->stat.mean_rec_length + 2);
}
double ha_spider::read_time(
@@ -11192,8 +11264,8 @@ double ha_spider::read_time(
rows / 2 + 2);
} else {
DBUG_PRINT("info",("spider read_time = %.6f",
share->read_rate * share->mean_rec_length * rows + 2));
DBUG_RETURN(share->read_rate * share->mean_rec_length * rows + 2);
share->read_rate * share->stat.mean_rec_length * rows + 2));
DBUG_RETURN(share->read_rate * share->stat.mean_rec_length * rows + 2);
}
}

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2008-2018 Kentoku Shiba
/* Copyright (C) 2008-2019 Kentoku Shiba
Copyright (C) 2019 MariaDB corp
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
@@ -170,7 +171,7 @@ public:
bool high_priority;
bool insert_delayed;
bool use_pre_call;
bool use_pre_records;
bool use_pre_action;
bool pre_bitmap_checked;
enum thr_lock_type lock_type;
int lock_mode;
@@ -243,6 +244,11 @@ public:
SPIDER_ITEM_HLD *direct_aggregate_item_current;
#endif
ha_rows table_rows;
#ifdef HA_HAS_CHECKSUM_EXTENDED
ulonglong checksum_val;
bool checksum_null;
uint action_flags;
#endif
/* for fulltext search */
bool ft_init_and_first;
@@ -512,6 +518,10 @@ public:
int check_crd();
int pre_records();
ha_rows records();
#ifdef HA_HAS_CHECKSUM_EXTENDED
int pre_calculate_checksum();
int calculate_checksum();
#endif
const char *table_type() const;
ulonglong table_flags() const;
const char *index_type(

View File

@@ -21,7 +21,7 @@ let $CHILD2_1_CREATE_TABLES=
let $CHILD2_1_SELECT_TABLES=
SELECT pkey FROM tbl_a ORDER BY pkey;
let $CHILD2_1_SELECT_ARGUMENT1=
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %';
SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %';
--connection master_1
set @old_spider_quick_mode= @@spider_quick_mode;
set session spider_quick_mode= 3;

View File

@@ -44,10 +44,10 @@ CHECKSUM TABLE tbl_a EXTENDED;
Table Checksum
auto_test_local.tbl_a 1061386331
connection child2_1;
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %';
SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %';
argument
select `pkey` from `auto_test_remote`.`tbl_a`
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'
checksum table `auto_test_remote`.`tbl_a` extended
SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %'
SELECT pkey FROM tbl_a ORDER BY pkey;
pkey
0

View File

@@ -0,0 +1,16 @@
--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP
--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP
--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP
--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP
--let $CHILD2_2_DROP_TABLES= $CHILD2_2_DROP_TABLES_BACKUP
--let $CHILD2_2_CREATE_TABLES= $CHILD2_2_CREATE_TABLES_BACKUP
--let $CHILD2_2_SELECT_TABLES= $CHILD2_2_SELECT_TABLES_BACKUP
--connection master_1
set session spider_bgs_mode= @old_spider_bgs_mode;
--disable_warnings
--disable_query_log
--disable_result_log
--source ../t/test_deinit.inc
--enable_result_log
--enable_query_log
--enable_warnings

View File

@@ -0,0 +1 @@
--source checksum_table_parallel_deinit.inc

View File

@@ -0,0 +1,2 @@
--source checksum_table_parallel_init.inc
--let $MASTER_1_CHECKSUM_TABLE= CHECKSUM TABLE tbl_a EXTENDED

View File

@@ -0,0 +1,53 @@
--disable_warnings
--disable_query_log
--disable_result_log
--source ../t/test_init.inc
if (!$HAVE_PARTITION)
{
--source checksum_table_parallel_deinit.inc
--enable_result_log
--enable_query_log
--enable_warnings
skip Test requires partitioning;
}
--enable_result_log
--enable_query_log
--enable_warnings
--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1
let $MASTER_1_COMMENT_2_1=
COMMENT='table "tbl_a"'
PARTITION BY KEY(pkey) (
PARTITION pt1 COMMENT='srv "s_2_1"',
PARTITION pt2 COMMENT='srv "s_2_2"'
);
--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES
let $CHILD2_1_DROP_TABLES=
DROP TABLE IF EXISTS tbl_a;
--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES
let $CHILD2_1_CREATE_TABLES=
CREATE TABLE tbl_a (
pkey int NOT NULL,
PRIMARY KEY (pkey)
) $CHILD2_1_ENGINE $CHILD2_1_CHARSET;
--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES
let $CHILD2_1_SELECT_TABLES=
SELECT pkey FROM tbl_a ORDER BY pkey;
let $CHILD2_1_SELECT_ARGUMENT1=
SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %';
--let $CHILD2_2_DROP_TABLES_BACKUP= $CHILD2_2_DROP_TABLES
let $CHILD2_2_DROP_TABLES=
DROP TABLE IF EXISTS tbl_a;
--let $CHILD2_2_CREATE_TABLES_BACKUP= $CHILD2_2_CREATE_TABLES
let $CHILD2_2_CREATE_TABLES=
CREATE TABLE tbl_a (
pkey int NOT NULL,
PRIMARY KEY (pkey)
) $CHILD2_2_ENGINE $CHILD2_2_CHARSET;
--let $CHILD2_2_SELECT_TABLES_BACKUP= $CHILD2_2_SELECT_TABLES
let $CHILD2_2_SELECT_TABLES=
SELECT pkey FROM tbl_a ORDER BY pkey;
let $CHILD2_2_SELECT_ARGUMENT1=
SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %';
--connection master_1
set @old_spider_bgs_mode= @@spider_bgs_mode;
set session spider_bgs_mode= 1;

View File

@@ -0,0 +1 @@
--source checksum_table_parallel_deinit.inc

View File

@@ -0,0 +1,2 @@
--source checksum_table_parallel_init.inc
--let $MASTER_1_CHECKSUM_TABLE= CHECKSUM TABLE tbl_a

View File

@@ -0,0 +1 @@
--source checksum_table_parallel_deinit.inc

View File

@@ -0,0 +1,2 @@
--source checksum_table_parallel_init.inc
--let $MASTER_1_CHECKSUM_TABLE= CHECKSUM TABLE tbl_a QUICK

View File

@@ -0,0 +1,130 @@
for master_1
for child2
child2_1
child2_2
child2_3
for child3
connection master_1;
set @old_spider_bgs_mode= @@spider_bgs_mode;
set session spider_bgs_mode= 1;
this test is for MDEV-16967
drop and create databases
connection master_1;
CREATE DATABASE auto_test_local;
USE auto_test_local;
connection child2_1;
SET @old_log_output = @@global.log_output;
SET GLOBAL log_output = 'TABLE,FILE';
CREATE DATABASE auto_test_remote;
USE auto_test_remote;
connection child2_1_2;
USE auto_test_remote;
connection child2_2;
SET @old_log_output = @@global.log_output;
SET GLOBAL log_output = 'TABLE,FILE';
CREATE DATABASE auto_test_remote2;
USE auto_test_remote2;
connection child2_2_2;
USE auto_test_remote2;
create table and insert
connection child2_1;
CHILD2_1_CREATE_TABLES
TRUNCATE TABLE mysql.general_log;
connection child2_2;
CHILD2_2_CREATE_TABLES
TRUNCATE TABLE mysql.general_log;
connection master_1;
CREATE TABLE tbl_a (
pkey int NOT NULL,
PRIMARY KEY (pkey)
) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1
INSERT INTO tbl_a (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
INSERT INTO tbl_a (pkey) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19);
INSERT INTO tbl_a (pkey) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29);
select test 1
connection child2_1;
TRUNCATE TABLE mysql.general_log;
LOCK TABLE tbl_a WRITE;
connection child2_2;
TRUNCATE TABLE mysql.general_log;
LOCK TABLE tbl_a WRITE;
connection master_1;
CHECKSUM TABLE tbl_a EXTENDED;
connection child2_1_2;
SELECT SLEEP(1);
SLEEP(1)
0
SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %';
argument
checksum table `auto_test_remote`.`tbl_a` extended
SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %'
connection child2_2_2;
SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %';
argument
checksum table `auto_test_remote2`.`tbl_a` extended
SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %'
connection child2_1;
UNLOCK TABLES;
SELECT pkey FROM tbl_a ORDER BY pkey;
pkey
1
3
5
7
9
11
13
15
17
19
21
23
25
27
29
connection child2_2;
UNLOCK TABLES;
SELECT pkey FROM tbl_a ORDER BY pkey;
pkey
0
2
4
6
8
10
12
14
16
18
20
22
24
26
28
connection master_1;
Table Checksum
auto_test_local.tbl_a 1061386331
deinit
connection master_1;
DROP DATABASE IF EXISTS auto_test_local;
connection child2_1;
DROP DATABASE IF EXISTS auto_test_remote;
SET GLOBAL log_output = @old_log_output;
connection child2_2;
DROP DATABASE IF EXISTS auto_test_remote2;
SET GLOBAL log_output = @old_log_output;
connection master_1;
set session spider_bgs_mode= @old_spider_bgs_mode;
for master_1
for child2
child2_1
child2_2
child2_3
for child3
end of test

View File

@@ -0,0 +1,128 @@
for master_1
for child2
child2_1
child2_2
child2_3
for child3
connection master_1;
set @old_spider_bgs_mode= @@spider_bgs_mode;
set session spider_bgs_mode= 1;
this test is for MDEV-16967
drop and create databases
connection master_1;
CREATE DATABASE auto_test_local;
USE auto_test_local;
connection child2_1;
SET @old_log_output = @@global.log_output;
SET GLOBAL log_output = 'TABLE,FILE';
CREATE DATABASE auto_test_remote;
USE auto_test_remote;
connection child2_1_2;
USE auto_test_remote;
connection child2_2;
SET @old_log_output = @@global.log_output;
SET GLOBAL log_output = 'TABLE,FILE';
CREATE DATABASE auto_test_remote2;
USE auto_test_remote2;
connection child2_2_2;
USE auto_test_remote2;
create table and insert
connection child2_1;
CHILD2_1_CREATE_TABLES
TRUNCATE TABLE mysql.general_log;
connection child2_2;
CHILD2_2_CREATE_TABLES
TRUNCATE TABLE mysql.general_log;
connection master_1;
CREATE TABLE tbl_a (
pkey int NOT NULL,
PRIMARY KEY (pkey)
) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1
INSERT INTO tbl_a (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
INSERT INTO tbl_a (pkey) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19);
INSERT INTO tbl_a (pkey) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29);
select test 1
connection child2_1;
TRUNCATE TABLE mysql.general_log;
LOCK TABLE tbl_a WRITE;
connection child2_2;
TRUNCATE TABLE mysql.general_log;
LOCK TABLE tbl_a WRITE;
connection master_1;
CHECKSUM TABLE tbl_a;
connection child2_1_2;
SELECT SLEEP(1);
SLEEP(1)
0
SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %';
argument
SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %'
connection child2_2_2;
SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %';
argument
SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %'
connection child2_1;
UNLOCK TABLES;
SELECT pkey FROM tbl_a ORDER BY pkey;
pkey
1
3
5
7
9
11
13
15
17
19
21
23
25
27
29
connection child2_2;
UNLOCK TABLES;
SELECT pkey FROM tbl_a ORDER BY pkey;
pkey
0
2
4
6
8
10
12
14
16
18
20
22
24
26
28
connection master_1;
Table Checksum
auto_test_local.tbl_a NULL
deinit
connection master_1;
DROP DATABASE IF EXISTS auto_test_local;
connection child2_1;
DROP DATABASE IF EXISTS auto_test_remote;
SET GLOBAL log_output = @old_log_output;
connection child2_2;
DROP DATABASE IF EXISTS auto_test_remote2;
SET GLOBAL log_output = @old_log_output;
connection master_1;
set session spider_bgs_mode= @old_spider_bgs_mode;
for master_1
for child2
child2_1
child2_2
child2_3
for child3
end of test

View File

@@ -0,0 +1,128 @@
for master_1
for child2
child2_1
child2_2
child2_3
for child3
connection master_1;
set @old_spider_bgs_mode= @@spider_bgs_mode;
set session spider_bgs_mode= 1;
this test is for MDEV-16967
drop and create databases
connection master_1;
CREATE DATABASE auto_test_local;
USE auto_test_local;
connection child2_1;
SET @old_log_output = @@global.log_output;
SET GLOBAL log_output = 'TABLE,FILE';
CREATE DATABASE auto_test_remote;
USE auto_test_remote;
connection child2_1_2;
USE auto_test_remote;
connection child2_2;
SET @old_log_output = @@global.log_output;
SET GLOBAL log_output = 'TABLE,FILE';
CREATE DATABASE auto_test_remote2;
USE auto_test_remote2;
connection child2_2_2;
USE auto_test_remote2;
create table and insert
connection child2_1;
CHILD2_1_CREATE_TABLES
TRUNCATE TABLE mysql.general_log;
connection child2_2;
CHILD2_2_CREATE_TABLES
TRUNCATE TABLE mysql.general_log;
connection master_1;
CREATE TABLE tbl_a (
pkey int NOT NULL,
PRIMARY KEY (pkey)
) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1
INSERT INTO tbl_a (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
INSERT INTO tbl_a (pkey) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19);
INSERT INTO tbl_a (pkey) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29);
select test 1
connection child2_1;
TRUNCATE TABLE mysql.general_log;
LOCK TABLE tbl_a WRITE;
connection child2_2;
TRUNCATE TABLE mysql.general_log;
LOCK TABLE tbl_a WRITE;
connection master_1;
CHECKSUM TABLE tbl_a QUICK;
connection child2_1_2;
SELECT SLEEP(1);
SLEEP(1)
0
SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %';
argument
SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %'
connection child2_2_2;
SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %';
argument
SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %'
connection child2_1;
UNLOCK TABLES;
SELECT pkey FROM tbl_a ORDER BY pkey;
pkey
1
3
5
7
9
11
13
15
17
19
21
23
25
27
29
connection child2_2;
UNLOCK TABLES;
SELECT pkey FROM tbl_a ORDER BY pkey;
pkey
0
2
4
6
8
10
12
14
16
18
20
22
24
26
28
connection master_1;
Table Checksum
auto_test_local.tbl_a NULL
deinit
connection master_1;
DROP DATABASE IF EXISTS auto_test_local;
connection child2_1;
DROP DATABASE IF EXISTS auto_test_remote;
SET GLOBAL log_output = @old_log_output;
connection child2_2;
DROP DATABASE IF EXISTS auto_test_remote2;
SET GLOBAL log_output = @old_log_output;
connection master_1;
set session spider_bgs_mode= @old_spider_bgs_mode;
for master_1
for child2
child2_1
child2_2
child2_3
for child3
end of test

View File

@@ -0,0 +1,107 @@
--echo
--echo this test is for MDEV-16967
--echo
--echo drop and create databases
--connection master_1
--disable_warnings
CREATE DATABASE auto_test_local;
USE auto_test_local;
--connection child2_1
SET @old_log_output = @@global.log_output;
SET GLOBAL log_output = 'TABLE,FILE';
CREATE DATABASE auto_test_remote;
USE auto_test_remote;
--connection child2_1_2
USE auto_test_remote;
--connection child2_2
SET @old_log_output = @@global.log_output;
SET GLOBAL log_output = 'TABLE,FILE';
CREATE DATABASE auto_test_remote2;
USE auto_test_remote2;
--connection child2_2_2
USE auto_test_remote2;
--enable_warnings
--echo
--echo create table and insert
--connection child2_1
--disable_query_log
echo CHILD2_1_CREATE_TABLES;
eval $CHILD2_1_CREATE_TABLES;
--enable_query_log
TRUNCATE TABLE mysql.general_log;
--connection child2_2
--disable_query_log
echo CHILD2_2_CREATE_TABLES;
eval $CHILD2_2_CREATE_TABLES;
--enable_query_log
TRUNCATE TABLE mysql.general_log;
--connection master_1
--disable_query_log
echo CREATE TABLE tbl_a (
pkey int NOT NULL,
PRIMARY KEY (pkey)
) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1;
eval CREATE TABLE tbl_a (
pkey int NOT NULL,
PRIMARY KEY (pkey)
) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1;
--enable_query_log
INSERT INTO tbl_a (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
INSERT INTO tbl_a (pkey) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19);
INSERT INTO tbl_a (pkey) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29);
--echo
--echo select test 1
--connection child2_1
TRUNCATE TABLE mysql.general_log;
LOCK TABLE tbl_a WRITE;
--connection child2_2
TRUNCATE TABLE mysql.general_log;
LOCK TABLE tbl_a WRITE;
--connection master_1
send_eval $MASTER_1_CHECKSUM_TABLE;
--connection child2_1_2
SELECT SLEEP(1);
eval $CHILD2_1_SELECT_ARGUMENT1;
--connection child2_2_2
eval $CHILD2_2_SELECT_ARGUMENT1;
--connection child2_1
UNLOCK TABLES;
eval $CHILD2_1_SELECT_TABLES;
--connection child2_2
UNLOCK TABLES;
eval $CHILD2_2_SELECT_TABLES;
--connection master_1
reap;
--echo
--echo deinit
--disable_warnings
--connection master_1
DROP DATABASE IF EXISTS auto_test_local;
--connection child2_1
DROP DATABASE IF EXISTS auto_test_remote;
SET GLOBAL log_output = @old_log_output;
--connection child2_2
DROP DATABASE IF EXISTS auto_test_remote2;
SET GLOBAL log_output = @old_log_output;
--enable_warnings

View File

@@ -0,0 +1,4 @@
!include include/default_mysqld.cnf
!include ../my_1_1.cnf
!include ../my_2_1.cnf
!include ../my_2_2.cnf

View File

@@ -0,0 +1,5 @@
--source ../include/checksum_table_parallel_extended_init.inc
--source checksum_table_parallel.inc
--source ../include/checksum_table_parallel_extended_deinit.inc
--echo
--echo end of test

View File

@@ -0,0 +1,4 @@
!include include/default_mysqld.cnf
!include ../my_1_1.cnf
!include ../my_2_1.cnf
!include ../my_2_2.cnf

View File

@@ -0,0 +1,5 @@
--source ../include/checksum_table_parallel_no_opt_init.inc
--source checksum_table_parallel.inc
--source ../include/checksum_table_parallel_no_opt_deinit.inc
--echo
--echo end of test

View File

@@ -0,0 +1,4 @@
!include include/default_mysqld.cnf
!include ../my_1_1.cnf
!include ../my_2_1.cnf
!include ../my_2_2.cnf

View File

@@ -0,0 +1,5 @@
--source ../include/checksum_table_parallel_quick_init.inc
--source checksum_table_parallel.inc
--source ../include/checksum_table_parallel_quick_deinit.inc
--echo
--echo end of test

View File

@@ -21,7 +21,7 @@ let $CHILD2_1_CREATE_TABLES=
let $CHILD2_1_SELECT_TABLES=
SELECT pkey FROM tbl_a ORDER BY pkey;
let $CHILD2_1_SELECT_ARGUMENT1=
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %';
SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %';
--let $OUTPUT_CHILD_GROUP2_BACKUP= $OUTPUT_CHILD_GROUP2
--let $OUTPUT_CHILD_GROUP2= 1
--let $USE_GENERAL_LOG_BACKUP= $USE_GENERAL_LOG

View File

@@ -409,6 +409,7 @@ if (`SELECT IF($PLUGIN_VERSION = 3, 1, 0)`)
check_time datetime not null default '0000-00-00 00:00:00',
create_time datetime not null default '0000-00-00 00:00:00',
update_time datetime not null default '0000-00-00 00:00:00',
checksum bigint unsigned default null,
primary key (db_name, table_name)
) ENGINE=$ENGINE_NAME DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
DROP TABLE IF EXISTS mysql.spider_table_crd;

View File

@@ -45,10 +45,10 @@ CHECKSUM TABLE tbl_a EXTENDED;
Table Checksum
auto_test_local.tbl_a 1061386331
connection child2_1;
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %';
SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %';
argument
select `pkey` from `auto_test_remote`.`tbl_a`
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'
checksum table `auto_test_remote`.`tbl_a` extended
SELECT argument FROM mysql.general_log WHERE argument LIKE '%checksum %'
SELECT pkey FROM tbl_a ORDER BY pkey;
pkey
0

View File

@@ -150,6 +150,7 @@ create table if not exists mysql.spider_table_sts(
check_time datetime not null default '0000-00-00 00:00:00',
create_time datetime not null default '0000-00-00 00:00:00',
update_time datetime not null default '0000-00-00 00:00:00',
checksum bigint unsigned default null,
primary key (db_name, table_name)
) engine=MyISAM default charset=utf8 collate=utf8_bin;
create table if not exists mysql.spider_table_crd(
@@ -408,6 +409,11 @@ begin
modify table_name char(199) not null default '';
end if;
-- Fix for version 3.3.15
call mysql.spider_fix_one_table('spider_table_sts', 'checksum',
'alter table mysql.spider_table_sts
add column checksum bigint unsigned default null after update_time');
-- Fix for MariaDB 10.4: Crash-Safe system tables
if @server_name = 'MariaDB' and
(

View File

@@ -2819,23 +2819,20 @@ void *spider_bg_conn_action(
{
switch (conn->bg_simple_action)
{
case SPIDER_BG_SIMPLE_CONNECT:
case SPIDER_SIMPLE_CONNECT:
conn->db_conn->bg_connect();
break;
case SPIDER_BG_SIMPLE_DISCONNECT:
case SPIDER_SIMPLE_DISCONNECT:
conn->db_conn->bg_disconnect();
break;
case SPIDER_BG_SIMPLE_RECORDS:
DBUG_PRINT("info",("spider bg simple records"));
default:
spider = (ha_spider*) conn->bg_target;
*conn->bg_error_num =
spider->dbton_handler[conn->dbton_id]->
show_records(conn->link_idx);
break;
default:
spider_db_simple_action(conn->bg_simple_action,
spider->dbton_handler[conn->dbton_id], conn->link_idx);
break;
}
conn->bg_simple_action = SPIDER_BG_SIMPLE_NO_ACTION;
conn->bg_simple_action = SPIDER_SIMPLE_NO_ACTION;
if (conn->bg_caller_wait)
{
pthread_mutex_lock(&conn->bg_conn_sync_mutex);

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2008-2018 Kentoku Shiba
/* Copyright (C) 2008-2019 Kentoku Shiba
Copyright (C) 2019 MariaDB corp
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
@@ -17,10 +18,13 @@
#define SPIDER_LOCK_MODE_SHARED 1
#define SPIDER_LOCK_MODE_EXCLUSIVE 2
#define SPIDER_BG_SIMPLE_NO_ACTION 0
#define SPIDER_BG_SIMPLE_CONNECT 1
#define SPIDER_BG_SIMPLE_DISCONNECT 2
#define SPIDER_BG_SIMPLE_RECORDS 3
#define SPIDER_SIMPLE_NO_ACTION 0
#define SPIDER_SIMPLE_CONNECT 1
#define SPIDER_SIMPLE_DISCONNECT 2
#define SPIDER_SIMPLE_RECORDS 3
#ifdef HA_HAS_CHECKSUM_EXTENDED
#define SPIDER_SIMPLE_CHECKSUM_TABLE 4
#endif
uchar *spider_conn_get_key(
SPIDER_CONN *conn,

View File

@@ -5684,7 +5684,38 @@ int spider_db_show_table_status(
DBUG_RETURN(error_num);
}
int spider_db_show_records(
int spider_db_simple_action(
uint simple_action,
spider_db_handler *db_handler,
int link_idx
) {
int error_num;
DBUG_ENTER("spider_db_simple_action");
switch (simple_action)
{
case SPIDER_SIMPLE_RECORDS:
DBUG_PRINT("info",("spider simple records"));
error_num = db_handler->show_records(
link_idx
);
break;
#ifdef HA_HAS_CHECKSUM_EXTENDED
case SPIDER_SIMPLE_CHECKSUM_TABLE:
DBUG_PRINT("info",("spider simple checksum_table"));
error_num = db_handler->checksum_table(
link_idx
);
break;
#endif
default:
DBUG_ASSERT(0);
break;
}
DBUG_RETURN(error_num);
}
int spider_db_simple_action(
uint simple_action,
ha_spider *spider,
int link_idx,
bool pre_call
@@ -5692,7 +5723,7 @@ int spider_db_show_records(
int error_num;
THD *thd = spider->trx->thd;
SPIDER_CONN *conn;
DBUG_ENTER("spider_db_show_records");
DBUG_ENTER("spider_db_simple_action");
if (pre_call)
{
if (spider_param_bgs_mode(thd, spider->share->bgs_mode))
@@ -5705,18 +5736,20 @@ int spider_db_show_records(
conn = spider->conns[link_idx];
if (!(error_num = spider_create_conn_thread(conn)))
{
spider_bg_conn_simple_action(conn, SPIDER_BG_SIMPLE_RECORDS, FALSE,
spider_bg_conn_simple_action(conn, simple_action, FALSE,
spider, link_idx, (int *) &spider->result_list.bgs_error);
}
} else {
conn = spider->conns[link_idx];
error_num = spider->dbton_handler[conn->dbton_id]->show_records(
error_num = spider_db_simple_action(
simple_action,
spider->dbton_handler[conn->dbton_id],
link_idx
);
}
} else {
conn = spider->conns[link_idx];
if (spider->use_pre_records)
if (spider->use_pre_action)
{
if (spider_param_bgs_mode(thd, spider->share->bgs_mode))
{
@@ -5730,7 +5763,9 @@ int spider_db_show_records(
error_num = 0;
}
} else {
error_num = spider->dbton_handler[conn->dbton_id]->show_records(
error_num = spider_db_simple_action(
simple_action,
spider->dbton_handler[conn->dbton_id],
link_idx
);
}
@@ -5758,7 +5793,7 @@ void spider_db_set_cardinarity(
{
key_part = &key_info->key_part[roop_count2];
field = key_part->field;
rec_per_key = (ha_rows) share->records /
rec_per_key = (ha_rows) share->stat.records /
share->cardinality[field->field_index];
if (rec_per_key > ~(ulong) 0)
key_info->rec_per_key[roop_count2] = ~(ulong) 0;

View File

@@ -697,7 +697,14 @@ int spider_db_show_table_status(
uint flag
);
int spider_db_show_records(
int spider_db_simple_action(
uint simple_action,
spider_db_handler *db_handler,
int link_idx
);
int spider_db_simple_action(
uint simple_action,
ha_spider *spider,
int link_idx,
bool pre_call

View File

@@ -740,15 +740,7 @@ SPIDER_DB_ROW *spider_db_handlersocket_result::fetch_row_from_tmp_table(
int spider_db_handlersocket_result::fetch_table_status(
int mode,
ha_rows &records,
ulong &mean_rec_length,
ulonglong &data_file_length,
ulonglong &max_data_file_length,
ulonglong &index_file_length,
ulonglong &auto_increment_value,
time_t &create_time,
time_t &update_time,
time_t &check_time
ha_statistics &stat
) {
DBUG_ENTER("spider_db_handlersocket_result::fetch_table_status");
DBUG_PRINT("info",("spider this=%p", this));
@@ -5813,15 +5805,7 @@ int spider_handlersocket_handler::show_table_status(
DBUG_ENTER("spider_handlersocket_show_table_status");
res.fetch_table_status(
sts_mode,
share->records,
share->mean_rec_length,
share->data_file_length,
share->max_data_file_length,
share->index_file_length,
auto_increment_value,
share->create_time,
share->update_time,
share->check_time
share->stat
);
if (auto_increment_value > share->lgtm_tblhnd_share->auto_increment_value)
{

View File

@@ -215,15 +215,7 @@ public:
);
int fetch_table_status(
int mode,
ha_rows &records,
ulong &mean_rec_length,
ulonglong &data_file_length,
ulonglong &max_data_file_length,
ulonglong &index_file_length,
ulonglong &auto_increment_value,
time_t &create_time,
time_t &update_time,
time_t &check_time
ha_statistics &stat
);
int fetch_table_records(
int mode,

View File

@@ -41,6 +41,16 @@ spider_db_result::spider_db_result(
DBUG_VOID_RETURN;
}
#ifdef HA_HAS_CHECKSUM_EXTENDED
int spider_db_result::fetch_table_checksum(
ha_spider *spider
) {
DBUG_ENTER("spider_db_result::fetch_table_checksum");
DBUG_PRINT("info",("spider this=%p", this));
DBUG_RETURN(0);
}
#endif
spider_db_conn::spider_db_conn(
SPIDER_CONN *in_conn
) : conn(in_conn), dbton_id(in_conn->dbton_id)
@@ -49,3 +59,20 @@ spider_db_conn::spider_db_conn(
DBUG_PRINT("info",("spider this=%p", this));
DBUG_VOID_RETURN;
}
#ifdef HA_HAS_CHECKSUM_EXTENDED
bool spider_db_share::checksum_support()
{
DBUG_ENTER("spider_db_share::checksum_support");
DBUG_PRINT("info",("spider this=%p", this));
DBUG_RETURN(FALSE);
}
int spider_db_handler::checksum_table(
int link_idx
) {
DBUG_ENTER("spider_db_handler::checksum_table");
DBUG_PRINT("info",("spider this=%p", this));
DBUG_RETURN(0);
}
#endif

View File

@@ -988,20 +988,17 @@ public:
) = 0;
virtual int fetch_table_status(
int mode,
ha_rows &records,
ulong &mean_rec_length,
ulonglong &data_file_length,
ulonglong &max_data_file_length,
ulonglong &index_file_length,
ulonglong &auto_increment_value,
time_t &create_time,
time_t &update_time,
time_t &check_time
ha_statistics &stat
) = 0;
virtual int fetch_table_records(
int mode,
ha_rows &records
) = 0;
#ifdef HA_HAS_CHECKSUM_EXTENDED
virtual int fetch_table_checksum(
ha_spider *spider
);
#endif
virtual int fetch_table_cardinality(
int mode,
TABLE *table,
@@ -1276,6 +1273,9 @@ public:
spider_string *str
) = 0;
#endif
#ifdef HA_HAS_CHECKSUM_EXTENDED
virtual bool checksum_support();
#endif
};
class spider_db_handler
@@ -1644,6 +1644,11 @@ public:
virtual int show_records(
int link_idx
) = 0;
#ifdef HA_HAS_CHECKSUM_EXTENDED
virtual int checksum_table(
int link_idx
);
#endif
virtual int show_last_insert_id(
int link_idx,
ulonglong &last_insert_id

View File

@@ -126,7 +126,7 @@ static const char *name_quote_str = SPIDER_SQL_NAME_QUOTE_STR;
#define SPIDER_SQL_SHOW_TABLE_STATUS_STR "show table status from "
#define SPIDER_SQL_SHOW_TABLE_STATUS_LEN sizeof(SPIDER_SQL_SHOW_TABLE_STATUS_STR) - 1
#define SPIDER_SQL_SELECT_TABLES_STATUS_STR "select `table_rows`,`avg_row_length`,`data_length`,`max_data_length`,`index_length`,`auto_increment`,`create_time`,`update_time`,`check_time` from `information_schema`.`tables` where `table_schema` = "
#define SPIDER_SQL_SELECT_TABLES_STATUS_STR "select `table_rows`,`avg_row_length`,`data_length`,`max_data_length`,`index_length`,`auto_increment`,`create_time`,`update_time`,`check_time`,`checksum` from `information_schema`.`tables` where `table_schema` = "
#define SPIDER_SQL_SELECT_TABLES_STATUS_LEN sizeof(SPIDER_SQL_SELECT_TABLES_STATUS_STR) - 1
#define SPIDER_SQL_SHOW_WARNINGS_STR "show warnings"
#define SPIDER_SQL_SHOW_WARNINGS_LEN sizeof(SPIDER_SQL_SHOW_WARNINGS_STR) - 1
@@ -154,6 +154,15 @@ static const char *name_quote_str = SPIDER_SQL_NAME_QUOTE_STR;
#define SPIDER_SQL_USING_HASH_LEN sizeof(SPIDER_SQL_USING_HASH_STR) - 1
#endif
#define SPIDER_SQL_SHOW_RECORDS_RECORDS_POS 0
#define SPIDER_SQL_EXPLAIN_SELECT_RECORDS_POS 8
#ifdef HA_HAS_CHECKSUM_EXTENDED
#define SPIDER_SQL_CHECKSUM_CHECKSUM_POS 1
#define SPIDER_SQL_CHECKSUM_TABLE_STR "checksum table "
#define SPIDER_SQL_CHECKSUM_TABLE_LEN (sizeof(SPIDER_SQL_CHECKSUM_TABLE_STR) - 1)
#endif
#define SPIDER_SQL_LIKE_STR " like "
#define SPIDER_SQL_LIKE_LEN (sizeof(SPIDER_SQL_LIKE_STR) - 1)
#define SPIDER_SQL_LIMIT1_STR " limit 1"
@@ -787,15 +796,7 @@ SPIDER_DB_ROW *spider_db_mbase_result::fetch_row_from_tmp_table(
int spider_db_mbase_result::fetch_table_status(
int mode,
ha_rows &records,
ulong &mean_rec_length,
ulonglong &data_file_length,
ulonglong &max_data_file_length,
ulonglong &index_file_length,
ulonglong &auto_increment_value,
time_t &create_time,
time_t &update_time,
time_t &check_time
ha_statistics &stat
) {
int error_num;
MYSQL_ROW mysql_row;
@@ -834,47 +835,47 @@ int spider_db_mbase_result::fetch_table_status(
}
if (mysql_row[4])
records =
stat.records =
(ha_rows) my_strtoll10(mysql_row[4], (char**) NULL, &error_num);
else
records = (ha_rows) 0;
stat.records = (ha_rows) 0;
DBUG_PRINT("info",
("spider records=%lld", records));
("spider records=%lld", stat.records));
if (mysql_row[5])
mean_rec_length =
stat.mean_rec_length =
(ulong) my_strtoll10(mysql_row[5], (char**) NULL, &error_num);
else
mean_rec_length = 0;
stat.mean_rec_length = 0;
DBUG_PRINT("info",
("spider mean_rec_length=%lu", mean_rec_length));
("spider mean_rec_length=%lu", stat.mean_rec_length));
if (mysql_row[6])
data_file_length =
stat.data_file_length =
(ulonglong) my_strtoll10(mysql_row[6], (char**) NULL, &error_num);
else
data_file_length = 0;
stat.data_file_length = 0;
DBUG_PRINT("info",
("spider data_file_length=%lld", data_file_length));
("spider data_file_length=%lld", stat.data_file_length));
if (mysql_row[7])
max_data_file_length =
stat.max_data_file_length =
(ulonglong) my_strtoll10(mysql_row[7], (char**) NULL, &error_num);
else
max_data_file_length = 0;
stat.max_data_file_length = 0;
DBUG_PRINT("info",
("spider max_data_file_length=%lld", max_data_file_length));
("spider max_data_file_length=%lld", stat.max_data_file_length));
if (mysql_row[8])
index_file_length =
stat.index_file_length =
(ulonglong) my_strtoll10(mysql_row[8], (char**) NULL, &error_num);
else
index_file_length = 0;
stat.index_file_length = 0;
DBUG_PRINT("info",
("spider index_file_length=%lld", index_file_length));
("spider index_file_length=%lld", stat.index_file_length));
if (mysql_row[10])
auto_increment_value =
stat.auto_increment_value =
(ulonglong) my_strtoll10(mysql_row[10], (char**) NULL, &error_num);
else
auto_increment_value = 1;
stat.auto_increment_value = 1;
DBUG_PRINT("info",
("spider auto_increment_value=%lld", auto_increment_value));
("spider auto_increment_value=%lld", stat.auto_increment_value));
if (mysql_row[11])
{
#ifdef SPIDER_HAS_TIME_STATUS
@@ -883,19 +884,19 @@ int spider_db_mbase_result::fetch_table_status(
SPIDER_str_to_datetime(mysql_row[11], strlen(mysql_row[11]),
&mysql_time, 0, &time_status);
#ifdef MARIADB_BASE_VERSION
create_time = (time_t) my_system_gmt_sec(&mysql_time,
stat.create_time = (time_t) my_system_gmt_sec(&mysql_time,
&not_used_long, &not_used_uint);
#else
create_time = (time_t) my_system_gmt_sec(&mysql_time,
stat.create_time = (time_t) my_system_gmt_sec(&mysql_time,
&not_used_long, &not_used_my_bool);
#endif
} else
create_time = (time_t) 0;
stat.create_time = (time_t) 0;
#ifndef DBUG_OFF
{
struct tm *ts, tmp_ts;
char buf[80];
ts = localtime_r(&create_time, &tmp_ts);
ts = localtime_r(&stat.create_time, &tmp_ts);
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", ts);
DBUG_PRINT("info",("spider create_time=%s", buf));
}
@@ -908,19 +909,19 @@ int spider_db_mbase_result::fetch_table_status(
SPIDER_str_to_datetime(mysql_row[12], strlen(mysql_row[12]),
&mysql_time, 0, &time_status);
#ifdef MARIADB_BASE_VERSION
update_time = (time_t) my_system_gmt_sec(&mysql_time,
stat.update_time = (time_t) my_system_gmt_sec(&mysql_time,
&not_used_long, &not_used_uint);
#else
update_time = (time_t) my_system_gmt_sec(&mysql_time,
stat.update_time = (time_t) my_system_gmt_sec(&mysql_time,
&not_used_long, &not_used_my_bool);
#endif
} else
update_time = (time_t) 0;
stat.update_time = (time_t) 0;
#ifndef DBUG_OFF
{
struct tm *ts, tmp_ts;
char buf[80];
ts = localtime_r(&update_time, &tmp_ts);
ts = localtime_r(&stat.update_time, &tmp_ts);
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", ts);
DBUG_PRINT("info",("spider update_time=%s", buf));
}
@@ -933,66 +934,77 @@ int spider_db_mbase_result::fetch_table_status(
SPIDER_str_to_datetime(mysql_row[13], strlen(mysql_row[13]),
&mysql_time, 0, &time_status);
#ifdef MARIADB_BASE_VERSION
check_time = (time_t) my_system_gmt_sec(&mysql_time,
stat.check_time = (time_t) my_system_gmt_sec(&mysql_time,
&not_used_long, &not_used_uint);
#else
check_time = (time_t) my_system_gmt_sec(&mysql_time,
stat.check_time = (time_t) my_system_gmt_sec(&mysql_time,
&not_used_long, &not_used_my_bool);
#endif
} else
check_time = (time_t) 0;
stat.check_time = (time_t) 0;
#ifndef DBUG_OFF
{
struct tm *ts, tmp_ts;
char buf[80];
ts = localtime_r(&check_time, &tmp_ts);
ts = localtime_r(&stat.check_time, &tmp_ts);
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", ts);
DBUG_PRINT("info",("spider check_time=%s", buf));
}
#endif
if (mysql_row[15])
{
stat.checksum_null = FALSE;
stat.checksum =
(ha_checksum) my_strtoll10(mysql_row[15], (char**) NULL, &error_num);
DBUG_PRINT("info", ("spider checksum=%lu", (ulong) stat.checksum));
} else {
stat.checksum_null = TRUE;
stat.checksum = (ha_checksum) 0;
DBUG_PRINT("info", ("spider checksum is null"));
}
} else {
if (mysql_row[0])
records =
stat.records =
(ha_rows) my_strtoll10(mysql_row[0], (char**) NULL, &error_num);
else
records = (ha_rows) 0;
stat.records = (ha_rows) 0;
DBUG_PRINT("info",
("spider records=%lld", records));
("spider records=%lld", stat.records));
if (mysql_row[1])
mean_rec_length =
stat.mean_rec_length =
(ulong) my_strtoll10(mysql_row[1], (char**) NULL, &error_num);
else
mean_rec_length = 0;
stat.mean_rec_length = 0;
DBUG_PRINT("info",
("spider mean_rec_length=%lu", mean_rec_length));
("spider mean_rec_length=%lu", stat.mean_rec_length));
if (mysql_row[2])
data_file_length =
stat.data_file_length =
(ulonglong) my_strtoll10(mysql_row[2], (char**) NULL, &error_num);
else
data_file_length = 0;
stat.data_file_length = 0;
DBUG_PRINT("info",
("spider data_file_length=%lld", data_file_length));
("spider data_file_length=%lld", stat.data_file_length));
if (mysql_row[3])
max_data_file_length =
stat.max_data_file_length =
(ulonglong) my_strtoll10(mysql_row[3], (char**) NULL, &error_num);
else
max_data_file_length = 0;
stat.max_data_file_length = 0;
DBUG_PRINT("info",
("spider max_data_file_length=%lld", max_data_file_length));
("spider max_data_file_length=%lld", stat.max_data_file_length));
if (mysql_row[4])
index_file_length =
stat.index_file_length =
(ulonglong) my_strtoll10(mysql_row[4], (char**) NULL, &error_num);
else
index_file_length = 0;
stat.index_file_length = 0;
DBUG_PRINT("info",
("spider index_file_length=%lld", index_file_length));
("spider index_file_length=%lld", stat.index_file_length));
if (mysql_row[5])
auto_increment_value =
stat.auto_increment_value =
(ulonglong) my_strtoll10(mysql_row[5], (char**) NULL, &error_num);
else
auto_increment_value = 1;
stat.auto_increment_value = 1;
DBUG_PRINT("info",
("spider auto_increment_value=%lld", auto_increment_value));
("spider auto_increment_value=%lld", stat.auto_increment_value));
if (mysql_row[6])
{
#ifdef SPIDER_HAS_TIME_STATUS
@@ -1001,19 +1013,19 @@ int spider_db_mbase_result::fetch_table_status(
SPIDER_str_to_datetime(mysql_row[6], strlen(mysql_row[6]),
&mysql_time, 0, &time_status);
#ifdef MARIADB_BASE_VERSION
create_time = (time_t) my_system_gmt_sec(&mysql_time,
stat.create_time = (time_t) my_system_gmt_sec(&mysql_time,
&not_used_long, &not_used_uint);
#else
create_time = (time_t) my_system_gmt_sec(&mysql_time,
stat.create_time = (time_t) my_system_gmt_sec(&mysql_time,
&not_used_long, &not_used_my_bool);
#endif
} else
create_time = (time_t) 0;
stat.create_time = (time_t) 0;
#ifndef DBUG_OFF
{
struct tm *ts, tmp_ts;
char buf[80];
ts = localtime_r(&create_time, &tmp_ts);
ts = localtime_r(&stat.create_time, &tmp_ts);
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", ts);
DBUG_PRINT("info",("spider create_time=%s", buf));
}
@@ -1026,19 +1038,19 @@ int spider_db_mbase_result::fetch_table_status(
SPIDER_str_to_datetime(mysql_row[7], strlen(mysql_row[7]),
&mysql_time, 0, &time_status);
#ifdef MARIADB_BASE_VERSION
update_time = (time_t) my_system_gmt_sec(&mysql_time,
stat.update_time = (time_t) my_system_gmt_sec(&mysql_time,
&not_used_long, &not_used_uint);
#else
update_time = (time_t) my_system_gmt_sec(&mysql_time,
stat.update_time = (time_t) my_system_gmt_sec(&mysql_time,
&not_used_long, &not_used_my_bool);
#endif
} else
update_time = (time_t) 0;
stat.update_time = (time_t) 0;
#ifndef DBUG_OFF
{
struct tm *ts, tmp_ts;
char buf[80];
ts = localtime_r(&update_time, &tmp_ts);
ts = localtime_r(&stat.update_time, &tmp_ts);
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", ts);
DBUG_PRINT("info",("spider update_time=%s", buf));
}
@@ -1051,34 +1063,46 @@ int spider_db_mbase_result::fetch_table_status(
SPIDER_str_to_datetime(mysql_row[8], strlen(mysql_row[8]),
&mysql_time, 0, &time_status);
#ifdef MARIADB_BASE_VERSION
check_time = (time_t) my_system_gmt_sec(&mysql_time,
stat.check_time = (time_t) my_system_gmt_sec(&mysql_time,
&not_used_long, &not_used_uint);
#else
check_time = (time_t) my_system_gmt_sec(&mysql_time,
stat.check_time = (time_t) my_system_gmt_sec(&mysql_time,
&not_used_long, &not_used_my_bool);
#endif
} else
check_time = (time_t) 0;
stat.check_time = (time_t) 0;
#ifndef DBUG_OFF
{
struct tm *ts, tmp_ts;
char buf[80];
ts = localtime_r(&check_time, &tmp_ts);
ts = localtime_r(&stat.check_time, &tmp_ts);
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", ts);
DBUG_PRINT("info",("spider check_time=%s", buf));
}
#endif
if (mysql_row[9])
{
stat.checksum_null = FALSE;
stat.checksum =
(ha_checksum) my_strtoll10(mysql_row[9], (char**) NULL, &error_num);
DBUG_PRINT("info", ("spider checksum=%lu", (ulong) stat.checksum));
} else {
stat.checksum_null = TRUE;
stat.checksum = (ha_checksum) 0;
DBUG_PRINT("info", ("spider checksum is null"));
}
}
DBUG_RETURN(0);
}
int spider_db_mbase_result::fetch_table_records(
int mode,
ha_rows &records
int spider_db_mbase_result::fetch_simple_action(
uint simple_action,
uint position,
void *param
) {
int error_num;
MYSQL_ROW mysql_row;
DBUG_ENTER("spider_db_mbase_result::fetch_table_records");
DBUG_ENTER("spider_db_mbase_result::fetch_simple_action");
DBUG_PRINT("info",("spider this=%p", this));
if (!(mysql_row = mysql_fetch_row(db_result)))
{
@@ -1091,32 +1115,78 @@ int spider_db_mbase_result::fetch_table_records(
}
DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE);
}
if (mode == 1)
if (num_fields() <= position)
{
if (mysql_row[0])
DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE);
}
switch (simple_action)
{
case SPIDER_SIMPLE_RECORDS:
{
records =
(ha_rows) my_strtoll10(mysql_row[0], (char**) NULL, &error_num);
} else
records = (ha_rows) 0;
DBUG_PRINT("info",
("spider records=%lld", records));
} else {
if (num_fields() != 10)
{
DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE);
ha_rows *records = (ha_rows *) param;
if (mysql_row[position])
{
*records =
(ha_rows) my_strtoll10(mysql_row[position], (char**) NULL,
&error_num);
} else {
*records = (ha_rows) 0;
}
DBUG_PRINT("info", ("spider records=%lld", *records));
break;
}
if (mysql_row[8])
#ifdef HA_HAS_CHECKSUM_EXTENDED
case SPIDER_SIMPLE_CHECKSUM_TABLE:
{
records =
(ha_rows) my_strtoll10(mysql_row[8], (char**) NULL, &error_num);
} else
records = 0;
ha_spider *spider = (ha_spider *) param;
if (mysql_row[position])
{
spider->checksum_val =
(ulonglong) my_strtoll10(mysql_row[position], (char**) NULL,
&error_num);
DBUG_PRINT("info", ("spider checksum=%llu", spider->checksum_val));
spider->checksum_null = FALSE;
} else {
spider->checksum_null = TRUE;
DBUG_PRINT("info", ("spider checksum is null"));
}
break;
}
#endif
default:
DBUG_ASSERT(0);
break;
}
DBUG_RETURN(0);
}
int spider_db_mbase_result::fetch_table_records(
int mode,
ha_rows &records
) {
DBUG_ENTER("spider_db_mbase_result::fetch_table_records");
DBUG_PRINT("info",("spider this=%p", this));
if (mode == 1)
{
DBUG_RETURN(fetch_simple_action(SPIDER_SIMPLE_RECORDS,
SPIDER_SQL_SHOW_RECORDS_RECORDS_POS, &records));
} else {
DBUG_RETURN(fetch_simple_action(SPIDER_SIMPLE_RECORDS,
SPIDER_SQL_EXPLAIN_SELECT_RECORDS_POS, &records));
}
}
#ifdef HA_HAS_CHECKSUM_EXTENDED
int spider_db_mbase_result::fetch_table_checksum(
ha_spider *spider
) {
DBUG_ENTER("spider_db_mbase_result::fetch_table_checksum");
DBUG_PRINT("info",("spider this=%p", this));
DBUG_RETURN(fetch_simple_action(SPIDER_SIMPLE_CHECKSUM_TABLE,
SPIDER_SQL_CHECKSUM_CHECKSUM_POS, spider));
}
#endif
int spider_db_mbase_result::fetch_table_cardinality(
int mode,
TABLE *table,
@@ -6770,6 +6840,15 @@ int spider_mbase_share::discover_table_structure(
}
#endif
#ifdef HA_HAS_CHECKSUM_EXTENDED
bool spider_mbase_share::checksum_support()
{
DBUG_ENTER("spider_mbase_share::checksum_support");
DBUG_PRINT("info",("spider this=%p", this));
DBUG_RETURN(TRUE);
}
#endif
spider_mbase_handler::spider_mbase_handler(
ha_spider *spider,
spider_mbase_share *db_share,
@@ -12260,16 +12339,9 @@ int spider_mbase_handler::show_table_status(
pthread_mutex_unlock(&conn->mta_conn_mutex);
error_num = res->fetch_table_status(
sts_mode,
share->records,
share->mean_rec_length,
share->data_file_length,
share->max_data_file_length,
share->index_file_length,
auto_increment_value,
share->create_time,
share->update_time,
share->check_time
share->stat
);
auto_increment_value = share->stat.auto_increment_value;
res->free_result();
delete res;
if (error_num)
@@ -12394,16 +12466,9 @@ int spider_mbase_handler::show_table_status(
pthread_mutex_unlock(&conn->mta_conn_mutex);
error_num = res->fetch_table_status(
sts_mode,
share->records,
share->mean_rec_length,
share->data_file_length,
share->max_data_file_length,
share->index_file_length,
auto_increment_value,
share->create_time,
share->update_time,
share->check_time
share->stat
);
auto_increment_value = share->stat.auto_increment_value;
res->free_result();
delete res;
if (error_num)
@@ -12432,11 +12497,11 @@ int spider_mbase_handler::show_table_status(
}
if (share->static_records_for_status != -1)
{
share->records = (ha_rows) share->static_records_for_status;
share->stat.records = (ha_rows) share->static_records_for_status;
}
if (share->static_mean_rec_length != -1)
{
share->mean_rec_length = (ulong) share->static_mean_rec_length;
share->stat.mean_rec_length = (ulong) share->static_mean_rec_length;
}
if (auto_increment_value > share->lgtm_tblhnd_share->auto_increment_value)
{
@@ -12740,7 +12805,8 @@ int spider_mbase_handler::show_index(
DBUG_RETURN(0);
}
int spider_mbase_handler::show_records(
int spider_mbase_handler::simple_action(
uint simple_action,
int link_idx
) {
int error_num;
@@ -12748,7 +12814,49 @@ int spider_mbase_handler::show_records(
SPIDER_DB_RESULT *res;
SPIDER_SHARE *share = spider->share;
uint pos = spider->conn_link_idx[link_idx];
DBUG_ENTER("spider_mbase_handler::show_records");
spider_string *str;
DBUG_ENTER("spider_mbase_handler::simple_action");
switch (simple_action)
{
case SPIDER_SIMPLE_RECORDS:
DBUG_PRINT("info",("spider simple records"));
str = &mysql_share->show_records[pos];
break;
#ifdef HA_HAS_CHECKSUM_EXTENDED
case SPIDER_SIMPLE_CHECKSUM_TABLE:
DBUG_PRINT("info",("spider simple checksum_table"));
str = &spider->result_list.sqls[link_idx];
str->length(0);
if (str->reserve(
SPIDER_SQL_CHECKSUM_TABLE_LEN +
mysql_share->db_nm_max_length +
SPIDER_SQL_DOT_LEN +
mysql_share->table_nm_max_length +
/* SPIDER_SQL_NAME_QUOTE_LEN */ 4 +
((spider->action_flags & T_QUICK) ? SPIDER_SQL_SQL_QUICK_LEN : 0) +
((spider->action_flags & T_EXTEND) ? SPIDER_SQL_SQL_EXTENDED_LEN : 0)
))
{
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
}
str->q_append(SPIDER_SQL_CHECKSUM_TABLE_STR,
SPIDER_SQL_CHECKSUM_TABLE_LEN);
mysql_share->append_table_name(str, pos);
if (spider->action_flags & T_QUICK)
{
str->q_append(SPIDER_SQL_SQL_QUICK_STR, SPIDER_SQL_SQL_QUICK_LEN);
}
if (spider->action_flags & T_EXTEND)
{
str->q_append(SPIDER_SQL_SQL_EXTENDED_STR,
SPIDER_SQL_SQL_EXTENDED_LEN);
}
break;
#endif
default:
DBUG_ASSERT(0);
break;
}
pthread_mutex_lock(&conn->mta_conn_mutex);
SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
conn->need_mon = &spider->need_mons[link_idx];
@@ -12761,8 +12869,8 @@ int spider_mbase_handler::show_records(
(
spider_db_query(
conn,
mysql_share->show_records[pos].ptr(),
mysql_share->show_records[pos].length(),
str->ptr(),
str->length(),
-1,
&spider->need_mons[link_idx]) &&
(error_num = spider_db_errorno(conn))
@@ -12795,8 +12903,8 @@ int spider_mbase_handler::show_records(
share);
if (spider_db_query(
conn,
mysql_share->show_records[pos].ptr(),
mysql_share->show_records[pos].length(),
str->ptr(),
str->length(),
-1,
&spider->need_mons[link_idx])
) {
@@ -12838,10 +12946,22 @@ int spider_mbase_handler::show_records(
conn->mta_conn_mutex_unlock_later = FALSE;
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
pthread_mutex_unlock(&conn->mta_conn_mutex);
error_num = res->fetch_table_records(
1,
spider->table_rows
);
switch (simple_action)
{
case SPIDER_SIMPLE_RECORDS:
DBUG_PRINT("info",("spider simple records"));
error_num = res->fetch_table_records(1, spider->table_rows);
break;
#ifdef HA_HAS_CHECKSUM_EXTENDED
case SPIDER_SIMPLE_CHECKSUM_TABLE:
DBUG_PRINT("info",("spider simple checksum_table"));
error_num = res->fetch_table_checksum(spider);
break;
#endif
default:
DBUG_ASSERT(0);
break;
}
res->free_result();
delete res;
if (error_num)
@@ -12849,10 +12969,34 @@ int spider_mbase_handler::show_records(
DBUG_PRINT("info", ("spider error_num=%d 7", error_num));
DBUG_RETURN(error_num);
}
DBUG_RETURN(0);
}
int spider_mbase_handler::show_records(
int link_idx
) {
int error_num;
DBUG_ENTER("spider_mbase_handler::show_records");
error_num = simple_action(SPIDER_SIMPLE_RECORDS, link_idx);
if (error_num)
{
DBUG_PRINT("info", ("spider error_num=%d", error_num));
DBUG_RETURN(error_num);
}
spider->trx->direct_aggregate_count++;
DBUG_RETURN(0);
}
#ifdef HA_HAS_CHECKSUM_EXTENDED
int spider_mbase_handler::checksum_table(
int link_idx
) {
DBUG_ENTER("spider_mbase_handler::checksum_table");
DBUG_RETURN(simple_action(SPIDER_SIMPLE_CHECKSUM_TABLE, link_idx));
DBUG_RETURN(0);
}
#endif
int spider_mbase_handler::show_last_insert_id(
int link_idx,
ulonglong &last_insert_id

View File

@@ -271,20 +271,22 @@ public:
);
int fetch_table_status(
int mode,
ha_rows &records,
ulong &mean_rec_length,
ulonglong &data_file_length,
ulonglong &max_data_file_length,
ulonglong &index_file_length,
ulonglong &auto_increment_value,
time_t &create_time,
time_t &update_time,
time_t &check_time
ha_statistics &stat
);
int fetch_simple_action(
uint simple_action,
uint position,
void *param
);
int fetch_table_records(
int mode,
ha_rows &records
);
#ifdef HA_HAS_CHECKSUM_EXTENDED
int fetch_table_checksum(
ha_spider *spider
);
#endif
int fetch_table_cardinality(
int mode,
TABLE *table,
@@ -669,6 +671,9 @@ public:
spider_string *str
);
#endif
#ifdef HA_HAS_CHECKSUM_EXTENDED
bool checksum_support();
#endif
protected:
int create_table_names_str();
void free_table_names_str();
@@ -1448,9 +1453,18 @@ public:
int link_idx,
int crd_mode
);
int simple_action(
uint simple_action,
int link_idx
);
int show_records(
int link_idx
);
#ifdef HA_HAS_CHECKSUM_EXTENDED
int checksum_table(
int link_idx
);
#endif
int show_last_insert_id(
int link_idx,
ulonglong &last_insert_id

View File

@@ -927,30 +927,22 @@ SPIDER_DB_ROW *spider_db_oracle_result::fetch_row_from_tmp_table(
int spider_db_oracle_result::fetch_table_status(
int mode,
ha_rows &records,
ulong &mean_rec_length,
ulonglong &data_file_length,
ulonglong &max_data_file_length,
ulonglong &index_file_length,
ulonglong &auto_increment_value,
time_t &create_time,
time_t &update_time,
time_t &check_time
ha_statistics &stat
) {
DBUG_ENTER("spider_db_oracle_result::fetch_table_status");
DBUG_PRINT("info",("spider this=%p", this));
/* TODO: develop later */
records = 2;
mean_rec_length = 65535;
data_file_length = 65535;
max_data_file_length = 65535;
index_file_length = 65535;
stat.records = 2;
stat.mean_rec_length = 65535;
stat.data_file_length = 65535;
stat.max_data_file_length = 65535;
stat.index_file_length = 65535;
/*
auto_increment_value = 0;
*/
create_time = (time_t) 0;
update_time = (time_t) 0;
check_time = (time_t) 0;
stat.create_time = (time_t) 0;
stat.update_time = (time_t) 0;
stat.check_time = (time_t) 0;
DBUG_RETURN(0);
}
@@ -1349,7 +1341,7 @@ int spider_db_oracle::connect(
this->connect_retry_interval = connect_retry_interval;
if ((error_num = spider_create_conn_thread(conn)))
DBUG_RETURN(error_num);
spider_bg_conn_simple_action(conn, SPIDER_BG_SIMPLE_CONNECT, TRUE, NULL,
spider_bg_conn_simple_action(conn, SPIDER_SIMPLE_CONNECT, TRUE, NULL,
0, NULL);
if (stored_error_num)
@@ -1440,7 +1432,7 @@ void spider_db_oracle::disconnect()
DBUG_PRINT("info",("spider this=%p", this));
if (!conn->bg_init)
DBUG_VOID_RETURN;
spider_bg_conn_simple_action(conn, SPIDER_BG_SIMPLE_DISCONNECT, TRUE, NULL,
spider_bg_conn_simple_action(conn, SPIDER_SIMPLE_DISCONNECT, TRUE, NULL,
0, NULL);
DBUG_VOID_RETURN;
}
@@ -11143,15 +11135,15 @@ int spider_oracle_handler::show_table_status(
if (error_num)
DBUG_RETURN(error_num);
*/
if (!share->records)
share->records = 10000;
share->mean_rec_length = 65535;
share->data_file_length = 65535;
share->max_data_file_length = 65535;
share->index_file_length = 65535;
share->create_time = (time_t) 0;
share->update_time = (time_t) 0;
share->check_time = (time_t) 0;
if (!share->stat.records)
share->stat.records = 10000;
share->stat.mean_rec_length = 65535;
share->stat.data_file_length = 65535;
share->stat.max_data_file_length = 65535;
share->stat.index_file_length = 65535;
share->stat.create_time = (time_t) 0;
share->stat.update_time = (time_t) 0;
share->stat.check_time = (time_t) 0;
} else {
pthread_mutex_lock(&conn->mta_conn_mutex);
SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
@@ -11235,16 +11227,9 @@ int spider_oracle_handler::show_table_status(
pthread_mutex_unlock(&conn->mta_conn_mutex);
error_num = res->fetch_table_status(
sts_mode,
share->records,
share->mean_rec_length,
share->data_file_length,
share->max_data_file_length,
share->index_file_length,
auto_increment_value,
share->create_time,
share->update_time,
share->check_time
share->stat
);
auto_increment_value = share->stat.auto_increment_value;
res->free_result();
delete res;
if (error_num)

View File

@@ -239,15 +239,7 @@ public:
);
int fetch_table_status(
int mode,
ha_rows &records,
ulong &mean_rec_length,
ulonglong &data_file_length,
ulonglong &max_data_file_length,
ulonglong &index_file_length,
ulonglong &auto_increment_value,
time_t &create_time,
time_t &update_time,
time_t &check_time
ha_statistics &stat
);
int fetch_table_records(
int mode,

View File

@@ -51,5 +51,6 @@
#define SPIDER_USE_CONST_ITEM_FOR_STRING_INT_REAL_DECIMAL_DATE_ITEM
#define SPIDER_SQL_CACHE_IS_IN_LEX
#define SPIDER_LIKE_FUNC_HAS_GET_NEGATED
#define HA_HAS_CHECKSUM_EXTENDED
#endif
#endif /* SPD_ENVIRON_INCLUDED */

View File

@@ -13,7 +13,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
#define SPIDER_DETAIL_VERSION "3.3.14"
#define SPIDER_DETAIL_VERSION "3.3.15"
#define SPIDER_HEX_VERSION 0x0303
#if MYSQL_VERSION_ID < 50500
@@ -655,15 +655,7 @@ typedef struct st_spider_patition_share
volatile bool crd_init;
volatile time_t sts_get_time;
volatile time_t crd_get_time;
ulonglong data_file_length;
ulonglong max_data_file_length;
ulonglong index_file_length;
ulonglong auto_increment_value;
ha_rows records;
ulong mean_rec_length;
time_t check_time;
time_t create_time;
time_t update_time;
ha_statistics stat;
longlong *cardinality;
/*
@@ -890,17 +882,7 @@ typedef struct st_spider_share
volatile bool auto_increment_init;
volatile ulonglong auto_increment_lclval;
*/
ulonglong data_file_length;
ulonglong max_data_file_length;
ulonglong index_file_length;
/*
ulonglong auto_increment_value;
*/
ha_rows records;
ulong mean_rec_length;
time_t check_time;
time_t create_time;
time_t update_time;
ha_statistics stat;
longlong static_records_for_status;
longlong static_mean_rec_length;

View File

@@ -1,4 +1,5 @@
/* Copyright (C) 2012-2017 Kentoku Shiba
/* Copyright (C) 2012-2019 Kentoku Shiba
Copyright (C) 2019 MariaDB corp
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
@@ -1126,6 +1127,7 @@ void spider_string::q_append(
) {
DBUG_ENTER("spider_string::q_append");
DBUG_PRINT("info",("spider this=%p", this));
DBUG_ASSERT(str.alloced_length() >= str.length() + data_len);
str.q_append(data, data_len);
DBUG_VOID_RETURN;
}

View File

@@ -1240,28 +1240,29 @@ void spider_store_binlog_pos_gtid(
void spider_store_table_sts_info(
TABLE *table,
ulonglong *data_file_length,
ulonglong *max_data_file_length,
ulonglong *index_file_length,
ha_rows *records,
ulong *mean_rec_length,
time_t *check_time,
time_t *create_time,
time_t *update_time
ha_statistics *stat
) {
MYSQL_TIME mysql_time;
DBUG_ENTER("spider_store_table_sts_info");
table->field[2]->store((longlong) *data_file_length, TRUE);
table->field[3]->store((longlong) *max_data_file_length, TRUE);
table->field[4]->store((longlong) *index_file_length, TRUE);
table->field[5]->store((longlong) *records, TRUE);
table->field[6]->store((longlong) *mean_rec_length, TRUE);
spd_tz_system->gmt_sec_to_TIME(&mysql_time, (my_time_t) *check_time);
table->field[2]->store((longlong) stat->data_file_length, TRUE);
table->field[3]->store((longlong) stat->max_data_file_length, TRUE);
table->field[4]->store((longlong) stat->index_file_length, TRUE);
table->field[5]->store((longlong) stat->records, TRUE);
table->field[6]->store((longlong) stat->mean_rec_length, TRUE);
spd_tz_system->gmt_sec_to_TIME(&mysql_time, (my_time_t) stat->check_time);
table->field[7]->store_time(&mysql_time);
spd_tz_system->gmt_sec_to_TIME(&mysql_time, (my_time_t) *create_time);
spd_tz_system->gmt_sec_to_TIME(&mysql_time, (my_time_t) stat->create_time);
table->field[8]->store_time(&mysql_time);
spd_tz_system->gmt_sec_to_TIME(&mysql_time, (my_time_t) *update_time);
spd_tz_system->gmt_sec_to_TIME(&mysql_time, (my_time_t) stat->update_time);
table->field[9]->store_time(&mysql_time);
if (stat->checksum_null)
{
table->field[10]->set_null();
table->field[10]->reset();
} else {
table->field[10]->set_notnull();
table->field[10]->store((longlong) stat->checksum, TRUE);
}
DBUG_VOID_RETURN;
}
@@ -1386,14 +1387,7 @@ int spider_insert_or_update_table_sts(
TABLE *table,
const char *name,
uint name_length,
ulonglong *data_file_length,
ulonglong *max_data_file_length,
ulonglong *index_file_length,
ha_rows *records,
ulong *mean_rec_length,
time_t *check_time,
time_t *create_time,
time_t *update_time
ha_statistics *stat
) {
int error_num;
char table_key[MAX_KEY_LENGTH];
@@ -1402,14 +1396,7 @@ int spider_insert_or_update_table_sts(
spider_store_tables_name(table, name, name_length);
spider_store_table_sts_info(
table,
data_file_length,
max_data_file_length,
index_file_length,
records,
mean_rec_length,
check_time,
create_time,
update_time
stat
);
if ((error_num = spider_check_sys_table_for_update_all_columns(table, table_key)))
@@ -2442,14 +2429,7 @@ int spider_get_sys_tables_static_link_id(
void spider_get_sys_table_sts_info(
TABLE *table,
ulonglong *data_file_length,
ulonglong *max_data_file_length,
ulonglong *index_file_length,
ha_rows *records,
ulong *mean_rec_length,
time_t *check_time,
time_t *create_time,
time_t *update_time
ha_statistics *stat
) {
MYSQL_TIME mysql_time;
#ifdef MARIADB_BASE_VERSION
@@ -2459,35 +2439,43 @@ void spider_get_sys_table_sts_info(
#endif
long not_used_long;
DBUG_ENTER("spider_get_sys_table_sts_info");
*data_file_length = (ulonglong) table->field[2]->val_int();
*max_data_file_length = (ulonglong) table->field[3]->val_int();
*index_file_length = (ulonglong) table->field[4]->val_int();
*records = (ha_rows) table->field[5]->val_int();
*mean_rec_length = (ulong) table->field[6]->val_int();
stat->data_file_length = (ulonglong) table->field[2]->val_int();
stat->max_data_file_length = (ulonglong) table->field[3]->val_int();
stat->index_file_length = (ulonglong) table->field[4]->val_int();
stat->records = (ha_rows) table->field[5]->val_int();
stat->mean_rec_length = (ulong) table->field[6]->val_int();
table->field[7]->get_date(&mysql_time, SPIDER_date_mode_t(0));
#ifdef MARIADB_BASE_VERSION
*check_time = (time_t) my_system_gmt_sec(&mysql_time,
stat->check_time = (time_t) my_system_gmt_sec(&mysql_time,
&not_used_long, &not_used_uint);
#else
*check_time = (time_t) my_system_gmt_sec(&mysql_time,
stat->check_time = (time_t) my_system_gmt_sec(&mysql_time,
&not_used_long, &not_used_my_bool);
#endif
table->field[8]->get_date(&mysql_time, SPIDER_date_mode_t(0));
#ifdef MARIADB_BASE_VERSION
*create_time = (time_t) my_system_gmt_sec(&mysql_time,
stat->create_time = (time_t) my_system_gmt_sec(&mysql_time,
&not_used_long, &not_used_uint);
#else
*create_time = (time_t) my_system_gmt_sec(&mysql_time,
stat->create_time = (time_t) my_system_gmt_sec(&mysql_time,
&not_used_long, &not_used_my_bool);
#endif
table->field[9]->get_date(&mysql_time, SPIDER_date_mode_t(0));
#ifdef MARIADB_BASE_VERSION
*update_time = (time_t) my_system_gmt_sec(&mysql_time,
stat->update_time = (time_t) my_system_gmt_sec(&mysql_time,
&not_used_long, &not_used_uint);
#else
*update_time = (time_t) my_system_gmt_sec(&mysql_time,
stat->update_time = (time_t) my_system_gmt_sec(&mysql_time,
&not_used_long, &not_used_my_bool);
#endif
if (table->field[10]->is_null())
{
stat->checksum_null = TRUE;
stat->checksum = 0;
} else {
stat->checksum_null = FALSE;
stat->checksum = (ha_checksum) table->field[10]->val_int();
}
DBUG_VOID_RETURN;
}
@@ -2908,14 +2896,7 @@ int spider_sys_insert_or_update_table_sts(
THD *thd,
const char *name,
uint name_length,
ulonglong *data_file_length,
ulonglong *max_data_file_length,
ulonglong *index_file_length,
ha_rows *records,
ulong *mean_rec_length,
time_t *check_time,
time_t *create_time,
time_t *update_time,
ha_statistics *stat,
bool need_lock
) {
int error_num;
@@ -2938,14 +2919,7 @@ int spider_sys_insert_or_update_table_sts(
table_sts,
name,
name_length,
data_file_length,
max_data_file_length,
index_file_length,
records,
mean_rec_length,
check_time,
create_time,
update_time
stat
)))
goto error;
spider_close_sys_table(thd, table_sts, &open_tables_backup, need_lock);
@@ -3080,14 +3054,7 @@ int spider_sys_get_table_sts(
THD *thd,
const char *name,
uint name_length,
ulonglong *data_file_length,
ulonglong *max_data_file_length,
ulonglong *index_file_length,
ha_rows *records,
ulong *mean_rec_length,
time_t *check_time,
time_t *create_time,
time_t *update_time,
ha_statistics *stat,
bool need_lock
) {
int error_num;
@@ -3120,14 +3087,7 @@ int spider_sys_get_table_sts(
} else {
spider_get_sys_table_sts_info(
table_sts,
data_file_length,
max_data_file_length,
index_file_length,
records,
mean_rec_length,
check_time,
create_time,
update_time
stat
);
}

View File

@@ -289,14 +289,7 @@ void spider_store_binlog_pos_gtid(
void spider_store_table_sts_info(
TABLE *table,
ulonglong *data_file_length,
ulonglong *max_data_file_length,
ulonglong *index_file_length,
ha_rows *records,
ulong *mean_rec_length,
time_t *check_time,
time_t *create_time,
time_t *update_time
ha_statistics *stat
);
void spider_store_table_crd_info(
@@ -330,14 +323,7 @@ int spider_insert_or_update_table_sts(
TABLE *table,
const char *name,
uint name_length,
ulonglong *data_file_length,
ulonglong *max_data_file_length,
ulonglong *index_file_length,
ha_rows *records,
ulong *mean_rec_length,
time_t *check_time,
time_t *create_time,
time_t *update_time
ha_statistics *stat
);
int spider_insert_or_update_table_crd(
@@ -493,14 +479,7 @@ int spider_get_sys_tables_static_link_id(
void spider_get_sys_table_sts_info(
TABLE *table,
ulonglong *data_file_length,
ulonglong *max_data_file_length,
ulonglong *index_file_length,
ha_rows *records,
ulong *mean_rec_length,
time_t *check_time,
time_t *create_time,
time_t *update_time
ha_statistics *stat
);
void spider_get_sys_table_crd_info(
@@ -564,14 +543,7 @@ int spider_sys_insert_or_update_table_sts(
THD *thd,
const char *name,
uint name_length,
ulonglong *data_file_length,
ulonglong *max_data_file_length,
ulonglong *index_file_length,
ha_rows *records,
ulong *mean_rec_length,
time_t *check_time,
time_t *create_time,
time_t *update_time,
ha_statistics *stat,
bool need_lock
);
@@ -602,14 +574,7 @@ int spider_sys_get_table_sts(
THD *thd,
const char *name,
uint name_length,
ulonglong *data_file_length,
ulonglong *max_data_file_length,
ulonglong *index_file_length,
ha_rows *records,
ulong *mean_rec_length,
time_t *check_time,
time_t *create_time,
time_t *update_time,
ha_statistics *stat,
bool need_lock
);

View File

@@ -4378,6 +4378,9 @@ SPIDER_SHARE *spider_create_share(
uchar *tmp_cardinality_upd, *tmp_table_mon_mutex_bitmap;
char buf[MAX_FIELD_WIDTH], *buf_pos;
char link_idx_str[SPIDER_SQL_INT_LEN];
#ifdef HA_HAS_CHECKSUM_EXTENDED
bool checksum_support = TRUE;
#endif
DBUG_ENTER("spider_create_share");
length = (uint) strlen(table_name);
bitmap_size = spider_bitmap_size(table_share->fields);
@@ -4536,8 +4539,24 @@ SPIDER_SHARE *spider_create_share(
{
goto error_init_dbton;
}
#ifdef HA_HAS_CHECKSUM_EXTENDED
if (
spider_dbton[roop_count].db_access_type == SPIDER_DB_ACCESS_TYPE_SQL &&
!share->dbton_share[roop_count]->checksum_support()
) {
checksum_support = FALSE;
}
#endif
}
}
#ifdef HA_HAS_CHECKSUM_EXTENDED
if (checksum_support)
{
share->additional_table_flags |=
HA_HAS_OLD_CHECKSUM |
HA_HAS_NEW_CHECKSUM;
}
#endif
DBUG_RETURN(share);
/*
@@ -5780,14 +5799,7 @@ int spider_free_share(
thd,
share->lgtm_tblhnd_share->table_name,
share->lgtm_tblhnd_share->table_name_length,
&share->data_file_length,
&share->max_data_file_length,
&share->index_file_length,
&share->records,
&share->mean_rec_length,
&share->check_time,
&share->create_time,
&share->update_time,
&share->stat,
FALSE
);
}
@@ -6163,21 +6175,7 @@ void spider_copy_sts_to_pt_share(
SPIDER_SHARE *share
) {
DBUG_ENTER("spider_copy_sts_to_pt_share");
memcpy(&partition_share->data_file_length, &share->data_file_length,
sizeof(ulonglong) * 4 + sizeof(ha_rows) +
sizeof(ulong) + sizeof(time_t) * 3);
/*
partition_share->data_file_length = share->data_file_length;
partition_share->max_data_file_length = share->max_data_file_length;
partition_share->index_file_length = share->index_file_length;
partition_share->auto_increment_value =
share->lgtm_tblhnd_share->auto_increment_value;
partition_share->records = share->records;
partition_share->mean_rec_length = share->mean_rec_length;
partition_share->check_time = share->check_time;
partition_share->create_time = share->create_time;
partition_share->update_time = share->update_time;
*/
partition_share->stat = share->stat;
DBUG_VOID_RETURN;
}
@@ -6186,23 +6184,7 @@ void spider_copy_sts_to_share(
SPIDER_PARTITION_SHARE *partition_share
) {
DBUG_ENTER("spider_copy_sts_to_share");
memcpy(&share->data_file_length, &partition_share->data_file_length,
sizeof(ulonglong) * 4 + sizeof(ha_rows) +
sizeof(ulong) + sizeof(time_t) * 3);
/*
share->data_file_length = partition_share->data_file_length;
share->max_data_file_length = partition_share->max_data_file_length;
share->index_file_length = partition_share->index_file_length;
share->lgtm_tblhnd_share->auto_increment_value =
partition_share->auto_increment_value;
DBUG_PRINT("info",("spider auto_increment_value=%llu",
share->lgtm_tblhnd_share->auto_increment_value));
share->records = partition_share->records;
share->mean_rec_length = partition_share->mean_rec_length;
share->check_time = partition_share->check_time;
share->create_time = partition_share->create_time;
share->update_time = partition_share->update_time;
*/
share->stat = partition_share->stat;
DBUG_VOID_RETURN;
}
@@ -7693,10 +7675,8 @@ int spider_get_sts(
if (
sts_sync == 0
) {
#endif
/* get */
get_type = 1;
#ifdef WITH_PARTITION_STORAGE_ENGINE
} else if (
!share->partition_share->sts_init
) {
@@ -7735,14 +7715,7 @@ int spider_get_sts(
current_thd,
share->lgtm_tblhnd_share->table_name,
share->lgtm_tblhnd_share->table_name_length,
&share->data_file_length,
&share->max_data_file_length,
&share->index_file_length,
&share->records,
&share->mean_rec_length,
&share->check_time,
&share->create_time,
&share->update_time,
&share->stat,
FALSE
);
if (
@@ -7850,10 +7823,8 @@ int spider_get_crd(
if (
crd_sync == 0
) {
#endif
/* get */
get_type = 1;
#ifdef WITH_PARTITION_STORAGE_ENGINE
} else if (
!share->partition_share->crd_init
) {
@@ -9367,7 +9338,9 @@ int spider_discover_table_structure(
str.q_append(share->table_name.str, share->table_name.length);
str.q_append(SPIDER_SQL_LCL_NAME_QUOTE_STR, SPIDER_SQL_LCL_NAME_QUOTE_LEN);
str.q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN);
#ifdef WITH_PARTITION_STORAGE_ENGINE
str_len = str.length();
#endif
#ifdef SPIDER_HAS_HASH_VALUE_TYPE
my_hash_value_type hash_value = my_calc_hash(&spider_open_tables,
(uchar*) table_name, table_name_length);