Skip to content

Commit 47df4f6

Browse files
committed
Add a GUC variable "synchronize_seqscans" to allow clients to disable the new
synchronized-scanning behavior, and make pg_dump disable sync scans so that it will reliably preserve row ordering. Per recent discussions.
1 parent 6dfa40d commit 47df4f6

File tree

5 files changed

+59
-14
lines changed

5 files changed

+59
-14
lines changed

doc/src/sgml/config.sgml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.162 2008/01/27 19:12:28 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.163 2008/01/30 18:35:55 tgl Exp $ -->
22

33
<chapter Id="runtime-config">
44
<title>Server Configuration</title>
@@ -4611,6 +4611,28 @@ dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir'
46114611
</listitem>
46124612
</varlistentry>
46134613

4614+
<varlistentry id="guc-synchronize-seqscans" xreflabel="synchronize_seqscans">
4615+
<term><varname>synchronize_seqscans</varname> (<type>boolean</type>)</term>
4616+
<indexterm>
4617+
<primary><varname>synchronize_seqscans</> configuration parameter</primary>
4618+
</indexterm>
4619+
<listitem>
4620+
<para>
4621+
This allows sequential scans of large tables to synchronize with each
4622+
other, so that concurrent scans read the same block at about the
4623+
same time and hence share the I/O workload. When this is enabled,
4624+
a scan might start in the middle of the table and then <quote>wrap
4625+
around</> the end to cover all rows, so as to synchronize with the
4626+
activity of scans already in progress. This can result in
4627+
unpredictable changes in the row ordering returned by queries that
4628+
have no <literal>ORDER BY</> clause. Setting this parameter to
4629+
<literal>off</> ensures the pre-8.3 behavior in which a sequential
4630+
scan always starts from the beginning of the table. The default
4631+
is <literal>on</>.
4632+
</para>
4633+
</listitem>
4634+
</varlistentry>
4635+
46144636
</variablelist>
46154637
</sect2>
46164638

src/backend/access/heap/heapam.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.248 2008/01/14 01:39:09 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.249 2008/01/30 18:35:55 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -59,6 +59,10 @@
5959
#include "utils/syscache.h"
6060

6161

62+
/* GUC variable */
63+
bool synchronize_seqscans = true;
64+
65+
6266
static HeapScanDesc heap_beginscan_internal(Relation relation,
6367
Snapshot snapshot,
6468
int nkeys, ScanKey key,
@@ -104,7 +108,8 @@ initscan(HeapScanDesc scan, ScanKey key)
104108
* the thresholds for these features could be different, we make them the
105109
* same so that there are only two behaviors to tune rather than four.
106110
* (However, some callers need to be able to disable one or both of
107-
* these behaviors, independently of the size of the table.)
111+
* these behaviors, independently of the size of the table; also there
112+
* is a GUC variable that can disable synchronized scanning.)
108113
*
109114
* During a rescan, don't make a new strategy object if we don't have to.
110115
*/
@@ -129,7 +134,7 @@ initscan(HeapScanDesc scan, ScanKey key)
129134
scan->rs_strategy = NULL;
130135
}
131136

132-
if (allow_sync)
137+
if (allow_sync && synchronize_seqscans)
133138
{
134139
scan->rs_syncscan = true;
135140
scan->rs_startblock = ss_get_location(scan->rs_rd, scan->rs_nblocks);

src/backend/utils/misc/guc.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Written by Peter Eisentraut <peter_e@gmx.net>.
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.431 2008/01/27 19:12:28 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.432 2008/01/30 18:35:55 tgl Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -110,6 +110,7 @@ extern int CommitDelay;
110110
extern int CommitSiblings;
111111
extern char *default_tablespace;
112112
extern char *temp_tablespaces;
113+
extern bool synchronize_seqscans;
113114
extern bool fullPageWrites;
114115

115116
#ifdef TRACE_SORT
@@ -1052,6 +1053,15 @@ static struct config_bool ConfigureNamesBool[] =
10521053
false, NULL, NULL
10531054
},
10541055

1056+
{
1057+
{"synchronize_seqscans", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
1058+
gettext_noop("Enable synchronized sequential scans."),
1059+
NULL
1060+
},
1061+
&synchronize_seqscans,
1062+
true, NULL, NULL
1063+
},
1064+
10551065
{
10561066
{"archive_mode", PGC_POSTMASTER, WAL_SETTINGS,
10571067
gettext_noop("Allows archiving of WAL files using archive_command."),

src/backend/utils/misc/postgresql.conf.sample

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,10 @@
476476
#backslash_quote = safe_encoding # on, off, or safe_encoding
477477
#default_with_oids = off
478478
#escape_string_warning = on
479-
#standard_conforming_strings = off
480479
#regex_flavor = advanced # advanced, extended, or basic
481480
#sql_inheritance = on
481+
#standard_conforming_strings = off
482+
#synchronize_seqscans = on
482483

483484
# - Other Platforms and Clients -
484485

src/bin/pg_dump/pg_dump.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* by PostgreSQL
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.481 2008/01/01 19:45:55 momjian Exp $
15+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.482 2008/01/30 18:35:55 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -552,6 +552,20 @@ main(int argc, char **argv)
552552
/* Set the datestyle to ISO to ensure the dump's portability */
553553
do_sql_command(g_conn, "SET DATESTYLE = ISO");
554554

555+
/*
556+
* If supported, set extra_float_digits so that we can dump float data
557+
* exactly (given correctly implemented float I/O code, anyway)
558+
*/
559+
if (g_fout->remoteVersion >= 70400)
560+
do_sql_command(g_conn, "SET extra_float_digits TO 2");
561+
562+
/*
563+
* If synchronized scanning is supported, disable it, to prevent
564+
* unpredictable changes in row ordering across a dump and reload.
565+
*/
566+
if (g_fout->remoteVersion >= 80300)
567+
do_sql_command(g_conn, "SET synchronize_seqscans TO off");
568+
555569
/*
556570
* Start serializable transaction to dump consistent data.
557571
*/
@@ -567,13 +581,6 @@ main(int argc, char **argv)
567581
else
568582
username_subquery = "SELECT usename FROM pg_user WHERE usesysid =";
569583

570-
/*
571-
* If supported, set extra_float_digits so that we can dump float data
572-
* exactly (given correctly implemented float I/O code, anyway)
573-
*/
574-
if (g_fout->remoteVersion >= 70400)
575-
do_sql_command(g_conn, "SET extra_float_digits TO 2");
576-
577584
/* Find the last built-in OID, if needed */
578585
if (g_fout->remoteVersion < 70300)
579586
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy