Skip to content

Instantly share code, notes, and snippets.

@zozo
Created June 12, 2012 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zozo/2917730 to your computer and use it in GitHub Desktop.
Save zozo/2917730 to your computer and use it in GitHub Desktop.
mc_development=# EXPLAIN select distinct surface_id from prices;
QUERY PLAN
--------------------------------------------------------------------------------------------------------
Unique (cost=0.00..58326.38 rows=87660 width=4)
-> Index Scan using index_prices_on_surface_id on prices (cost=0.00..57102.49 rows=489558 width=4)
(2 rows)
mc_development=# EXPLAIN select distinct surface_id from stocks;
QUERY PLAN
---------------------------------------------------------------------
HashAggregate (cost=12660.70..13038.76 rows=37806 width=4)
-> Seq Scan on stocks (cost=0.00..11179.96 rows=592296 width=4)
(2 rows)
mc_development=# \d stocks
Table "public.stocks"
Column | Type | Modifiers
------------+-----------------------------+-----------------------------------------------------
id | integer | not null default nextval('stocks_id_seq'::regclass)
surface_id | integer |
interval | character varying(255) |
status | integer |
created_at | timestamp without time zone |
updated_at | timestamp without time zone |
Indexes:
"stocks_pkey" PRIMARY KEY, btree (id)
"index_stocks_on_surface_id_and_interval" UNIQUE, btree (surface_id, "interval")
"index_stocks_on_interval" btree ("interval")
"index_stocks_on_surface_id" btree (surface_id)
mc_development=# \d prices
Table "public.prices"
Column | Type | Modifiers
----------------+-----------------------------+-----------------------------------------------------
id | integer | not null default nextval('prices_id_seq'::regclass)
surface_id | integer |
interval | character varying(255) |
price_base | integer |
price_sell | integer |
price_discount | integer |
price_our | integer |
created_at | timestamp without time zone |
updated_at | timestamp without time zone |
Indexes:
"prices_pkey" PRIMARY KEY, btree (id)
"index_prices_on_surface_id_and_interval" UNIQUE, btree (surface_id, "interval")
"index_prices_on_interval" btree ("interval")
"index_prices_on_surface_id" btree (surface_id)
mc_development=# select count(*) from stocks;
count
--------
592296
(1 row)
mc_development=# select count(*) from prices;
count
--------
500000
(1 row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment