Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bonnefoa committed Dec 16, 2024
1 parent 7ce628f commit bde4f56
Show file tree
Hide file tree
Showing 33 changed files with 415 additions and 406 deletions.
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,16 @@ $(BUILD_TEST_TARGETS):
run-test: build-test-pg$(PG_VERSION)
docker run \
--name $(TEST_CONTAINER_NAME) --rm \
$(DOCKER_RUN_OPTS) \
$(TEST_CONTAINER_NAME):pg$(PG_VERSION) \
bash -c "make regresscheck_noinstall && make installcheck"

.PHONY: update-regress-output
update-regress-output: DOCKER_RUN_OPTS = -v./results:/usr/src/pg_tracing/results
update-regress-output: run-test
update-regress-output: build-test-pg$(PG_VERSION)
docker run \
--name $(TEST_CONTAINER_NAME) --rm \
-v./results:/usr/src/pg_tracing/results \
$(TEST_CONTAINER_NAME):pg$(PG_VERSION) \
bash -c "make regresscheck_noinstall || true"
@if [ $(PG_VERSION) = "15" ]; then \
cp results/*.out expected/; \
else \
Expand Down
1 change: 1 addition & 0 deletions expected/cleanup.out
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ DROP function test_function_project_set;
DROP function test_function_result;
DROP VIEW peek_ordered_spans;
DROP VIEW peek_ordered_json_spans;
DROP VIEW peek_ordered_spans_with_pos;
DROP VIEW peek_json_spans_with_level;
DROP VIEW peek_json_spans;
DROP EXTENSION pg_tracing;
36 changes: 18 additions & 18 deletions expected/json.out
Original file line number Diff line number Diff line change
Expand Up @@ -86,35 +86,35 @@ SELECT trace_id, name,
CALL clean_spans();
-- Test parameters and deparse_info
/*dddbs='postgres.db',traceparent='00-00000000000000000000000000000001-0000000000000001-01'*/ SELECT * FROM pg_tracing_test WHERE a=1;
a | b
---+----------------------
1 | aaa
a | b | c
---+----------------------+---
1 | 1 | 1
(1 row)

SELECT trace_id, name, parameters, deparse_info, lvl FROM peek_ordered_json_spans;
trace_id | name | parameters | deparse_info | lvl
----------------------------------+-----------------------------------------------------+------------+---------------------+-----
00000000000000000000000000000001 | SELECT * FROM pg_tracing_test WHERE a=$1 | {1} | | 1
00000000000000000000000000000001 | Planner | | | 2
00000000000000000000000000000001 | ExecutorRun | | | 2
00000000000000000000000000000001 | IndexScan using pg_tracing_index on pg_tracing_test | | Index Cond: (a = 1) | 3
trace_id | name | parameters | deparse_info | lvl
----------------------------------+-------------------------------------------------------+------------+---------------------+-----
00000000000000000000000000000001 | SELECT * FROM pg_tracing_test WHERE a=$1 | {1} | | 1
00000000000000000000000000000001 | Planner | | | 2
00000000000000000000000000000001 | ExecutorRun | | | 2
00000000000000000000000000000001 | IndexScan using pg_tracing_index_a on pg_tracing_test | | Index Cond: (a = 1) | 3
(4 rows)

CALL clean_spans();
-- Test service name
/*traceparent='00-00000000000000000000000000000001-0000000000000001-01'*/ SELECT * FROM pg_tracing_test WHERE a=1;
a | b
---+----------------------
1 | aaa
a | b | c
---+----------------------+---
1 | 1 | 1
(1 row)

SELECT trace_id, name, service_name FROM peek_ordered_json_spans;
trace_id | name | service_name
----------------------------------+-----------------------------------------------------+---------------------
00000000000000000000000000000001 | SELECT * FROM pg_tracing_test WHERE a=$1 | "PostgreSQL_Server"
00000000000000000000000000000001 | Planner | "PostgreSQL_Server"
00000000000000000000000000000001 | ExecutorRun | "PostgreSQL_Server"
00000000000000000000000000000001 | IndexScan using pg_tracing_index on pg_tracing_test | "PostgreSQL_Server"
trace_id | name | service_name
----------------------------------+-------------------------------------------------------+---------------------
00000000000000000000000000000001 | SELECT * FROM pg_tracing_test WHERE a=$1 | "PostgreSQL_Server"
00000000000000000000000000000001 | Planner | "PostgreSQL_Server"
00000000000000000000000000000001 | ExecutorRun | "PostgreSQL_Server"
00000000000000000000000000000001 | IndexScan using pg_tracing_index_a on pg_tracing_test | "PostgreSQL_Server"
(4 rows)

