Created
January 18, 2019 12:05
-
-
Save sashka/a1a770e3aab4c35a6f2f89de78594ba3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment