- Notifications
You must be signed in to change notification settings - Fork58
Remake of pglist_test.py but on the perl.#136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
2 changes: 2 additions & 0 deletionsMakefile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletionsREADME.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
207 changes: 207 additions & 0 deletionst/002_pglist.pl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
# Test RUM index with big base 'pglist'. | ||
use strict; | ||
use warnings; | ||
use Config; | ||
use Test::More; | ||
plan skip_all => 'This test requires downloading a 1GB archive. ' . | ||
'The unpacked file weighs almost 3GB. ' . | ||
'Perform only if the big_values is enabled in PG_TEST_EXTRA' | ||
unless $ENV{PG_TEST_EXTRA} && $ENV{PG_TEST_EXTRA} =~ /\bbig_values\b/; | ||
plan tests => 4; | ||
my $node; | ||
# Utility function | ||
sub file_exists | ||
{ | ||
my ($file) = @_; | ||
return -e $file; | ||
} | ||
# Check the existence of the test base, install if necessary | ||
sub install_pglist | ||
{ | ||
my $dir = Cwd->getcwd; #current directory | ||
my %config = ( | ||
#directory with pglist dump must be inside the current directory | ||
pglist_tmp_dir=> $dir . '/pglist_tmp/', | ||
dump_name=> 'pglist-28-04-16.dump', | ||
dump_url=> 'http://www.sai.msu.su/~megera/postgres/files/pglist-28-04-16.dump.gz', | ||
pglist_archive=> $dir . '/pglist_tmp/' . 'pglist-28-04-16.dump.gz', | ||
); | ||
my $path_to_dump = $config{pglist_tmp_dir} . $config{dump_name}; | ||
if (file_exists($path_to_dump)) | ||
{ | ||
note($config{dump_name} . ' already installed'); | ||
} | ||
else | ||
{ | ||
# Create folder /contrib/rum/pglist_tmp if not already exists | ||
mkdir($config{pglist_tmp_dir}, 0700) | ||
unless file_exists($config{pglist_tmp_dir}); | ||
# Download archive pglist-28-04-16.dump.gz if not already exists | ||
unless (file_exists($config{pglist_archive})) | ||
{ | ||
note('Downloading pglist dump in ' . $config{pglist_archive}); | ||
# Flag "-nv" allows us to avoid frequent messages | ||
# about the download status in the log. | ||
# But it can be enabled for debugging purposes. | ||
system("wget -P $config{pglist_tmp_dir} -nv $config{dump_url}") == 0 | ||
or die "Couldn't get archive by link: $?"; | ||
} | ||
# Unzip the dump. Delete archive to save memory | ||
system("gzip -d $config{pglist_archive}") == 0 | ||
or die "Couldn't extract archive: $?"; | ||
file_exists($path_to_dump) | ||
or die "Failed to get " . $config{dump_name}; | ||
note($config{dump_name} . ' is ready to use'); | ||
} | ||
$node->psql("postgres", "CREATE DATABASE pglist"); | ||
$node->psql("postgres", "CREATE ROLE oleg"); | ||
my $command = "'" . $path_to_dump . "'"; | ||
my $result = $node->psql("pglist", '\i ' . $command); | ||
} | ||
# Tests SELECT constructions to 'pglist' base | ||
sub test_select | ||
{ | ||
note("Creating index 'rumidx_orderby_sent'"); | ||
$node->safe_psql("pglist", "CREATE INDEX rumidx_orderby_sent ON pglist " . | ||
"USING rum (fts rum_tsvector_timestamp_ops, sent) " . | ||
"WITH (attach=sent, to=fts, order_by_attach=t)"); | ||
note("Test ORDER BY timestamp"); | ||
my $result1 = $node->safe_psql("pglist", | ||
"SELECT sent, subject FROM pglist WHERE fts @@ " . | ||
"to_tsquery('english', 'backend <-> crushed') " . | ||
"ORDER BY sent <=| '2016-01-01 00:01' LIMIT 5"); | ||
is($result1, '1999-06-02 11:52:46|Re: [HACKERS] PID of backend'); | ||
note("Test tsvector filter"); | ||
my $result2 = $node->safe_psql("pglist", | ||
"SELECT count(*) FROM pglist " . | ||
"WHERE fts @@ to_tsquery('english', 'tom & lane')"); | ||
is($result2, '222813'); | ||
$node->safe_psql("pglist", "DROP INDEX rumidx_orderby_sent"); | ||
} | ||
sub test_order_by | ||
{ | ||
note("Creating index 'pglist_rum_idx'"); | ||
$node->safe_psql("pglist", | ||
"CREATE INDEX pglist_rum_idx ON pglist " . | ||
"USING rum (fts rum_tsvector_ops)"); | ||
note("Test ORDER BY tsvector"); | ||
my $result3 = $node->safe_psql("pglist", | ||
"SELECT id FROM pglist " . | ||
"WHERE fts @@ to_tsquery('english', 'postgres:*') " . | ||
"ORDER BY fts <=> " . | ||
"to_tsquery('english', 'postgres:*') LIMIT 9"); | ||
is((split(" ", $result3))[0], '816114'); | ||
# Autovacuum after large update, with active RUM index crashes postgres | ||
note("Test Issue #19"); | ||
my $stderr; | ||
$node->safe_psql("pglist", "DELETE FROM pglist WHERE id < 100000"); | ||
$node->safe_psql("pglist", "vacuum", stderr => \$stderr); | ||
is($stderr, undef); | ||
$node->safe_psql("pglist", "DROP INDEX pglist_rum_idx"); | ||
} | ||
# Start backend | ||
my $pg_15_modules; | ||
BEGIN | ||
{ | ||
$pg_15_modules = eval | ||
{ | ||
require PostgreSQL::Test::Cluster; | ||
require PostgreSQL::Test::Utils; | ||
return 1; | ||
}; | ||
unless (defined $pg_15_modules) | ||
{ | ||
$pg_15_modules = 0; | ||
require PostgresNode; | ||
require TestLib; | ||
} | ||
} | ||
note('PostgreSQL 15 modules are used: ' . ($pg_15_modules ? 'yes' : 'no')); | ||
if ($pg_15_modules) | ||
{ | ||
$node = PostgreSQL::Test::Cluster->new("master"); | ||
} | ||
else | ||
{ | ||
$node = PostgresNode::get_new_node("master"); | ||
} | ||
$node->init(allows_streaming => 1); | ||
$node->append_conf("postgresql.conf", "shared_buffers='4GB'\n" . | ||
"maintenance_work_mem='2GB'\n" . | ||
"max_wal_size='2GB'\n" . | ||
"work_mem='50MB'"); | ||
$node->start; | ||
# Check the existence of the pglist base | ||
note('Check the existence of the pglist base...'); | ||
my $check_pglist = $node->psql('postgres', "SELECT count(*) FROM pg_database " . | ||
"WHERE datistemplate = false AND " . | ||
"datname = 'pglist'"); | ||
if ($check_pglist == 1) | ||
{ | ||
note("pglist already exists"); | ||
} | ||
else | ||
{ | ||
note("Create pglist database"); | ||
install_pglist(); | ||
} | ||
$node->psql("pglist", "CREATE EXTENSION rum"); | ||
note('Setup is completed successfully'); | ||
eval | ||
{ | ||
test_select(); | ||
test_order_by(); | ||
$node->stop(); | ||
done_testing(); | ||
1; | ||
} or do { | ||
note('Something went wrong: $@\n'); | ||
}; | ||
14 changes: 0 additions & 14 deletionstests/README.md
This file was deleted.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Empty file removedtests/__init__.py
Empty file.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.