SlideShare a Scribd company logo
PostgreSQL Index
create table staging.account(account_id serial primary key,name text, dob date);
create table staging.blog (blog_id serial primary key, account_id integer not
null references staging.account(account_id),title text);
create table staging.post (post_id serial primary key, blog_id integer not null
references staging.blog(blog_id), account_id integer not null references
staging.account(account_id),visible boolean default false, blog_test text);
Some simple query we perform to check
• See all my blog post
• How many post a user create
• See all current blog
• How may blog a user create
• See all current post of a blog for time period
Data(using python faker lib)
pip install Faker
A simple script to generate fake names. Use this script and generate fake name for account. Here we are generating 100
account name and 1000 blog title and
from faker import Faker
fake = Faker()
for x in range(100):
print (fake.name())
# for generate random blog title
For x in range(1000):
select random() * 99 + 1; # for random number range from 1 to 100
print (fake.slug())
Let explain and analyse query
explain analyse select * from staging.post where blog_id = 4334;
Seq Scan on post (cost=0.00..441.51 rows=7 width=364)
(actual time=0.354..1.568 rows=7 loops=1)
Filter: (blog_id = 4334)
Rows Removed by Filter: 7085
Planning Time: 0.084 ms
Execution Time: 1.590 ms
Bitmap Heap Scan on post (cost=4.34..29.47 rows=7
width=364) (actual time=0.035..0.045 rows=7 loops=1)
Recheck Cond: (blog_id = 4334)
Heap Blocks: exact=7
-> Bitmap Index Scan on post_blog_id_idx (cost=0.00..4.33
rows=7 width=0) (actual time=0.028..0.028 rows=7 loops=1)
Index Cond: (blog_id = 4334)
Planning Time: 0.360 ms
Execution Time: 0.078 ms
After creating index on post table.

More Related Content

PDF
TYPO3 User Group - Lausanne - 12 novembre 2013
PDF
Parsing swiftly-Cocoaheads-2015-02-12
PPTX
Introduction to JQuery
PPTX
Web весна 2013 лекция 6
KEY
Scala on Your Phone
PPTX
Web осень 2012 лекция 6
PDF
Type Systems & Props Design - Exploring PropTypes, TypeScript, Flow & Reason
DOC
Modify the bouncing ball example demonstrated/tutorialoutlet
TYPO3 User Group - Lausanne - 12 novembre 2013
Parsing swiftly-Cocoaheads-2015-02-12
Introduction to JQuery
Web весна 2013 лекция 6
Scala on Your Phone
Web осень 2012 лекция 6
Type Systems & Props Design - Exploring PropTypes, TypeScript, Flow & Reason
Modify the bouncing ball example demonstrated/tutorialoutlet

What's hot (17)

DOCX
01 list using array
PDF
Difference between mysql_fetch_array and mysql_fetch_assoc in PHP
PPT
jQuery Plugin
PDF
Twitter sentiment analysis for cryptoassets
PPTX
Web осень 2012 лекция 7
DOC
Java script frame history
 
PDF
for this particular program how do i create the input innotepad 1st ?#include...
PDF
Practical TypeScript
PDF
Reactive clean architecture
KEY
Testing Your Sproutcore Presentation
DOCX
Add row in asp.net Gridview on button click using C# and vb.net
PDF
Constraints: A Developer's Secret Weapon | PostgreSQL Conference EU 2018 | Wi...
PDF
Constraints: A Developer's Secret Weapon | pgDay Paris 2018 | Will Leinweber
PPTX
5. CodeIgniter copy1
PPT
Introduction to JQuery
01 list using array
Difference between mysql_fetch_array and mysql_fetch_assoc in PHP
jQuery Plugin
Twitter sentiment analysis for cryptoassets
Web осень 2012 лекция 7
Java script frame history
 
for this particular program how do i create the input innotepad 1st ?#include...
Practical TypeScript
Reactive clean architecture
Testing Your Sproutcore Presentation
Add row in asp.net Gridview on button click using C# and vb.net
Constraints: A Developer's Secret Weapon | PostgreSQL Conference EU 2018 | Wi...
Constraints: A Developer's Secret Weapon | pgDay Paris 2018 | Will Leinweber
5. CodeIgniter copy1
Introduction to JQuery
Ad

Similar to Postgre sql index (9)

