|
1 | 1 | use strict;
|
2 | 2 | use warnings;
|
3 | 3 | use TestLib;
|
4 |
| -use Test::More tests => 6; |
| 4 | +use Test::More tests => 11; |
5 | 5 | use PostgresNode;
|
6 | 6 |
|
7 | 7 | my $node = PostgresNode->new('aqotest');
|
8 | 8 | $node->init;
|
9 | 9 | $node->append_conf('postgresql.conf', qq{
|
10 | 10 | shared_preload_libraries = 'aqo'
|
11 | 11 | aqo.mode = 'intelligent'
|
12 |
| - aqo.log_ignorance = 'on' |
| 12 | + aqo.log_ignorance = 'off' # TODO: solve problems with deadlock on the table creation or remove this table at all. |
13 | 13 | log_statement = 'ddl'
|
14 | 14 | });
|
15 | 15 |
|
|
51 | 51 | "$TRANSACTIONS", '-c', "$CLIENTS", '-j', "$THREADS" ],
|
52 | 52 | 'pgbench in frozen mode');
|
53 | 53 |
|
54 |
| -$node->safe_psql('postgres', "DROP EXTENSION aqo"); |
| 54 | +# ############################################################################## |
| 55 | +# |
| 56 | +# Check procedure of ML-knowledge data cleaning. |
| 57 | +# |
| 58 | +# ############################################################################## |
| 59 | + |
| 60 | +# Store OIDs of pgbench tables |
| 61 | +my $aoid = $node->safe_psql('postgres', |
| 62 | + "SELECT ('pgbench_accounts'::regclass)::oid"); |
| 63 | +my $boid = $node->safe_psql('postgres', |
| 64 | + "SELECT ('pgbench_branches'::regclass)::oid"); |
| 65 | +my $toid = $node->safe_psql('postgres', |
| 66 | + "SELECT ('pgbench_tellers'::regclass)::oid"); |
| 67 | +my $hoid = $node->safe_psql('postgres', |
| 68 | + "SELECT ('pgbench_history'::regclass)::oid"); |
| 69 | +note("oids: $aoid, $boid, $toid, $hoid"); |
| 70 | + |
| 71 | +# Add data into AQO to control that cleaning procedure won't delete nothing extra |
| 72 | +$node->safe_psql('postgres', " |
| 73 | + CREATE TABLE detector(a int); |
| 74 | + INSERT INTO detector (a) VALUES (1); |
| 75 | + UPDATE detector SET a = a + 1; |
| 76 | + DELETE FROM detector; |
| 77 | + SELECT count(*) FROM detector; |
| 78 | +"); |
| 79 | + |
| 80 | +# New queries won't add rows into AQO knowledge base. |
| 81 | +$node->safe_psql('postgres', "ALTER SYSTEM SET aqo.mode = 'disabled'"); |
| 82 | +$node->restart(); |
| 83 | +my $res = $node->safe_psql('postgres', "SHOW aqo.mode"); |
| 84 | +is($res, 'disabled'); |
| 85 | + |
| 86 | +# Number of rows in aqo_data: related to pgbench test and total value. |
| 87 | +my $pgb_fss_count = $node->safe_psql('postgres', " |
| 88 | + SELECT count(*) FROM aqo_data |
| 89 | + WHERE $aoid = ANY(oids) OR |
| 90 | + $boid = ANY(oids) OR |
| 91 | + $toid = ANY(oids) OR |
| 92 | + $hoid = ANY(oids) |
| 93 | +"); |
| 94 | +my $fss_count = $node->safe_psql('postgres', "SELECT count(*) FROM aqo_data;"); |
| 95 | + |
| 96 | +# Number of rows in aqo_queries: related to pgbench test and total value. |
| 97 | +my $pgb_fs_count = $node->safe_psql('postgres', " |
| 98 | + SELECT count(*) FROM aqo_queries |
| 99 | + WHERE fspace_hash IN ( |
| 100 | + SELECT fspace_hash FROM aqo_data |
| 101 | + WHERE |
| 102 | + $aoid = ANY(oids) OR |
| 103 | + $boid = ANY(oids) OR |
| 104 | + $toid = ANY(oids) OR |
| 105 | + $hoid = ANY(oids) |
| 106 | + ) |
| 107 | +"); |
| 108 | +my $fs_count = $node->safe_psql('postgres', "SELECT count(*) FROM aqo_queries;"); |
| 109 | + |
| 110 | +# Number of rows in aqo_query_texts: related to pgbench test and total value. |
| 111 | +my $pgb_fs_samples_count = $node->safe_psql('postgres', " |
| 112 | + SELECT count(*) FROM aqo_query_texts |
| 113 | + WHERE query_hash IN ( |
| 114 | + SELECT fspace_hash FROM aqo_data |
| 115 | + WHERE $aoid = ANY(oids) OR $boid = ANY(oids) OR $toid = ANY(oids) OR $hoid = ANY(oids) |
| 116 | + ) |
| 117 | +"); |
| 118 | +my $fs_samples_count = $node->safe_psql('postgres', "SELECT count(*) FROM aqo_query_texts;"); |
55 | 119 |
|
| 120 | +# Number of rows in aqo_query_stat: related to pgbench test and total value. |
| 121 | +my $pgb_stat_count = $node->safe_psql('postgres', " |
| 122 | + SELECT count(*) FROM aqo_query_texts |
| 123 | + WHERE query_hash IN ( |
| 124 | + SELECT fspace_hash FROM aqo_data |
| 125 | + WHERE $aoid = ANY(oids) OR $boid = ANY(oids) OR $toid = ANY(oids) OR $hoid = ANY(oids) |
| 126 | + ) |
| 127 | +"); |
| 128 | +my $stat_count = $node->safe_psql('postgres', "SELECT count(*) FROM aqo_query_stat;"); |
| 129 | + |
| 130 | +note("pgbench-related rows: aqo_data - $pgb_fss_count/$fss_count, |
| 131 | + aqo_queries: $pgb_fs_count/$fs_count, aqo_query_texts: $pgb_fs_samples_count/$fs_samples_count, |
| 132 | + aqo_query_stat: $pgb_stat_count/$stat_count"); |
| 133 | + |
| 134 | +$node->safe_psql('postgres', " |
| 135 | + DROP TABLE pgbench_accounts, pgbench_branches, pgbench_tellers, |
| 136 | + pgbench_history CASCADE;"); |
| 137 | + |
| 138 | +# Clean unneeded AQO knowledge |
| 139 | +$node->safe_psql('postgres', "SELECT clean_aqo_data()"); |
| 140 | + |
| 141 | +# Calculate total number of rows in AQO-related tables. |
| 142 | +my $new_fs_count = $node->safe_psql('postgres', "SELECT count(*) FROM aqo_queries;"); |
| 143 | +my $new_fss_count = $node->safe_psql('postgres', "SELECT count(*) FROM aqo_data;"); |
| 144 | +my $new_fs_samples_count = $node->safe_psql('postgres', "SELECT count(*) FROM aqo_query_texts;"); |
| 145 | +my $new_stat_count = $node->safe_psql('postgres', "SELECT count(*) FROM aqo_query_stat;"); |
| 146 | +note("Total AQO rows after dropping pgbench-related tables: |
| 147 | + aqo_queries: $new_fs_count, aqo_data: $new_fss_count, |
| 148 | + aqo_query_texts: $new_fs_samples_count, aqo_query_stat: $new_stat_count"); |
| 149 | + |
| 150 | +# Check total number of rows in AQO knowledge base after removing of |
| 151 | +# pgbench-related data. |
| 152 | +is($new_fs_count == $fs_count - $pgb_fs_count, 1, 'Total number of feature spaces'); |
| 153 | +is($new_fss_count == $fss_count - $pgb_fss_count, 1, 'Total number of feature subspaces'); |
| 154 | +is($new_fs_samples_count == $fs_samples_count - $pgb_fs_samples_count, 1, 'Total number of samples in aqo_query_texts'); |
| 155 | +is($new_stat_count == $stat_count - $pgb_stat_count, 1, 'Total number of samples in aqo_query_texts'); |
| 156 | + |
| 157 | +$node->safe_psql('postgres', "DROP EXTENSION aqo"); |
56 | 158 | $node->stop();
|
0 commit comments