Skip to content

Instantly share code, notes, and snippets.

@lukeasrodgers
Created July 29, 2016 13:56
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 lukeasrodgers/922ef0e6209c121c29f40fc9b8beb58e to your computer and use it in GitHub Desktop.
Save lukeasrodgers/922ef0e6209c121c29f40fc9b8beb58e to your computer and use it in GitHub Desktop.
http://bonesmoses.org/2016/07/15/pg-phriday-a-postgres-persepctive-on-mongodb/
CREATE TABLE sensor_log (
id SERIAL NOT NULL PRIMARY KEY,
location VARCHAR NOT NULL,
reading BIGINT NOT NULL,
reading_date TIMESTAMP NOT NULL
);
\timing
INSERT INTO sensor_log (id, location, reading, reading_date)
SELECT s.id, s.id % 1000, s.id % 100,
CURRENT_DATE - ((s.id * 10) || 's')::INTERVAL
FROM generate_series(1, 1000000) s(id);
TIME: 7236.906 ms
CREATE INDEX idx_sensor_log_date
ON sensor_log (reading_date);
TIME: 804.044 ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment