补充hash_index的fastcheck

This commit is contained in:
chendong76
2021-09-08 16:52:17 +08:00
parent 010fdac4e4
commit b933f03d06
7 changed files with 305 additions and 8 deletions

View File

@ -10,3 +10,4 @@ multi_standby_single/failover
multi_standby_single/params
#multi_standby_single/most_available
multi_standby_single/failover_with_data
multi_standby_single/hash_index

View File

@ -0,0 +1,100 @@
#!/bin/sh
# hash index xlog
# 1. parallel recovery mode
# 2. extreme rto mode
source ./util.sh
function hash_index_test()
{
db_name=$1
echo "begin test hash index in database $db_name"
gsql -d $db -p $dn1_primary_port -c "create database $db_name;"
gsql -d $db_name -p $dn1_primary_port -c "create table hash_table_1 (id int, num int, sex varchar default 'male');"
gsql -d $db_name -p $dn1_primary_port -c "create index hash_t1_id1 on hash_table_1 using hash (id);"
gsql -d $db_name -p $dn1_primary_port -c "insert into hash_table_1 select random()*10, random()*10, 'XXX' from generate_series(1,5000);"
gsql -d $db_name -p $dn1_primary_port -c "delete from hash_table_1 where id = 7 and num = 1;"
gsql -d $db_name -p $dn1_primary_port -c "insert into hash_table_1 select 7, random()*3, 'XXX' from generate_series(1,500);"
gsql -d $db_name -p $dn1_primary_port -c "delete from hash_table_1 where id = 5;"
gsql -d $db_name -p $dn1_primary_port -c "vacuum hash_table_1;"
gsql -d $db_name -p $dn1_primary_port -c "insert into hash_table_1 select random()*50, random()*3, 'XXX' from generate_series(1,50000);"
gsql -d $db_name -p $dn1_primary_port -c "delete from hash_table_1 where num = 2;"
gsql -d $db_name -p $dn1_primary_port -c "vacuum hash_table_1;"
gsql -d $db_name -p $dn1_primary_port -c "create table hash_table_2(id int, name varchar, sex varchar default 'male');"
gsql -d $db_name -p $dn1_primary_port -c "insert into hash_table_2 select random()*100, 'XXX', 'XXX' from generate_series(1,50000);"
gsql -d $db_name -p $dn1_primary_port -c "create or replace procedure hash_proc_9(sid in integer)
is
begin
set enable_indexscan = on;
set enable_bitmapscan = off;
delete from hash_table_9 where id = sid;
perform * from hash_table_9 where id = sid;
insert into hash_table_9 select sid, random() * 10, 'xxx' from generate_series(1,5000);
end;
/"
gsql -d $db_name -p $dn1_primary_port -c "call hash_proc_9(1);"
gsql -d $db_name -p $dn1_primary_port -c "call hash_proc_9(1);"
gsql -d $db_name -p $dn1_primary_port -c "call hash_proc_9(1);"
gsql -d $db_name -p $dn1_primary_port -c "call hash_proc_9(1);"
sleep 3;
gsql -d $db -p $dn1_primary_port -c "drop database $db_name;"
}
function test_1()
{
set_default
gs_guc set -Z datanode -D $primary_data_dir -c "autovacuum = off"
# parallel recovery
echo "begin to kill primary"
kill_cluster
echo "begin to set parallel recovery param"
gs_guc set -Z datanode -D $primary_data_dir -c "recovery_max_workers = 2"
gs_guc set -Z datanode -D $primary_data_dir -c "recovery_parse_workers = 0"
gs_guc set -Z datanode -D $primary_data_dir -c "recovery_redo_workers = 0"
gs_guc set -Z datanode -D $primary_data_dir -c "hot_standby = on"
start_cluster
echo "start cluter success!"
hash_index_test "hash_db_1"
echo "begin to query primary"
query_primary
echo "begin to query standby"
query_standby
# extreme rto
echo "begin to kill primary"
kill_cluster
echo "begin to set extreme rto param"
gs_guc set -Z datanode -D $primary_data_dir -c "recovery_max_workers = 0"
gs_guc set -Z datanode -D $primary_data_dir -c "recovery_parse_workers = 2"
gs_guc set -Z datanode -D $primary_data_dir -c "recovery_redo_workers = 1"
gs_guc set -Z datanode -D $primary_data_dir -c "hot_standby = off"
start_cluster
echo "start cluter success!"
hash_index_test "hash_db_2"
echo "begin to query primary"
query_primary
echo "begin to query standby"
query_standby
}
function tear_down()
{
sleep 1
set_default
kill_cluster
gs_guc set -Z datanode -D $primary_data_dir -c "recovery_max_workers = 4"
gs_guc set -Z datanode -D $primary_data_dir -c "recovery_parse_workers = 1"
gs_guc set -Z datanode -D $primary_data_dir -c "recovery_redo_workers = 1"
gs_guc set -Z datanode -D $primary_data_dir -c "hot_standby = on"
start_cluster
}
test_1
tear_down

