15 lines
399 B
MySQL
15 lines
399 B
MySQL
|
-- Taken from https://wiki.postgresql.org/wiki/Count_estimate
|
||
|
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;
|