Skip to content
This repository was archived by the owner on Jul 6, 2021. It is now read-only.

Commit 2fa468c

Browse files
author
Oleg
committed
H002 perf #365
1 parent 3d938e6 commit 2fa468c

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

resources/checks/H002_unused_indexes.sh

+2-4
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,6 @@ index_data as (
213213
and am1.amname = am2.amname -- same access type
214214
and i1.columns like (i2.columns || '%') -- index 2 includes all columns from index 1
215215
and i1.opclasses like (i2.opclasses || '%')
216-
-- index expressions is same
217-
and pg_get_expr(i1.indexprs, i1.indrelid) is not distinct from pg_get_expr(i2.indexprs, i2.indrelid)
218-
-- index predicates is same
219-
and pg_get_expr(i1.indpred, i1.indrelid) is not distinct from pg_get_expr(i2.indpred, i2.indrelid)
220216
), redundant_indexes_fk as (
221217
select
222218
ri.*,
@@ -225,6 +221,8 @@ index_data as (
225221
left join fk_indexes fi on
226222
fi.fk_table_ref = ri.table_name
227223
and fi.opclasses like (ri.opclasses || '%')
224+
where substring(ri.main_index_def from position('USING' in ri.main_index_def) for length(ri.main_index_def)) =
225+
substring(ri.index_def from position('USING' in ri.index_def) for length(ri.index_def))
228226
),
229227
-- Cut recursive links
230228
redundant_indexes_tmp_num as (

run_tests.sh

+32
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,37 @@ su - postgres -c "psql -A -t -d postgres -c 'DROP DATABASE if exists ${db_name}'
1212
su - postgres -c "psql -A -t -d postgres -c 'CREATE DATABASE ${db_name}'"
1313
su - postgres -c "psql -A -t -d ${db_name} -f "${current_dir}"/.ci/test_db_dump.sql"
1414

15+
# ---------------------------------------------------------------------------------------------
16+
echo "=======> Test started: H002_unused_indexes.sh"
17+
test_resut=1
18+
19+
rm -Rf ./artifacts
20+
./checkup -h 127.0.0.1 --username postgres --project test --dbname ${db_name} -e 1 \
21+
--file ./resources/checks/H002_unused_indexes.sh
22+
23+
data_dir=$(cat ./artifacts/test/nodes.json | jq -r '.last_check | .dir') \
24+
&& result=$(cat ./artifacts/test/json_reports/$data_dir/H002_unused_indexes.json |
25+
jq '.results ."127.0.0.1" .data .redundant_indexes ."public.t_with_redundant_idx_id"') \
26+
&& ([[ "$result" == "[]" ]] || [[ "$result" == "null" ]]) \
27+
&& echo "ERROR in H002: ${result} in '.results .\"127.0.0.1\" .data .redundant_indexes .\"public.t_with_redundant_idx_id\"'" \
28+
&& echo $(cat ./artifacts/test/json_reports/$data_dir/H002_unused_indexes.json | jq '.') \
29+
&& test_resut=0
30+
31+
data_dir=$(cat ./artifacts/test/nodes.json | jq -r '.last_check | .dir') \
32+
&& result=$(cat ./artifacts/test/json_reports/$data_dir/H002_unused_indexes.json |
33+
jq '.results ."127.0.0.1" .data .redundant_indexes ."public.t_with_redundant_idx_f1_uniq"') \
34+
&& ([[ ! "$result" == "[]" ]] && [[ ! "$result" == "null" ]]) \
35+
&& echo "ERROR in H002: ${result} in '.results .\"127.0.0.1\" .data .redundant_indexes .\"public.t_with_redundant_idx_f1_uniq\"'" \
36+
&& echo $(cat ./artifacts/test/json_reports/$data_dir/H002_unused_indexes.json | jq '.') \
37+
&& test_resut=0
38+
39+
if [ "$test_resut" -eq "1" ]; then
40+
echo "<======= Test finished: H002"
41+
else
42+
echo "<======= Test failed: H002"
43+
fi
44+
45+
# ---------------------------------------------------------------------------------------------
1546
echo "=======> Test started: H003 Non indexed FKs"
1647
test_resut=1
1748
su - postgres -c "psql -A -t -d ${db_name} -f "${current_dir}"/.ci/h003_step_1.sql"
@@ -47,3 +78,4 @@ if [ "$test_resut" -eq "1" ]; then
4778
else
4879
echo "<======= Test failed: H003"
4980
fi
81+
# ---------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)