Skip to content

Instantly share code, notes, and snippets.

@lgastako
Last active September 22, 2015 06:58
Show Gist options
  • Save lgastako/3e11998cc44997b50edb to your computer and use it in GitHub Desktop.
Save lgastako/3e11998cc44997b50edb to your computer and use it in GitHub Desktop.
CREATE VIEW salesforce.actual_sf_task_count AS
SELECT COUNT(*) sf_task_count
FROM salesforce.sf_task;
-- [local]:5432 salesforce@salesforce # SELECT * FROM actual_sf_task_count;
-- +---------------+
-- | sf_task_count |
-- +---------------+
-- | 8226055 |
-- +---------------+
-- (1 row)
-- Time: 2508.322 ms
CREATE VIEW salesforce.estimated_sf_task_count AS
SELECT reltuples::integer AS sf_task_count
FROM pg_class
WHERE oid = 'salesforce.sf_task'::regclass;
-- [local]:5432 salesforce@salesforce # SELECT * FROM estimated_sf_task_count;
-- +---------------+
-- | sf_task_count |
-- +---------------+
-- | 8226055 |
-- +---------------+
-- (1 row)
-- Time: 0.465 ms
CREATE FOREIGN TABLE slush.fdw_actual_sf_task_count (
sf_task_count INTEGER
)
SERVER salesforce OPTIONS (
schema_name 'salesforce',
table_name 'actual_sf_task_count'
);
-- [local]:5432 slush@slush # EXPLAIN VERBOSE SELECT * FROM slush.fdw_actual_sf_task_count;
-- +--------------------------------------------------------------------------------------------+
-- | QUERY PLAN |
-- +--------------------------------------------------------------------------------------------+
-- | Foreign Scan on slush.fdw_actual_sf_task_count (cost=351767.69..351767.72 rows=1 width=0) |
-- | Output: sf_task_count |
-- | Remote SQL: SELECT sf_task_count FROM salesforce.actual_sf_task_count |
-- +--------------------------------------------------------------------------------------------+
-- (3 rows)
-- Time: 7.936 ms
CREATE FOREIGN TABLE slush.fdw_estimated_sf_task_count (
sf_task_count INTEGER
)
SERVER salesforce OPTIONS (
schema_name 'salesforce',
table_name 'estimated_sf_task_count'
);
-- [local]:5432 slush@slush # EXPLAIN VERBOSE SELECT * FROM slush.fdw_estimated_sf_task_count;
-- +-----------------------------------------------------------------------------------------+
-- | QUERY PLAN |
-- +-----------------------------------------------------------------------------------------+
-- | Foreign Scan on slush.fdw_estimated_sf_task_count (cost=100.27..108.31 rows=1 width=4) |
-- | Output: sf_task_count |
-- | Remote SQL: SELECT sf_task_count FROM salesforce.estimated_sf_task_count |
-- +-----------------------------------------------------------------------------------------+
-- (3 rows)
-- Time: 1.591 ms
SELECT COUNT(*)
FROM salesforce.sf_task;
-- [local]:5432 slush@slush # SELECT COUNT(*)
-- slush-# FROM salesforce.sf_task;
-- +---------+
-- | count |
-- +---------+
-- | 8226055 |
-- +---------+
-- (1 row)
-- Time: 11673.777 ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment