compute_index_stats is missing a CHECK_FOR_INTERRUPTS

From: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: compute_index_stats is missing a CHECK_FOR_INTERRUPTS
Date: 2015-03-28 21:17:36
Message-ID: CAMkU=1zQNPzOXLs4QuMPwkw3=5BT8iyKHJcvBKtq2JazZ=dfZQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Analyze on functional indexes cannot be interrupted very easily.

Example:

create language plperl;
create table foo1 as select x::text from generate_series(1,1000) foo (x);
create table foo2 as select reverse(x) from foo1;
--use a fast version to set up the demo, as we are impatient
CREATE or replace FUNCTION slow_reverse(text) RETURNS text
LANGUAGE plperl IMMUTABLE STRICT COST 1000000
AS $_X$
return reverse($_[0]);
$_X$;
create index on foo2 (slow_reverse(reverse));
analyze foo2;
--put the slow version in place.
CREATE or replace FUNCTION slow_reverse(text) RETURNS text
LANGUAGE plperl IMMUTABLE STRICT COST 1000000
AS $_X$
my $foo; foreach (1..1e6) {$foo+=sqrt($_)};
return reverse($_[0]);
$_X$;

-- now spring the trap
analyze foo2;

Ctrl-C (or pg_ctl stop -mf) hangs for a long time.

The attached patch fixes it, but don't vouch for its safety.

I believe I've seen a real-world example of this causing refusal of a fast
shutdown to shutdown fast.

Cheers,

Jeff

Attachment Content-Type Size
compute_index_stats_interrupt.patch application/octet-stream 483 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2015-03-28 21:24:36 Re: Manipulating complex types as non-contiguous structures in-memory
Previous Message Andreas Karlsson 2015-03-28 20:36:55 Re: Index-only scans with btree_gist