Sha256: 0371f7e0f1902fb6ede22cf4574ba5943732373e6d244141e4dc237e4ce7aa32
Contents?: true
Size: 600 Bytes
Versions: 161
Compression:
Stored size: 600 Bytes
Contents
/* A plpgsql function by Michael Fuhr for faster counting. See https://wiki.postgresql.org/wiki/Count_estimate Normal count(*) can be slow where that are millions of rows. This is a faster way to count filtered rows by parsing the output of an explain query. */ CREATE FUNCTION count_estimate(query text) RETURNS INTEGER AS $func$ DECLARE rec record; ROWS INTEGER; BEGIN FOR rec IN EXECUTE 'EXPLAIN ' || query LOOP ROWS := SUBSTRING(rec."QUERY PLAN" FROM ' rows=([[:digit:]]+)'); EXIT WHEN ROWS IS NOT NULL; END LOOP; RETURN ROWS; END $func$ LANGUAGE plpgsql;
Version data entries
161 entries across 161 versions & 1 rubygems