-- Cleanup
Expand Down
36 changes: 18 additions & 18 deletions expected/planstate.out
Original file line number Diff line number Diff line change
Expand Up @@ -42,35 +42,35 @@ SELECT span_type, span_operation, deparse_info FROM peek_ordered_spans where tra
-- Check generated spans when deparse is disabled
SET pg_tracing.deparse_plan=false;
/*dddbs='postgres.db',traceparent='00-00000000000000000000000000000003-0000000000000003-01'*/ SELECT * from pg_tracing_test where a=1;
a | b
---+----------------------
1 | aaa
a | b | c
---+----------------------+---
1 | 1 | 1
(1 row)

SELECT span_operation, deparse_info, parameters, lvl from peek_ordered_spans where trace_id='00000000000000000000000000000003';
span_operation | deparse_info | parameters | lvl
-----------------------------------------------------+--------------+------------+-----
SELECT * from pg_tracing_test where a=$1 | | {1} | 0
Planner | | | 1
ExecutorRun | | | 1
IndexScan using pg_tracing_index on pg_tracing_test | | | 2
span_operation | deparse_info | parameters | lvl
-------------------------------------------------------+--------------+------------+-----
SELECT * from pg_tracing_test where a=$1 | | {1} | 0
Planner | | | 1
ExecutorRun | | | 1
IndexScan using pg_tracing_index_a on pg_tracing_test | | | 2
(4 rows)

-- Check generated spans when deparse is enabled
SET pg_tracing.deparse_plan=true;
/*dddbs='postgres.db',traceparent='00-00000000000000000000000000000004-0000000000000004-01'*/ SELECT * from pg_tracing_test where a=1;
a | b
---+----------------------
1 | aaa
a | b | c
---+----------------------+---
1 | 1 | 1
(1 row)

SELECT span_operation, deparse_info, parameters, lvl from peek_ordered_spans where trace_id='00000000000000000000000000000004';
span_operation | deparse_info | parameters | lvl
-----------------------------------------------------+---------------------+------------+-----
SELECT * from pg_tracing_test where a=$1 | | {1} | 0
Planner | | | 1
ExecutorRun | | | 1
IndexScan using pg_tracing_index on pg_tracing_test | Index Cond: (a = 1) | | 2
span_operation | deparse_info | parameters | lvl
-------------------------------------------------------+---------------------+------------+-----
SELECT * from pg_tracing_test where a=$1 | | {1} | 0
Planner | | | 1
ExecutorRun | | | 1
IndexScan using pg_tracing_index_a on pg_tracing_test | Index Cond: (a = 1) | | 2
(4 rows)

-- Clean created spans
Expand Down
80 changes: 29 additions & 51 deletions expected/planstate_bitmap.out
Original file line number Diff line number Diff line change
@@ -1,57 +1,35 @@
/*dddbs='postgres.db',traceparent='00-00000000000000000000000000000001-0000000000000001-01'*/ SELECT * from pg_tracing_test where a=1 OR a=2 OR a=3;
a | b
---+----------------------
1 | aaa
2 | aaa
3 | aaa
/*traceparent='00-00000000000000000000000000000001-0000000000000001-01'*/ SELECT * from pg_tracing_test where a=1 OR b='2' OR c=3;
a | b | c
---+----------------------+---
1 | 1 | 1
2 | 2 | 2
3 | 3 | 3
(3 rows)

