Skip to content

Commit

Permalink
Fixed the index renaming to prevent deadlocks.
Browse files Browse the repository at this point in the history
See issue #5 for more information.
  • Loading branch information
grayhemp committed Mar 21, 2015
1 parent aca5372 commit aac145e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
8 changes: 4 additions & 4 deletions lib/PgToolkit/Compactor/Table.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2224,12 +2224,12 @@ sub _get_swap_index_names_query {
string => $arg_hash{'data'}->{'name'});

return
'ALTER INDEX '.$schema_ident.'.pgcompact_index_'.$$.
' RENAME TO pgcompact_swap_index_'.$$.'; '.
'ALTER INDEX '.$schema_ident.'.'.$index_ident.
' RENAME TO pgcompact_index_'.$$.'; '.
' RENAME TO pgcompact_swap_index_'.$$.'; '.
'ALTER INDEX '.$schema_ident.'.pgcompact_index_'.$$.
' RENAME TO '.$index_ident.';'.
'ALTER INDEX '.$schema_ident.'.pgcompact_swap_index_'.$$.
' RENAME TO '.$index_ident.';';
' RENAME TO pgcompact_index_'.$$.'; ';
}

sub _get_vacuum_full_query {
Expand Down
5 changes: 3 additions & 2 deletions misc/scratch.sql
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,10 @@ SELECT
(random() * 1000000)::text,
(random() * 5000)::integer) AS "текстовая колонка"
FROM generate_series(1, 10000) AS i;
CREATE INDEX "таблица - восемь idx1" ON "таблица - восемь" (
CREATE INDEX "таблица - восемь idx1" ON "схема один"."таблица - восемь" (
"текстовая колонка", "идентификатор");
ALTER TABLE "таблица - восемь" ADD CONSTRAINT "таблица - восемь pkey"
ALTER TABLE "схема один"."таблица - восемь"
ADD CONSTRAINT "таблица - восемь pkey"
PRIMARY KEY ("идентификатор");
DELETE FROM "схема один"."таблица - восемь"
WHERE "идентификатор" BETWEEN 1000 AND 10000 - 1000;
Expand Down
16 changes: 8 additions & 8 deletions t/lib/PgToolkit/DatabaseStub.pm
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,12 @@ sub init {
'row_list' => []},
'swap_index_names2' => {
'sql_pattern' =>
qr/ALTER INDEX schema\.pgcompact_index_$$ /.
qr/RENAME TO pgcompact_swap_index_$$; /.
qr/ALTER INDEX schema\.table_idx2 /.
qr/RENAME TO pgcompact_index_$$; /.
qr/RENAME TO pgcompact_swap_index_$$; /.
qr/ALTER INDEX schema\.pgcompact_index_$$ /.
qr/RENAME TO table_idx2;/.
qr/ALTER INDEX schema\.pgcompact_swap_index_$$ /.
qr/RENAME TO table_idx2;/,
qr/RENAME TO pgcompact_index_$$; /,
'row_list_sequence' => [[[]]]},
'drop_temp_index2' => {
'sql_pattern' =>
Expand Down Expand Up @@ -290,12 +290,12 @@ sub init {
'row_list' => []},
'swap_index_names3' => {
'sql_pattern' =>
qr/ALTER INDEX schema\.pgcompact_index_$$ /.
qr/RENAME TO pgcompact_swap_index_$$; /.
qr/ALTER INDEX schema\.table_idx3 /.
qr/RENAME TO pgcompact_index_$$; /.
qr/RENAME TO pgcompact_swap_index_$$; /.
qr/ALTER INDEX schema\.pgcompact_index_$$ /.
qr/RENAME TO table_idx3;/.
qr/ALTER INDEX schema\.pgcompact_swap_index_$$ /.
qr/RENAME TO table_idx3;/,
qr/RENAME TO pgcompact_index_$$; /,
'row_list' => []},
'drop_temp_index_concurrently3' => {
'sql_pattern' =>
Expand Down

0 comments on commit aac145e

Please sign in to comment.