dwyl / dwyl/learn-postgresql

What is an index and how is it useful?

Open
#18 0 comments 0 reactions 1 assignee Claimed by @roryc89 View on GitHub
enhancement help wanted priority-1 question technical
Dominant language
JavaScript
Stars
346
Forks
37
PR merge metrics
No merged PRs in 30d

Description

# _The Problem_ ...

Quite a _few_ of our projects are using PostgreSQL now and one in _particular_ is running up against "_slow query_" issues ... this is because the database has no `index` so any query that does `JOIN` with _multiple_ tables will (_almost **by definition**_) take _ages_ to compute. ⏳ 😢

![oxabs-no-indexes-in-database](https://cloud.githubusercontent.com/assets/194400/19965357/843379e0-a1be-11e6-85a5-a952eb4b66f9.png)

# Tasks/Todo:

Following the `documentation-driven-learning` approach, undertake the following:

+ [ ] _**measure**_ query performance for our "slow" query and take a _screenshot_ of time/resources required to return it. (_it's **essential** to **benchmark** the **existing** state before embarking on our **quest** to lower query time!_)
+ [ ] ***research*** what an `index` _is_:
+ [ ] **what** are indices? (_thankfully our friends at Heroku have done some of the work explaining this: https://devcenter.heroku.com/articles/postgresql-indexes but we still need a `section` in **our** readme covering the topic and relevant links to any other learning resources..._)
+ [ ] **how** do I apply one to an _existing_ table (_or set of tables_)?
+ [ ] **apply** an index to your "_slowest_" and/or "_biggest_" table and
+ [ ] ***document*** _how much_ query time is improved/lowered (_with a screenshot_)

## Further Reading (_please add moar!!_)

+ General PostgreSQL performance tips (_great starting point for your quest!_): https://www.postgresql.org/docs/8.3/static/performance-tips.html
+ Using `ANALYZE` to _optimize_ PostgreSQL queries: [https://wiki.postgresql.org/wiki/ANALYZE](https://wiki.postgresql.org/wiki/Introduction_to_VACUUM,_ANALYZE,_EXPLAIN,_and_COUNT#Using_ANALYZE_to_optimize_PostgreSQL_queries)
+ Gentle intro to `index`: https://www.tutorialspoint.com/postgresql/postgresql_indexes.htm
+ Change one line 100x faster queries: https://www.datadoghq.com/blog/100x-faster-postgres-performance-by-changing-1-line/

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.