SELECT span_operation, deparse_info, parameters, lvl from peek_ordered_spans where trace_id='00000000000000000000000000000001';
span_operation | deparse_info | parameters | lvl
----------------------------------------------------------+-----------------------------------------------+------------+-----
SELECT * from pg_tracing_test where a=$1 OR a=$2 OR a=$3 | | {1,2,3} | 0
Planner | | | 1
ExecutorRun | | | 1
BitmapHeapScan on pg_tracing_test | Recheck Cond: ((a = 1) OR (a = 2) OR (a = 3)) | | 2
BitmapOr | | | 3
BitmapIndexScan on pg_tracing_index | Index Cond: (a = 1) | | 4
BitmapIndexScan on pg_tracing_index | Index Cond: (a = 2) | | 4
BitmapIndexScan on pg_tracing_index | Index Cond: (a = 3) | | 4
-- PG < 18
-- +-----------------------------------------------------------------------------------------+
-- | A: BitmapOr |
-- ++-----------------------------+-------------------------------+--------------------------+
-- |B: Bitmap Index Scan (a=1) |C: Bitmap Index Scan (b='2') |D: Bitmap Index Scan (c=3)|
-- +-----------------------------+-------------------------------+--------------------------+
-- PG >= 18
-- +-----------------------------------------------------------------------------------------+
-- | A: BitmapOr |
-- ++-----------------------------+-------------------------------+--------------------------+
-- |B: Bitmap Index Scan (c=1) |C: Bitmap Index Scan (b='2') |D: Bitmap Index Scan (a=1)|
-- +-----------------------------+-------------------------------+--------------------------+
SELECT span_operation, deparse_info, parameters, pos_start, pos_end, lvl from peek_ordered_spans_with_pos where trace_id='00000000000000000000000000000001';
span_operation | deparse_info | parameters | pos_start | pos_end | lvl
----------------------------------------------------------+---------------------------------------------------------+------------+-----------+---------+-----
SELECT * from pg_tracing_test where a=$1 OR b=$2 OR c=$3 | | {1,'2',3} | 1 | 11 | 0
Planner | | | 2 | 3 | 1
ExecutorRun | | | 4 | 10 | 1
BitmapHeapScan on pg_tracing_test | Recheck Cond: ((a = 1) OR (b = '2'::bpchar) OR (c = 3)) | | 5 | 9 | 2
BitmapOr | | | 5 | 8 | 3
BitmapIndexScan on pg_tracing_index_a | Index Cond: (a = 1) | | 5 | 6 | 4
BitmapIndexScan on pg_tracing_index_b | Index Cond: (b = '2'::bpchar) | | 6 | 7 | 4
BitmapIndexScan on pg_tracing_index_c | Index Cond: (c = 3) | | 7 | 8 | 4
(8 rows)

--
-- +----------------------------------------------------------------------------------------------+
-- | A: BitmapOr |
-- ++-----------------------------+-------------------------------+-------------------------------+
-- |B: Bitmap Index Scan (aid=1) |C: Bitmap Index Scan (aid=2) |D: Bitmap Index Scan (aid=3) |
-- +-----------------------------+-------------------------------+-------------------------------+
SELECT span_id AS span_a_id,
get_epoch(span_start) as span_a_start,
get_epoch(span_end) as span_a_end
from pg_tracing_peek_spans
where trace_id='00000000000000000000000000000001' AND span_operation='BitmapOr' \gset
SELECT span_id AS span_b_id,
get_epoch(span_start) as span_b_start,
get_epoch(span_end) as span_b_end
from pg_tracing_peek_spans
where parent_id =:'span_a_id' and deparse_info='Index Cond: (a = 1)' \gset
SELECT span_id AS span_c_id,
get_epoch(span_start) as span_c_start,
get_epoch(span_end) as span_c_end
from pg_tracing_peek_spans
where parent_id =:'span_a_id' and deparse_info='Index Cond: (a = 2)' \gset
SELECT span_id AS span_d_id,
get_epoch(span_start) as span_d_start,
get_epoch(span_end) as span_d_end
from pg_tracing_peek_spans
where parent_id =:'span_a_id' and deparse_info='Index Cond: (a = 3)' \gset
SELECT :span_b_end >= :span_c_start as bitmap_or_second_child_start_after_first,
:span_c_end >= :span_d_start as bitmap_or_third_child_start_after_second,
:span_d_end <= :span_a_end as bitmap_or_ends_after_latest_child;
bitmap_or_second_child_start_after_first | bitmap_or_third_child_start_after_second | bitmap_or_ends_after_latest_child
------------------------------------------+------------------------------------------+-----------------------------------
t | t | t
(1 row)