PDF
Python in the database
KEY
PostgreSQL
PDF
JDD 2016 - Tomasz Borek - DB for next project? Why, Postgres, of course
PPTX
Connecting and using PostgreSQL database with psycopg2 [Python 2.7]
PDF
Programming with Python and PostgreSQL
PDF
Chris Lea - What does NoSQL Mean for You
PDF
DataDay 2023 Presentation
PDF
PostgreSQL 9.0 & The Future
PDF
MySQL Cookbook: Recipes for Your Business
Python in the database
PostgreSQL
JDD 2016 - Tomasz Borek - DB for next project? Why, Postgres, of course
Connecting and using PostgreSQL database with psycopg2 [Python 2.7]
Programming with Python and PostgreSQL
Chris Lea - What does NoSQL Mean for You
DataDay 2023 Presentation
PostgreSQL 9.0 & The Future
MySQL Cookbook: Recipes for Your Business
Ad

Recently uploaded (20)

PPTX
AI Strategy room jwfjksfksfjsjsjsjsjfsjfsj
PPTX
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
PPTX
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
PDF
Mega Projects Data Mega Projects Data
PPTX
Acceptance and paychological effects of mandatory extra coach I classes.pptx
PDF
BF and FI - Blockchain, fintech and Financial Innovation Lesson 2.pdf
PPTX
IBA_Chapter_11_Slides_Final_Accessible.pptx
PDF
Lecture1 pattern recognition............
PDF
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
PPT
Reliability_Chapter_ presentation 1221.5784
PDF
.pdf is not working space design for the following data for the following dat...
PPTX
IB Computer Science - Internal Assessment.pptx
PPTX
iec ppt-1 pptx icmr ppt on rehabilitation.pptx
PPTX
Database Infoormation System (DBIS).pptx
PPTX
Data_Analytics_and_PowerBI_Presentation.pptx
PDF
22.Patil - Early prediction of Alzheimer’s disease using convolutional neural...
PPTX
Computer network topology notes for revision
PPTX
Market Analysis -202507- Wind-Solar+Hybrid+Street+Lights+for+the+North+Amer...
PPTX
SAP 2 completion done . PRESENTATION.pptx
PPTX
ALIMENTARY AND BILIARY CONDITIONS 3-1.pptx
AI Strategy room jwfjksfksfjsjsjsjsjfsjfsj
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
Mega Projects Data Mega Projects Data
Acceptance and paychological effects of mandatory extra coach I classes.pptx
BF and FI - Blockchain, fintech and Financial Innovation Lesson 2.pdf
IBA_Chapter_11_Slides_Final_Accessible.pptx
Lecture1 pattern recognition............
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
Reliability_Chapter_ presentation 1221.5784
.pdf is not working space design for the following data for the following dat...
IB Computer Science - Internal Assessment.pptx
iec ppt-1 pptx icmr ppt on rehabilitation.pptx
Database Infoormation System (DBIS).pptx
Data_Analytics_and_PowerBI_Presentation.pptx
22.Patil - Early prediction of Alzheimer’s disease using convolutional neural...
Computer network topology notes for revision
Market Analysis -202507- Wind-Solar+Hybrid+Street+Lights+for+the+North+Amer...
SAP 2 completion done . PRESENTATION.pptx
ALIMENTARY AND BILIARY CONDITIONS 3-1.pptx

Postgre sql index

  • 1. PostgreSQL Index create table staging.account(account_id serial primary key,name text, dob date); create table staging.blog (blog_id serial primary key, account_id integer not null references staging.account(account_id),title text); create table staging.post (post_id serial primary key, blog_id integer not null references staging.blog(blog_id), account_id integer not null references staging.account(account_id),visible boolean default false, blog_test text);
  • 2. Some simple query we perform to check • See all my blog post • How many post a user create • See all current blog • How may blog a user create • See all current post of a blog for time period
  • 3. Data(using python faker lib) pip install Faker A simple script to generate fake names. Use this script and generate fake name for account. Here we are generating 100 account name and 1000 blog title and from faker import Faker fake = Faker() for x in range(100): print (fake.name()) # for generate random blog title For x in range(1000): select random() * 99 + 1; # for random number range from 1 to 100 print (fake.slug())
  • 4. Let explain and analyse query explain analyse select * from staging.post where blog_id = 4334; Seq Scan on post (cost=0.00..441.51 rows=7 width=364) (actual time=0.354..1.568 rows=7 loops=1) Filter: (blog_id = 4334) Rows Removed by Filter: 7085 Planning Time: 0.084 ms Execution Time: 1.590 ms Bitmap Heap Scan on post (cost=4.34..29.47 rows=7 width=364) (actual time=0.035..0.045 rows=7 loops=1) Recheck Cond: (blog_id = 4334) Heap Blocks: exact=7 -> Bitmap Index Scan on post_blog_id_idx (cost=0.00..4.33 rows=7 width=0) (actual time=0.028..0.028 rows=7 loops=1) Index Cond: (blog_id = 4334) Planning Time: 0.360 ms Execution Time: 0.078 ms After creating index on post table.