CREATE OR REPLACE FUNCTION exec_n(_sql text, _ncast int) RETURNS void
LANGUAGE plpgsql AS $$
DECLARE
	_input text := 'f';
BEGIN
	FOR n IN 1 .. _ncast LOOP
		EXECUTE _sql USING _input;
	END LOOP;
END
$$;

-- 20,000,000 calls to varchar_exemptor(); 0 calls to varchar() anyway
-- 281.6s master, 269.2s patched
SELECT exec_n('SELECT 1 WHERE false' || repeat(' AND $1::varchar(1) IS NULL', 1000),
			  20000);