View File

@ -1,6 +1,6 @@
--------------------------------
---------- hash index ----------
--------------------------------
-------------------------------------
---------- hash index part1----------
-------------------------------------
set enable_seqscan = off;
set enable_indexscan = off;
------------------
@ -179,7 +179,7 @@ create index hash_t5_id1 on hash_table_5 using hash(id) with(fillfactor = 80);
insert into hash_table_5 select random()*100, 'XXX', 'XXX' from generate_series(1,100);
update hash_table_5 set name = 'aaa' where id = 80;
alter index hash_t5_id1 set (fillfactor = 60);
alter index hash_t5_id1 RESET (fillfactor);
alter index hash_t5_id1 reset (fillfactor);
explain (costs off) select * from hash_table_5 where id = 80;
QUERY PLAN
----------------------------------------
@ -211,3 +211,24 @@ explain (costs off) select * from hash_table_6 where id*10 = 80;
(4 rows)
drop table hash_table_6 cascade;
-- create unlogged table index, which will be delete in hash_index_002
drop table if exists hash_table_7;
NOTICE: table "hash_table_7" does not exist, skipping
create unlogged table hash_table_7(id int, name varchar, sex varchar default 'male');
insert into hash_table_7 select random()*100, 'XXX', 'XXX' from generate_series(1,1000);
create index hash_t7_id1 on hash_table_7 using hash(id) with (fillfactor = 30);
explain (costs off) select * from hash_table_7 where id = 80;
QUERY PLAN
----------------------------------------
Bitmap Heap Scan on hash_table_7
Recheck Cond: (id = 80)
-> Bitmap Index Scan on hash_t7_id1
Index Cond: (id = 80)
(4 rows)
select count(*) from hash_table_7;
count
-------
1000
(1 row)

View File

@ -0,0 +1,98 @@
-------------------------------------
---------- hash index part2----------
-------------------------------------
set enable_seqscan = off;
set enable_indexscan = off;
-- continue to hash_index_001
explain (costs off) select * from hash_table_7 where id = 80;
QUERY PLAN
----------------------------------------
Bitmap Heap Scan on hash_table_7
Recheck Cond: (id = 80)
-> Bitmap Index Scan on hash_t7_id1
Index Cond: (id = 80)
(4 rows)
drop table hash_table_7 cascade;
-- low maintenance_work_mem
set maintenance_work_mem = '1MB';
drop table if exists hash_table_8;
NOTICE: table "hash_table_8" does not exist, skipping
create table hash_table_8(id int, name varchar, sex varchar default 'male');
insert into hash_table_8 select random()*100, 'XXX', 'XXX' from generate_series(1,50000);
create index hash_t8_id1 on hash_table_8 using hash(id) with (fillfactor = 30);
explain (costs off) select * from hash_table_8 where id = 80;
QUERY PLAN
----------------------------------------
Bitmap Heap Scan on hash_table_8
Recheck Cond: (id = 80)
-> Bitmap Index Scan on hash_t8_id1
Index Cond: (id = 80)
(4 rows)
drop table hash_table_8 cascade;
-- vacuum one page
set enable_indexscan = on;
set enable_bitmapscan = off;
set maintenance_work_mem = '100MB';
alter system set autovacuum = off;
drop table if exists hash_table_9;
NOTICE: table "hash_table_9" does not exist, skipping
create table hash_table_9(id int, name varchar, sex varchar default 'male');
insert into hash_table_9 select random()*100, 'XXX', 'XXX' from generate_series(1,50000);
create index hash_t9_id1 on hash_table_9 using hash(id) with (fillfactor = 10);
create or replace procedure hash_proc_9(sid in integer)
is
begin
delete from hash_table_9 where id = sid;
perform * from hash_table_9 where id = sid;
insert into hash_table_9 select sid, random() * 10, 'xxx' from generate_series(1,5000);
end;
/
call hash_proc_9(1);
hash_proc_9
-------------
(1 row)
call hash_proc_9(1);
hash_proc_9
-------------
(1 row)
call hash_proc_9(1);
hash_proc_9
-------------
(1 row)
call hash_proc_9(1);
hash_proc_9
-------------
(1 row)
drop table hash_table_9 cascade;
drop procedure hash_proc_9;
-- some dml operator
drop table if exists hash_table_10;
NOTICE: table "hash_table_10" does not exist, skipping
create table hash_table_10(id int, num int, sex varchar default 'male');
create index hash_t10_id1 on hash_table_10 using hash (id);
insert into hash_table_10 select random()*10, random()*10, 'XXX' from generate_series(1,5000);
insert into hash_table_10 select random()*10, random()*10, 'XXX' from generate_series(1,5000);
delete from hash_table_10 where id = 7 and num = 1;
insert into hash_table_10 select 7, random()*3, 'XXX' from generate_series(1,500);
delete from hash_table_10 where id = 5;
vacuum hash_table_10;
insert into hash_table_10 select random()*50, random()*3, 'XXX' from generate_series(1,50000);
delete from hash_table_10 where num = 2;
vacuum hash_table_10;
drop table hash_table_10 cascade;
--reset all parameters
reset enable_indexscan;
reset enable_bitmapscan;
reset enable_seqscan;
reset maintenance_work_mem;
alter system set autovacuum = on;

