\set ECHO 0
BEGIN;
\set QUIET 1
\i sql/explanation.sql
-- Need to mock md5() so that it emits known values, so the tests will pass.
CREATE SCHEMA mock;
CREATE TEMPORARY SEQUENCE md5seq;
CREATE TEMPORARY TABLE md5s (
md5 TEXT,
id INTEGER DEFAULT NEXTVAL('md5seq')
);
INSERT INTO md5s VALUES
('6e9d7e0628d306480fece89e8483fe6e'),
('b012abc1673778343cb1b89aae1e9b94'),
('029dde3a3c872f0c960f03d2ecfaf5ee'),
('3e4c4968cee7653037613c234a953be1'),
('dd3d1b1fb6c70be827075e01b306250c'),
('037a8fe70739ed1be6a3006d0ab80c82'),
('2c4e922dc19ce9f01a3bf08fbd76b041'),
('709b2febd8e560dd8830f4c7277c3758'),
('9dd89be09ea07a1000a21cbfc09121c7'),
('8dc3d35ab978f6c6e46f7927e7b86d21'),
('3d7c72f13ae7571da70f434b5bc9e0af');
CREATE FUNCTION mock.md5(TEXT) RETURNS TEXT LANGUAGE plpgsql AS $$
DECLARE
rec md5s;
BEGIN
SELECT * INTO rec FROM md5s WHERE id = (SELECT MIN(id) FROM md5s);
DELETE FROM md5s WHERE id = rec.id;
RETURN rec.md5;
END;
$$;
-- Mock now(), too.
CREATE FUNCTION mock.now() RETURNS TIMESTAMPTZ LANGUAGE SQL AS $$
SELECT '2010-11-08 19:21:19.817375+00'::timestamptz;
$$;
SET search_path = mock,public,pg_catalog;
SET DateStyle = 'ISO';
SET IntervalStyle = 'postgres';
SET timezone = 'UTC';
-- Okay, now on with the tests. Create a table to query against.
CREATE TABLE foo(id int);
\set QUIET 0
-- Plan an explain and an explain analyze.
SELECT * FROM explanation('select * from foo');
-- Plan an explain analyze. Omit imes because it varies. :-(
SELECT planned_at = NOW() AS have_planned_at, node_id, parent_id, node_type, total_runtime IS NOT NULL AS have_total_runtime, strategy, operation, startup_cost, total_cost, plan_rows, plan_width, actual_startup_time IS NOT NULL AS have_actual_startup_time, actual_total_time IS NOT NULL AS have_actual_Total_time, actual_rows, actual_loops, parent_relationship, sort_key, sort_method, sort_space_used, sort_space_type, join_type, join_filter, hash_cond, relation_name, alias, scan_direction, index_name, index_cond, recheck_cond, tid_cond, merge_cond, subplan_name, function_name, function_call, filter, one_time_filter, command, shared_hit_blocks, shared_read_blocks, shared_written_blocks, local_hit_blocks, local_read_blocks, local_written_blocks, temp_read_blocks, temp_written_blocks, output, hash_buckets, hash_batches, original_hash_batches, peak_memory_usage, schema, cte_name FROM explanation( query := 'select * from foo', analyzed := true);
-- Make sure parse_node() recurses.
SELECT * FROM parse_node($$ AggregateSorted258.13262.3143240.1210.12101SortOuter258.13258.1443240.1170.11701d.named.versiond.abstractd.descriptiond.relstatusd.ownerd.sha1d.metaquicksort25MemoryNested LoopOuterLeft16.75258.0943240.0090.00901(semver_cmp(d.version, dt.version) = 0)Hash JoinOuterInner16.75253.0642920.0090.00901(de.distribution = d.name)(semver_cmp(d.version, de.dist_version) = 0)↵
Seq ScanOuterdistribution_extensionsde0.0015.105101280.0080.00801HashInner13.0013.003002280.0000.00000Seq ScanOuterdistributionsd0.0013.003002280.0000.00000Index ScanInnerNoMovementdistribution_tags_pkeydistribution_tagsdt0.000.463960.0000.00000(d.name = dt.distribution)Function ScanSubPlanSubPlan 1unnestg0.001.00100320.0000.00000(x IS NOT NULL)
$$);
-- Make sure parse_trigger() works.
SELECT * FROM parse_triggers(ARRAY[
$$ HarryMelissausers14$$,
$$ JoshJeffwankers2$$
]::xml[]);
ROLLBACK;