Commit 24ee346a authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-27590 Auto-increment on Spider tables with DESC PK does not work properly

use index_first for DESC keys
parent d751f42a
......@@ -9288,6 +9288,9 @@ void ha_spider::get_auto_increment(
THD *thd = ha_thd();
int auto_increment_mode = spider_param_auto_increment_mode(thd,
share->auto_increment_mode);
bool rev= table->key_info[table->s->next_number_index].
key_part[table->s->next_number_keypart].key_part_flag &
HA_REVERSE_SORT;
DBUG_ENTER("ha_spider::get_auto_increment");
DBUG_PRINT("info",("spider this=%p", this));
*nb_reserved_values = ULONGLONG_MAX;
......@@ -9307,7 +9310,9 @@ void ha_spider::get_auto_increment(
table_share->next_number_key_offset);
error_num = index_read_last_map(table->record[1], key,
make_prev_keypart_map(table_share->next_number_keypart));
} else
} else if (rev)
error_num = index_first(table->record[1]);
else
error_num = index_last(table->record[1]);
if (error_num)
......
for master_1
connect master_1, localhost, root, , , $MASTER_1_MYPORT, $MASTER_1_MYSOCK;
connection master_1;
CALL mtr.add_suppression("unknown variable");
SET SESSION sql_log_bin= 0;
INSTALL PLUGIN spider SONAME 'ha_spider';
CREATE SERVER s_1 FOREIGN DATA WRAPPER mysql OPTIONS (
HOST 'localhost',
DATABASE 'auto_test_local',
USER 'root',
PASSWORD '',
SOCKET '$MASTER_1_MYSOCK'
);
SET spider_internal_sql_log_off= 0;
SET spider_direct_order_limit= 10000;
SET spider_init_sql_alloc_size= 1;
for child2
for child3
create database auto_test_local;
set spider_same_server_link= on;
#
# MDEV-27590 Auto-increment on Spider tables with DESC PK does not work properly
#
select @@spider_auto_increment_mode;
@@spider_auto_increment_mode
-1
create or replace table auto_test_local.t (id int primary key) engine=InnoDB;
create or replace table t_sp1 (id int auto_increment, primary key(id desc))
engine=Spider COMMENT='wrapper "mysql", srv "s_1", table "t"';
insert into t_sp1 () values (),(),();
insert into t_sp1 () values (),(),();
select * from t_sp1;
id
1
2
3
4
5
6
drop table t_sp1, auto_test_local.t;
drop database auto_test_local;
for master_1
connection master_1;
DROP FUNCTION spider_flush_table_mon_cache;
DROP FUNCTION spider_copy_tables;
DROP FUNCTION spider_ping_table;
DROP FUNCTION spider_bg_direct_sql;
DROP FUNCTION spider_direct_sql;
UNINSTALL PLUGIN spider_wrapper_protocols;
UNINSTALL PLUGIN spider_alloc_mem;
UNINSTALL PLUGIN spider;
Warnings:
Warning 1620 Plugin is busy and will be uninstalled on shutdown
DROP TABLE IF EXISTS mysql.spider_xa;
DROP TABLE IF EXISTS mysql.spider_xa_member;
DROP TABLE IF EXISTS mysql.spider_xa_failed_log;
DROP TABLE IF EXISTS mysql.spider_tables;
DROP TABLE IF EXISTS mysql.spider_link_mon_servers;
DROP TABLE IF EXISTS mysql.spider_link_failed_log;
DROP TABLE IF EXISTS mysql.spider_table_position_for_recovery;
DROP TABLE IF EXISTS mysql.spider_table_sts;
DROP TABLE IF EXISTS mysql.spider_table_crd;
DROP SERVER s_1;
disconnect master_1;
for child2
for child3
--source ../t/test_init.inc
create database auto_test_local;
set spider_same_server_link= on;
--echo #
--echo # MDEV-27590 Auto-increment on Spider tables with DESC PK does not work properly
--echo #
select @@spider_auto_increment_mode;
create or replace table auto_test_local.t (id int primary key) engine=InnoDB;
create or replace table t_sp1 (id int auto_increment, primary key(id desc))
engine=Spider COMMENT='wrapper "mysql", srv "s_1", table "t"';
insert into t_sp1 () values (),(),();
insert into t_sp1 () values (),(),();
select * from t_sp1;
drop table t_sp1, auto_test_local.t;
drop database auto_test_local;
--source ../t/test_deinit.inc
......@@ -2,10 +2,10 @@ let $VERSION_COMPILE_OS_WIN=
`SELECT IF(@@version_compile_os like 'Win%', 1, 0)`;
if ($VERSION_COMPILE_OS_WIN)
{
INSTALL PLUGIN spider SONAME 'ha_spider.dll';
INSTALL PLUGIN spider SONAME 'ha_spider';
if ($MASTER_1_MYPORT)
{
eval CREATE SERVER s_1 FOREIGN DATA WRAPPER mysql OPTIONS (
evalp CREATE SERVER s_1 FOREIGN DATA WRAPPER mysql OPTIONS (
HOST 'localhost',
DATABASE 'auto_test_local',
USER 'root',
......@@ -15,7 +15,7 @@ if ($VERSION_COMPILE_OS_WIN)
}
if ($CHILD2_1_MYPORT)
{
eval CREATE SERVER s_2_1 FOREIGN DATA WRAPPER mysql OPTIONS (
evalp CREATE SERVER s_2_1 FOREIGN DATA WRAPPER mysql OPTIONS (
HOST 'localhost',
DATABASE 'auto_test_remote',
USER 'root',
......@@ -25,7 +25,7 @@ if ($VERSION_COMPILE_OS_WIN)
}
if ($CHILD2_2_MYPORT)
{
eval CREATE SERVER s_2_2 FOREIGN DATA WRAPPER mysql OPTIONS (
evalp CREATE SERVER s_2_2 FOREIGN DATA WRAPPER mysql OPTIONS (
HOST 'localhost',
DATABASE 'auto_test_remote2',
USER 'root',
......@@ -35,7 +35,7 @@ if ($VERSION_COMPILE_OS_WIN)
}
if ($CHILD2_3_MYPORT)
{
eval CREATE SERVER s_2_3 FOREIGN DATA WRAPPER mysql OPTIONS (
evalp CREATE SERVER s_2_3 FOREIGN DATA WRAPPER mysql OPTIONS (
HOST 'localhost',
DATABASE 'auto_test_remote3',
USER 'root',
......@@ -45,7 +45,7 @@ if ($VERSION_COMPILE_OS_WIN)
}
if ($CHILD3_1_MYPORT)
{
eval CREATE SERVER s_3_1 FOREIGN DATA WRAPPER mysql OPTIONS (
evalp CREATE SERVER s_3_1 FOREIGN DATA WRAPPER mysql OPTIONS (
HOST 'localhost',
DATABASE 'auto_test_local',
USER 'root',
......@@ -55,7 +55,7 @@ if ($VERSION_COMPILE_OS_WIN)
}
if ($CHILD3_2_MYPORT)
{
eval CREATE SERVER s_3_2 FOREIGN DATA WRAPPER mysql OPTIONS (
evalp CREATE SERVER s_3_2 FOREIGN DATA WRAPPER mysql OPTIONS (
HOST 'localhost',
DATABASE 'auto_test_local',
USER 'root',
......@@ -65,7 +65,7 @@ if ($VERSION_COMPILE_OS_WIN)
}
if ($CHILD2_3_MYPORT)
{
eval CREATE SERVER s_3_3 FOREIGN DATA WRAPPER mysql OPTIONS (
evalp CREATE SERVER s_3_3 FOREIGN DATA WRAPPER mysql OPTIONS (
HOST 'localhost',
DATABASE 'auto_test_local',
USER 'root',
......@@ -76,10 +76,10 @@ if ($VERSION_COMPILE_OS_WIN)
}
if (!$VERSION_COMPILE_OS_WIN)
{
INSTALL PLUGIN spider SONAME 'ha_spider.so';
INSTALL PLUGIN spider SONAME 'ha_spider';
if ($MASTER_1_MYSOCK)
{
eval CREATE SERVER s_1 FOREIGN DATA WRAPPER mysql OPTIONS (
evalp CREATE SERVER s_1 FOREIGN DATA WRAPPER mysql OPTIONS (
HOST 'localhost',
DATABASE 'auto_test_local',
USER 'root',
......@@ -89,7 +89,7 @@ if (!$VERSION_COMPILE_OS_WIN)
}
if ($CHILD2_1_MYSOCK)
{
eval CREATE SERVER s_2_1 FOREIGN DATA WRAPPER mysql OPTIONS (
evalp CREATE SERVER s_2_1 FOREIGN DATA WRAPPER mysql OPTIONS (
HOST 'localhost',
DATABASE 'auto_test_remote',
USER 'root',
......@@ -99,7 +99,7 @@ if (!$VERSION_COMPILE_OS_WIN)
}
if ($CHILD2_2_MYSOCK)
{
eval CREATE SERVER s_2_2 FOREIGN DATA WRAPPER mysql OPTIONS (
evalp CREATE SERVER s_2_2 FOREIGN DATA WRAPPER mysql OPTIONS (
HOST 'localhost',
DATABASE 'auto_test_remote2',
USER 'root',
......@@ -109,7 +109,7 @@ if (!$VERSION_COMPILE_OS_WIN)
}
if ($CHILD2_3_MYSOCK)
{
eval CREATE SERVER s_2_3 FOREIGN DATA WRAPPER mysql OPTIONS (
evalp CREATE SERVER s_2_3 FOREIGN DATA WRAPPER mysql OPTIONS (
HOST 'localhost',
DATABASE 'auto_test_remote3',
USER 'root',
......@@ -119,7 +119,7 @@ if (!$VERSION_COMPILE_OS_WIN)
}
if ($CHILD3_1_MYSOCK)
{
eval CREATE SERVER s_3_1 FOREIGN DATA WRAPPER mysql OPTIONS (
evalp CREATE SERVER s_3_1 FOREIGN DATA WRAPPER mysql OPTIONS (
HOST 'localhost',
DATABASE 'auto_test_local',
USER 'root',
......@@ -129,7 +129,7 @@ if (!$VERSION_COMPILE_OS_WIN)
}
if ($CHILD3_2_MYSOCK)
{
eval CREATE SERVER s_3_2 FOREIGN DATA WRAPPER mysql OPTIONS (
evalp CREATE SERVER s_3_2 FOREIGN DATA WRAPPER mysql OPTIONS (
HOST 'localhost',
DATABASE 'auto_test_local',
USER 'root',
......@@ -139,7 +139,7 @@ if (!$VERSION_COMPILE_OS_WIN)
}
if ($CHILD3_3_MYSOCK)
{
eval CREATE SERVER s_3_3 FOREIGN DATA WRAPPER mysql OPTIONS (
evalp CREATE SERVER s_3_3 FOREIGN DATA WRAPPER mysql OPTIONS (
HOST 'localhost',
DATABASE 'auto_test_local',
USER 'root',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment