Skip to content
This repository was archived by the owner on Sep 23, 2024. It is now read-only.

Commit 4c29e65

Browse files
authored
Trick Postgres into more efficiant use of index (#189)
1 parent e7db01e commit 4c29e65

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
1.8.4 (2022-09-08)
2+
-------------------
3+
**Changes**
4+
- INCREMENTAL: Use sub-query to trick PostreSQL into more efficient use of index.
5+
16
1.8.3 (2022-01-18)
27
-------------------
38
**Fixes**
@@ -48,7 +53,7 @@
4853
Fix data loss issue when running `LOG_BASED` due to the tap not sending new SCHEMA singer messages when source tables change structure, mainly new/renamed columns, which causes the target to not be up to date with the stream structure.
4954
The tap now:
5055
* Runs discovery for selected stream at the beginning of sync to send up to date SCHEMA singer messages
51-
* When new columns are detected in WAL payloads, then run discovery for the stream and send new SCHEMA message.
56+
* When new columns are detected in WAL payloads, then run discovery for the stream and send new SCHEMA message.
5257

5358
1.6.2 (2020-05-18)
5459
-------------------

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
long_description = f.read()
77

88
setup(name='pipelinewise-tap-postgres',
9-
version='1.8.3',
9+
version='1.8.4',
1010
description='Singer.io tap for extracting data from PostgresSQL - PipelineWise compatible',
1111
long_description=long_description,
1212
long_description_content_type='text/markdown',

tap_postgres/sync_strategies/incremental.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,17 @@ def _get_select_sql(params):
129129
stream = params['stream']
130130
if replication_key_value:
131131
select_sql = f"""
132-
SELECT {','.join(escaped_columns)}
133-
FROM {post_db.fully_qualified_table_name(schema_name, stream['table_name'])}
134-
WHERE {post_db.prepare_columns_sql(replication_key)} >= '{replication_key_value}'::{replication_key_sql_datatype}
135-
ORDER BY {post_db.prepare_columns_sql(replication_key)} ASC"""
132+
SELECT {','.join(escaped_columns)}
133+
FROM (
134+
SELECT *
135+
FROM {post_db.fully_qualified_table_name(schema_name, stream['table_name'])}
136+
WHERE {post_db.prepare_columns_sql(replication_key)} >= '{replication_key_value}'::{replication_key_sql_datatype}
137+
ORDER BY {post_db.prepare_columns_sql(replication_key)} ASC
138+
) pg_speedup_trick"""
136139
else:
137140
# if not replication_key_value
138-
select_sql = f"""SELECT {','.join(escaped_columns)}
139-
FROM {post_db.fully_qualified_table_name(schema_name, stream['table_name'])}
140-
ORDER BY {post_db.prepare_columns_sql(replication_key)} ASC"""
141+
select_sql = f"""
142+
SELECT {','.join(escaped_columns)}
143+
FROM {post_db.fully_qualified_table_name(schema_name, stream['table_name'])}
144+
"""
141145
return select_sql

0 commit comments

Comments
 (0)