Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit997f12a

Browse files
committed
Add dummy tests on the AQO and pg_stat_statements collaboration by using
the same queryid.TODO: Should we arrange the AQO naming convention too?
1 parent9cb041f commit997f12a

File tree

2 files changed

+50
-22
lines changed

2 files changed

+50
-22
lines changed

‎t/001_pgbench.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
});
1717

1818
# Test constants. Default values.
19-
my$TRANSACTIONS =1000;
19+
my$TRANSACTIONS =1;
2020
my$CLIENTS = 10;
2121
my$THREADS = 10;
2222

‎t/002_pg_stat_statements_aqo.pl

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use warnings;
33
use PostgreSQL::Test::Cluster;
44
use PostgreSQL::Test::Utils;
5-
use Test::Moretests=>3;
5+
use Test::Moretests=>4;
66
print"start";
77
my$node = PostgreSQL::Test::Cluster->new('profiling');
88
$node->init;
@@ -24,20 +24,19 @@
2424
# General purpose variables.
2525
my$res;
2626
my$total_classes;
27+
28+
# Check: allow to load the libraries only on startup
2729
$node->start();
28-
# ERROR: AQO allow to load library only on startup
29-
print"create extantion aqo";
3030
$node->psql('postgres',"CREATE EXTENSION aqo");
3131
$node->psql('postgres',"CREATE EXTENSION pg_stat_statements");
32-
print"create preload libraries";
33-
$node->append_conf('postgresql.conf',qq{shared_preload_libraries = 'aqo, pg_stat_statements'});
32+
33+
$node->append_conf('postgresql.conf',qq{
34+
shared_preload_libraries = 'aqo, pg_stat_statements'
35+
aqo.mode = 'learn' # unconditional learning
36+
});
3437
$node->restart();
3538
$node->psql('postgres',"CREATE EXTENSION aqo");
3639
$node->psql('postgres',"CREATE EXTENSION pg_stat_statements");
37-
$node->psql('postgres',"
38-
ALTER SYSTEM SET aqo.profile_enable = 'true';
39-
SELECT pg_reload_conf();
40-
");
4140

4241
$node->psql('postgres',"CREATE TABLE aqo_test0(a int, b int, c int, d int);
4342
WITH RECURSIVE t(a, b, c, d)
@@ -48,18 +47,47 @@
4847
) INSERT INTO aqo_test0 (SELECT * FROM t);
4948
CREATE INDEX aqo_test0_idx_a ON aqo_test0 (a);
5049
ANALYZE aqo_test0;");
51-
$node->psql('postgres',"
52-
ALTER SYSTEM SET aqo.mode = 'controlled';
53-
");
50+
5451
$res =$node->safe_psql('postgres',"SELECT * FROM aqo_test0");
5552
$res =$node->safe_psql('postgres',"SELECT count(*) FROM pg_stat_statements where query = 'SELECT * FROM aqo_test0'");
56-
is($res, 1);# The same query add in pg_stat_statements
57-
$res =$node->safe_psql('postgres',"SELECT count(*) from aqo_query_texts where query_text = 'SELECT * FROM aqo_test0'");
58-
is($res, 0);# The same query isn't add in aqo_query_texts
59-
$query_id =$node->safe_psql('postgres',"SELECT queryid FROM pg_stat_statements where query = 'SELECT * FROM aqo_test0'");
60-
$res =$node->safe_psql('postgres',"insert into aqo_queries values ($query_id,'f','f',$query_id,'f')");
61-
# Add query in aqo_query_texts
62-
$res =$node->safe_psql('postgres',"insert into aqo_query_texts values ($query_id,'SELECT * FROM aqo_test0')");
63-
$res =$node->safe_psql('postgres',"SELECT count(*) from aqo_query_texts where query_text = 'SELECT * FROM aqo_test0'");# The same query is in aqo_query_texts
53+
54+
# Check number of queries which logged in both extensions.
55+
$res =$node->safe_psql('postgres',"
56+
SELECT count(*) FROM aqo_query_texts aqt, pg_stat_statements pgss
57+
WHERE aqt.query_hash = pgss.queryid
58+
");
59+
is($res, 3);
60+
61+
# TODO: Maybe AQO should parameterize query text too?
62+
$res =$node->safe_psql('postgres',"
63+
SELECT count(*) FROM aqo_query_texts aqt, pg_stat_statements pgss
64+
WHERE aqt.query_hash = pgss.queryid AND aqt.query_text = pgss.query
65+
");
6466
is($res, 1);
65-
$node->stop();
67+
68+
# Just fix a number of differences
69+
$res =$node->safe_psql('postgres',"
70+
SELECT count(*) FROM aqo_query_texts
71+
WHERE query_hash NOT IN (SELECT queryid FROM pg_stat_statements)
72+
");
73+
is($res, 1);
74+
75+
$res =$node->safe_psql('postgres',"
76+
SELECT query_text FROM aqo_query_texts
77+
WHERE query_hash NOT IN (SELECT queryid FROM pg_stat_statements)
78+
");
79+
note($res);# Just see differences
80+
81+
$res =$node->safe_psql('postgres',"
82+
SELECT count(*) FROM pg_stat_statements
83+
WHERE queryid NOT IN (SELECT query_hash FROM aqo_query_texts)
84+
");
85+
is($res, 8);
86+
87+
$res =$node->safe_psql('postgres',"
88+
SELECT query FROM pg_stat_statements
89+
WHERE queryid NOT IN (SELECT query_hash FROM aqo_query_texts)
90+
");
91+
note($res);# Just see differences
92+
93+
$node->stop();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp