From c588df9971f41210d2fad8bf0112a78458de96cb Mon Sep 17 00:00:00 2001
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: Tue, 7 Jun 2016 19:18:31 -0400
Subject: [PATCH] Make psql_crosstab plans more stable
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

To achieve this, ANALYZE the data table before querying it, as suggested
by Tom Lane.  On my system, this enables the test to pass with 128 kB of
work_mem (a value with which other tests fail -- so it seems good
enough).

Reported by Michaël Paquier.
---
 src/test/regress/expected/psql_crosstab.out | 2 ++
 src/test/regress/sql/psql_crosstab.sql      | 3 +++
 2 files changed, 5 insertions(+)

diff --git a/src/test/regress/expected/psql_crosstab.out b/src/test/regress/expected/psql_crosstab.out
index a9c20a179b3..f45e7261326 100644
--- a/src/test/regress/expected/psql_crosstab.out
+++ b/src/test/regress/expected/psql_crosstab.out
@@ -10,6 +10,8 @@ VALUES
    ('v0','h4','dbl', -3, '2014-12-15'),
    ('v0',NULL,'qux', 5, '2014-07-15'),
    ('v1','h2','quux',7, '2015-04-04');
+-- make plans more stable
+ANALYZE ctv_data;
 -- running \crosstabview after query uses query in buffer
 SELECT v, EXTRACT(year FROM d), count(*)
  FROM ctv_data
diff --git a/src/test/regress/sql/psql_crosstab.sql b/src/test/regress/sql/psql_crosstab.sql
index 43c959b7209..dff023876bf 100644
--- a/src/test/regress/sql/psql_crosstab.sql
+++ b/src/test/regress/sql/psql_crosstab.sql
@@ -12,6 +12,9 @@ VALUES
    ('v0',NULL,'qux', 5, '2014-07-15'),
    ('v1','h2','quux',7, '2015-04-04');
 
+-- make plans more stable
+ANALYZE ctv_data;
+
 -- running \crosstabview after query uses query in buffer
 SELECT v, EXTRACT(year FROM d), count(*)
  FROM ctv_data
-- 
GitLab