View File

@ -111,6 +111,7 @@ test: single_node_random
#test: single_node_arrays
#test: single_node_btree_index single_node_hash_index single_node_update
test: hash_index_001
test: hash_index_002
test: single_node_update
#test single_node_namespace
#test: single_node_prepared_xacts

View File

@ -1,6 +1,6 @@
--------------------------------
---------- hash index ----------
--------------------------------
-------------------------------------
---------- hash index part1----------
-------------------------------------
set enable_seqscan = off;
set enable_indexscan = off;
@ -152,7 +152,7 @@ create index hash_t5_id1 on hash_table_5 using hash(id) with(fillfactor = 80);
insert into hash_table_5 select random()*100, 'XXX', 'XXX' from generate_series(1,100);
update hash_table_5 set name = 'aaa' where id = 80;
alter index hash_t5_id1 set (fillfactor = 60);
alter index hash_t5_id1 RESET (fillfactor);
alter index hash_t5_id1 reset (fillfactor);
explain (costs off) select * from hash_table_5 where id = 80;
drop table hash_table_5 cascade;
@ -167,3 +167,11 @@ insert into hash_table_6 select random()*100, 'XXX', 'XXX' from generate_series(
delete from hash_table_6 where id in (50, 60, 70);
explain (costs off) select * from hash_table_6 where id*10 = 80;
drop table hash_table_6 cascade;
-- create unlogged table index, which will be delete in hash_index_002
drop table if exists hash_table_7;
create unlogged table hash_table_7(id int, name varchar, sex varchar default 'male');
insert into hash_table_7 select random()*100, 'XXX', 'XXX' from generate_series(1,1000);
create index hash_t7_id1 on hash_table_7 using hash(id) with (fillfactor = 30);
explain (costs off) select * from hash_table_7 where id = 80;
select count(*) from hash_table_7;

View File

@ -0,0 +1,68 @@
-------------------------------------
---------- hash index part2----------
-------------------------------------
set enable_seqscan = off;
set enable_indexscan = off;
-- continue to hash_index_001
explain (costs off) select * from hash_table_7 where id = 80;
drop table hash_table_7 cascade;
-- low maintenance_work_mem
set maintenance_work_mem = '1MB';
drop table if exists hash_table_8;
create table hash_table_8(id int, name varchar, sex varchar default 'male');
insert into hash_table_8 select random()*100, 'XXX', 'XXX' from generate_series(1,50000);
create index hash_t8_id1 on hash_table_8 using hash(id) with (fillfactor = 30);
explain (costs off) select * from hash_table_8 where id = 80;
drop table hash_table_8 cascade;
-- vacuum one page
set enable_indexscan = on;
set enable_bitmapscan = off;
set maintenance_work_mem = '100MB';
alter system set autovacuum = off;
drop table if exists hash_table_9;
create table hash_table_9(id int, name varchar, sex varchar default 'male');
insert into hash_table_9 select random()*100, 'XXX', 'XXX' from generate_series(1,50000);
create index hash_t9_id1 on hash_table_9 using hash(id) with (fillfactor = 10);
create or replace procedure hash_proc_9(sid in integer)
is
begin
delete from hash_table_9 where id = sid;
perform * from hash_table_9 where id = sid;
insert into hash_table_9 select sid, random() * 10, 'xxx' from generate_series(1,5000);
end;
/
call hash_proc_9(1);
call hash_proc_9(1);
call hash_proc_9(1);
call hash_proc_9(1);
drop table hash_table_9 cascade;
drop procedure hash_proc_9;
-- some dml operator
drop table if exists hash_table_10;
create table hash_table_10(id int, num int, sex varchar default 'male');
create index hash_t10_id1 on hash_table_10 using hash (id);
insert into hash_table_10 select random()*10, random()*10, 'XXX' from generate_series(1,5000);
insert into hash_table_10 select random()*10, random()*10, 'XXX' from generate_series(1,5000);
delete from hash_table_10 where id = 7 and num = 1;
insert into hash_table_10 select 7, random()*3, 'XXX' from generate_series(1,500);
delete from hash_table_10 where id = 5;
vacuum hash_table_10;
insert into hash_table_10 select random()*50, random()*3, 'XXX' from generate_series(1,50000);
delete from hash_table_10 where num = 2;
vacuum hash_table_10;
drop table hash_table_10 cascade;
--reset all parameters
reset enable_indexscan;
reset enable_bitmapscan;
reset enable_seqscan;
reset maintenance_work_mem;
alter system set autovacuum = on;