Patch applied to commit - 80d690721973f6a031143a24a34b78a0225101a2 SQL repro script ================ CREATE EXTENSION IF NOT EXISTS pg_trgm; set statement_timeout = '1s'; show statement_timeout; \timing on select 1 where repeat('1.1',80000) %>> 'Lorem ipsum dolor sit amet'; -- Check whether this change brought in any performance regressions set statement_timeout='0'; show statement_timeout; select COUNT(*) from generate_series(1,1) q(e) where repeat('1.1',10000) %>> ('Lorem ipsum dolor sit amet'||e::text); select COUNT(*) from generate_series(1,10) q(e) where repeat('1.1',10000) %>> ('Lorem ipsum dolor sit amet'||e::text); select COUNT(*) from generate_series(1,100) q(e) where repeat('1.1',10000) %>> ('Lorem ipsum dolor sit amet'||e::text); SQL script output ================= CREATE EXTENSION SET statement_timeout ------------------- 1s (1 row) Timing is on. psql:/home/ubuntu/proj/sqlsmithdata/repro1.sql:11: ERROR: canceling statement due to statement timeout Time: 1000.792 ms (00:01.001) SET Time: 0.093 ms statement_timeout ------------------- 0 (1 row) Time: 0.077 ms count ------- 0 (1 row) Time: 473.487 ms count ------- 0 (1 row) Time: 4726.628 ms (00:04.727) count ------- 0 (1 row) Time: 47231.271 ms (00:47.231)