From 849d2ac9ad9a97d4fcc0a6594d503615fa5ce37b Mon Sep 17 00:00:00 2001 From: Kenichi Ishigaki Date: Sat, 27 Jan 2018 12:34:47 +0900 Subject: [PATCH] Add a regression test for RT-124227 --- MANIFEST | 1 + t/rt_124227_index_regression.t | 74 ++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 t/rt_124227_index_regression.t diff --git a/MANIFEST b/MANIFEST index fee016a..4dfc3c8 100644 --- a/MANIFEST +++ b/MANIFEST @@ -92,6 +92,7 @@ t/lib/SQLiteTest.pm t/rt_106151_outermost_savepoint.t t/rt_106950_extra_warnings_with_savepoints.t t/rt_115465_column_info_with_spaces.t +t/rt_124227_index_regression.t t/rt_15186_prepcached.t t/rt_21406_auto_finish.t t/rt_25371_asymmetric_unicode.t diff --git a/t/rt_124227_index_regression.t b/t/rt_124227_index_regression.t new file mode 100644 index 0000000..cb55710 --- /dev/null +++ b/t/rt_124227_index_regression.t @@ -0,0 +1,74 @@ +use strict; +use warnings; +use lib "t/lib"; +use SQLiteTest; +use Test::More; +use Test::NoWarnings; + +plan tests => 5; + +my $sql_in_question = <<'EOS'; +SELECT cdid + FROM cd me +WHERE 2 > ( + SELECT COUNT( * ) + FROM cd rownum__emulation + WHERE + ( + me.genreid IS NOT NULL + AND + rownum__emulation.genreid IS NULL + ) + OR + ( + me.genreid IS NOT NULL + AND + rownum__emulation.genreid IS NOT NULL + AND + rownum__emulation.genreid < me.genreid + ) + OR + ( + ( me.genreid = rownum__emulation.genreid OR ( me.genreid IS NULL AND rownum__emulation.genreid IS NULL ) ) + AND + rownum__emulation.cdid > me.cdid + ) +) +EOS + +{ # With an index + my $dbh = connect_ok(); + $dbh->do($_) for ( + 'CREATE TABLE cd ( cdid INTEGER PRIMARY KEY NOT NULL, genreid integer )', + 'CREATE INDEX cd_idx_genreid ON cd (genreid)', + 'INSERT INTO cd ( cdid, genreid ) VALUES + ( 1, 1 ), + ( 2, NULL ), + ( 3, NULL ), + ( 4, NULL ), + ( 5, NULL ) + ', + ); + + my $res = $dbh->selectall_arrayref($sql_in_question); + + is_deeply $res => [[4], [5]], "got the expected result with the index" or note explain $res; +} + +{ # Without the index + my $dbh = connect_ok(); + $dbh->do($_) for ( + 'CREATE TABLE cd ( cdid INTEGER PRIMARY KEY NOT NULL, genreid integer )', + 'INSERT INTO cd ( cdid, genreid ) VALUES + ( 1, 1 ), + ( 2, NULL ), + ( 3, NULL ), + ( 4, NULL ), + ( 5, NULL ) + ', + ); + + my $res = $dbh->selectall_arrayref($sql_in_question); + + is_deeply $res => [[4], [5]], "got the expected result without the index" or note explain $res; +}