-- Clean created spans
CALL clean_spans();
8 changes: 5 additions & 3 deletions expected/setup.out
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ $$;
CREATE OR REPLACE PROCEDURE reset_pg_tracing_test_table() AS $$
BEGIN
DROP TABLE IF EXISTS pg_tracing_test;
CREATE TABLE pg_tracing_test (a int, b char(20));
CREATE TABLE pg_tracing_test (a int, b char(20), c int);
COMMIT;
CREATE INDEX pg_tracing_index ON pg_tracing_test (a);
INSERT INTO pg_tracing_test VALUES(generate_series(1, 10000), 'aaa');
CREATE INDEX pg_tracing_index_a ON pg_tracing_test (a);
CREATE INDEX pg_tracing_index_b ON pg_tracing_test (b);
CREATE INDEX pg_tracing_index_c ON pg_tracing_test (c);
INSERT INTO pg_tracing_test SELECT *, *, * FROM generate_series(1, 10000);
ANALYZE pg_tracing_test;
END;
$$ LANGUAGE plpgsql;
Expand Down
19 changes: 19 additions & 0 deletions expected/utility.out
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ SET pg_tracing.sample_rate = 1.0;
DROP EXTENSION pg_tracing;
CREATE EXTENSION pg_tracing;
SET pg_tracing.sample_rate = 0.0;
-- Fetching spans with sort and aggregations can lead to very expensive plans
-- while only a small amount of rows is processed. Disable jit as it will add
-- a significant overhead for not much benefit
set jit=false;
-- Create utility view to keep order stable
CREATE VIEW peek_ordered_spans AS
WITH oldest_start AS (
Expand All @@ -66,6 +70,21 @@ CREATE VIEW peek_ordered_spans AS
extract(MICROSECONDS FROM age(span_start, oldest_start.min_start)) as us_start,
extract(MICROSECONDS FROM age(span_end, oldest_start.min_start)) as us_end
FROM pg_tracing_peek_spans_with_level, oldest_start order by span_start, lvl, span_end, deparse_info;
CREATE VIEW peek_ordered_spans_with_pos AS
WITH oldest_start AS (
SELECT min(span_start) as min_start FROM pg_tracing_peek_spans
), time_position AS (
SELECT time, ROW_NUMBER () OVER (ORDER BY time) as pos FROM (
SELECT span_start as time FROM pg_tracing_peek_spans_with_level
UNION
SELECT span_end as time FROM pg_tracing_peek_spans_with_level) positions
) SELECT pg_tracing_peek_spans_with_level.*, start_time.pos as pos_start, end_time.pos as pos_end,
extract(MICROSECONDS FROM age(span_start, oldest_start.min_start)) as us_start,
extract(MICROSECONDS FROM age(span_end, oldest_start.min_start)) as us_end
FROM oldest_start, pg_tracing_peek_spans_with_level
JOIN time_position start_time ON span_start = start_time.time
JOIN time_position end_time ON span_end = end_time.time
ORDER BY span_start, lvl, span_end, deparse_info;
-- Column type to convert json to record
create type span_json as ("traceId" text, "parentSpanId" text, "spanId" text, name text, "startTimeUnixNano" text, "endTimeUnixNano" text, attributes jsonb, kind int, status jsonb);
CREATE VIEW peek_json_spans AS
Expand Down
4 changes: 2 additions & 2 deletions expected/wal.out
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ FROM peek_ordered_spans;
00000000000000000000000000000002 | Planner | Planner | f | f
00000000000000000000000000000002 | ExecutorRun | ExecutorRun | |
00000000000000000000000000000002 | Update | Update on pg_tracing_test | t | t
00000000000000000000000000000002 | IndexScan | IndexScan using pg_tracing_index on pg_tracing_test | f | f
00000000000000000000000000000002 | IndexScan | IndexScan using pg_tracing_index_a on pg_tracing_test | f | f
00000000000000000000000000000002 | TransactionCommit | TransactionCommit | |
00000000000000000000000000000003 | Delete query | DELETE FROM pg_tracing_test WHERE a = $1 | t | t
00000000000000000000000000000003 | Planner | Planner | f | f
00000000000000000000000000000003 | ExecutorRun | ExecutorRun | |
00000000000000000000000000000003 | Delete | Delete on pg_tracing_test | t | t
00000000000000000000000000000003 | IndexScan | IndexScan using pg_tracing_index on pg_tracing_test | t | t
00000000000000000000000000000003 | IndexScan | IndexScan using pg_tracing_index_a on pg_tracing_test | t | t
00000000000000000000000000000003 | TransactionCommit | TransactionCommit | |
(19 rows)

Expand Down
1 change: 1 addition & 0 deletions regress/16/expected/cleanup.out
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ DROP function test_function_project_set;
DROP function test_function_result;
DROP VIEW peek_ordered_spans;
DROP VIEW peek_ordered_json_spans;
DROP VIEW peek_ordered_spans_with_pos;
DROP VIEW peek_json_spans_with_level;
DROP VIEW peek_json_spans;
DROP EXTENSION pg_tracing;
Loading

0 comments on commit bde4f56

Please sign in to comment.