SlideShare ist ein Scribd-Unternehmen logo
1 von 19
Mesut ÖNCEL Software Developer
mstoncel
@mesutoncel
mesutoncel
mesutoncel91@gmail.com
@mesutoncel
Neden index kullanıyoruz?
B-tree Index
Expression Index
CREATE INDEX idx_name on table_name (expression)
CREATE TABLE user_data AS
SELECT d as date,
'user_' || replace((d :: date) :: text, '-', '') ||'@gmail.com' email,
md5(d :: text) as padding,
replace((d :: date) :: text, '-', '') :: int as number
FROM generate_series(timestamp '1800-01-01',
timestamp '2200-01-01',
interval '1 day') s (d);
date email pading number
1800-01-01 00:00:00.000000 user_18000101@gmail.com 18077793d1afc397046f46adfaeab411 18000101
1800-01-02 00:00:00.000000 user_18000102@gmail.com 14368f03d495281d3a3d33e02c1bf80c 18000102
1800-01-03 00:00:00.000000 user_18000103@gmail.com dcc6b0efdbacbb4540671a50a33744d2 18000103
1800-01-04 00:00:00.000000 user_18000104@gmail.com 6999a16531d1e33f244cc894613a0c8d 18000104
1800-01-05 00:00:00.000000 user_18000105@gmail.com 8685fb2051aa8cd05db09a150fb74095 18000105
1800-01-06 00:00:00.000000 user_18000106@gmail.com 02b1e445353227c019aa6ef8c027c744 18000106
1800-01-07 00:00:00.000000 user_18000107@gmail.com 3c898ba68d6249a819257fa0799b0bac 18000107
1800-01-08 00:00:00.000000 user_18000108@gmail.com 9322fd00eadfff94e90f582dd0ed12d8 18000108
1800-01-09 00:00:00.000000 user_18000109@gmail.com 830787e882375bdb0a5b526b90d998fa 18000109
EXPLAIN ANALYZE select * from user_data where upper(email) ='USER'
Seq Scan on user_data (cost=0.00..3995.47 rows=730 width=65) (actual time=96.941..96.941 rows=0 loops=1)
Filter: (upper(email) = 'USER'::text)
Rows Removed by Filter: 146098
Planning time: 0.248 ms
Execution time: 96.970 ms
CREATE INDEX idx_user_email on user_data (upper(email))
Bitmap Heap Scan on user_data (cost=22.08..1406.12 rows=730 width=65) (actual time=0.062..0.062 rows=0 loops=1)
Recheck Cond: (upper(email) = 'USER'::text)
-> Bitmap Index Scan on idx_user_email (actual time=0.059..0.059 rows=0 loops=1)
Index Cond: (upper(email) = ‘USER'::text)
Planning time: 1.172 ms
Execution time: 0.097 ms
EXPLAIN ANALYZE select * from user_data where upper(email) ='USER'
EXPLAIN ANALYZE select * from user_data order by (email || padding) desc
Sort (cost=24153.43..24518.68 rows=146098 width=101) (actual time=3486.804..4286.983 rows=146098 loops=1)
Sort Key: ((email || padding)) DESC
Sort Method: external merge Disk: 19616kB
-> Seq Scan on user_data (cost=0.00..3630.22 rows=146098 width=101) (actual time=0.018..66.519 rows=146098 loops=1)
Planning time: 0.160 ms
Execution time: 4313.415 ms
create index idx_col_text on user_data ((email || padding))
EXPLAIN ANALYZE select * from user_data order by (email || padding) desc
Index Scan Backward using idx_col_text on user_data (cost=0.42..15313.14 rows=146098 width=101) (a
Planning time: 0.218 ms
Execution time: 90.887 ms
explain analyze select * from user_data where number::text like '18000%'
Seq Scan on user_data (cost=0.00..4360.72 rows=730 width=69) (actual time=0.015..69.488 rows=273 loops=1)
Filter: ((number)::text ~~ '18000%'::text)
Rows Removed by Filter: 145825
Planning time: 0.144 ms
Execution time: 69.519 ms
explain analyze select * from user_data where number::text like '18000%'
create index idx_user_data_b_tree on user_data ((number::text))
Seq Scan on user_data (cost=0.00..4360.72 rows=730 width=69) (actual time=0.135..65.767 rows=273 loops=1)
Filter: ((number)::text ~~ '18000%'::text)
Rows Removed by Filter: 145825
Planning time: 0.704 ms
Execution time: 65.930 ms
CREATE INDEX idx_faults_uname_varchar_pattern ON user_data ((number::text) varchar_pattern_ops)
EXPLAIN ANALYZE select * from user_data where number::text like '18000%'
Bitmap Heap Scan on user_data (cost=19.90..1405.77 rows=730 width=69) (actual time=0.151..0.351 rows=273 loops=1)
Filter: ((number)::text ~~ '18000%'::text)
Heap Blocks: exact=4
-> Bitmap Index Scan on idx_faults_uname_varchar_pattern (cost=0.00..19.72 rows=730 width=0) (actual time=0.120..0.120 rows=273 lo
Index Cond: (((number)::text ~>=~ '18000'::text) AND ((number)::text ~<~ '18001'::text))
Planning time: 0.910 ms
Execution time: 0.414 ms
Kişisel fonksiyonlarınızı da kullanabilirsiniz.
Tek şartımız var :)
Oluşturduğunuz fonksiyon Immutable olmalı!
CREATE FUNCTION special_function(num int) RETURNS text AS $$
BEGIN
RETURN upper(num::text) ;
END
$$ LANGUAGE 'plpgsql' IMMUTABLE;
CREATE INDEX idx_special_func on user_data (special_function(number))
EXPLAIN ANALYZE select * from user_data where special_function(number) = '18000'
Bitmap Heap Scan on user_data (cost=18.08..1582.79 rows=730 width=69) (actual time=0.097..0.097 rows=0 loops=1)
Recheck Cond: (special_function(number) = '18000'::text)
-> Bitmap Index Scan on idx_special_func (cost=0.00..17.90 rows=730 width=0) (actual time=0.090..0.090 rows=0 loops=1)
Index Cond: (special_function(number) = '18000'::text)
Planning time: 0.197 ms
Execution time: 0.256 ms
EXPLAIN ANALYZE select email from user_data where lower(email) > 'user18' and date_part('month'::text, date) = '1' and number=2
Seq Scan on user_data (cost=0.00..5091.20 rows=1 width=24) (actual time=34.569..34.569 rows=0 loops=1)
Filter: ((number = 2) AND (lower(email) > 'user18'::text) AND (date_part('month'::text, date) = '1'::double
precision))
Rows Removed by Filter: 146098
Planning time: 0.189 ms
Execution time: 34.608 ms
CREATE INDEX idx_multiple_column on user_data (lower(email), extract(month from date), number)
Index Scan using idx_multiple_column on user_data (cost=0.42..2021.17 rows=1 width=24) (actual time=149.422..149.422 rows=0 loops
Index Cond: ((lower(email) > 'user18'::text) AND (date_part('month'::text, date) = '1'::double precision) AND (number = 2))
Planning time: 0.522 ms
Execution time: 149.454 ms
EXPLAIN ANALYZE select email from user_data where lower(email) > 'user18' and extract(month from date) = 1
Seq Scan on user_data (cost=0.00..4725.96 rows=243 width=24) (actual time=0.028..259.265 rows=12401 loops=1)
Filter: ((lower(email) > 'user18'::text) AND (date_part('month'::text, date) = '1'::double precision))
Rows Removed by Filter: 133697
Planning time: 0.063 ms
Execution time: 259.923 ms
CREATE INDEX idx_multiple_column on user_data (lower(email), extract(month from date))
EXPLAIN ANALYZE select email from user_data where lower(email) > 'user18' and extract(month from date) = 1
Bitmap Heap Scan on user_data (cost=1675.47..2349.16 rows=243 width=24) (actual time=127.902..130.773 rows=12401 loops=1)
Recheck Cond: ((lower(email) > 'user18'::text) AND (date_part('month'::text, date) = '1'::double precision))
Heap Blocks: exact=544
-> Bitmap Index Scan on idx_multiple_column (cost=0.00..1675.41 rows=243 width=0) (actual time=127.811..127.811 rows=12401 loops=1)
Index Cond: ((lower(email) > 'user18'::text) AND (date_part('month'::text, date) = '1'::double precision))
Planning time: 0.395 ms
Execution time: 131.268 ms
create index idx_float_price on booking ((data ->> ‘amount'))
select created_at from booking where data ->> 'amount'> '100';
TEŞEKKÜRLER

Weitere ähnliche Inhalte

Was ist angesagt? (7)

3 pandasadvanced
3 pandasadvanced3 pandasadvanced
3 pandasadvanced
 
The Ring programming language version 1.5.3 book - Part 23 of 184
The Ring programming language version 1.5.3 book - Part 23 of 184The Ring programming language version 1.5.3 book - Part 23 of 184
The Ring programming language version 1.5.3 book - Part 23 of 184
 
2D arrays
2D arrays2D arrays
2D arrays
 
Basic operations by novi reandy sasmita
Basic operations by novi reandy sasmitaBasic operations by novi reandy sasmita
Basic operations by novi reandy sasmita
 
Pandas pythonfordatascience
Pandas pythonfordatasciencePandas pythonfordatascience
Pandas pythonfordatascience
 
Pymongo for the Clueless
Pymongo for the CluelessPymongo for the Clueless
Pymongo for the Clueless
 
Date and time functions in mysql
Date and time functions in mysqlDate and time functions in mysql
Date and time functions in mysql
 

Ähnlich wie Postgresql İndex on Expression

Ähnlich wie Postgresql İndex on Expression (20)

Dive into EXPLAIN - PostgreSql
Dive into EXPLAIN  - PostgreSqlDive into EXPLAIN  - PostgreSql
Dive into EXPLAIN - PostgreSql
 
Powering Heap With PostgreSQL And CitusDB (PGConf Silicon Valley 2015)
Powering Heap With PostgreSQL And CitusDB (PGConf Silicon Valley 2015)Powering Heap With PostgreSQL And CitusDB (PGConf Silicon Valley 2015)
Powering Heap With PostgreSQL And CitusDB (PGConf Silicon Valley 2015)
 
PyCon SG x Jublia - Building a simple-to-use Database Management tool
PyCon SG x Jublia - Building a simple-to-use Database Management toolPyCon SG x Jublia - Building a simple-to-use Database Management tool
PyCon SG x Jublia - Building a simple-to-use Database Management tool
 
Mignesh Birdi Assignment3.pdf
Mignesh Birdi Assignment3.pdfMignesh Birdi Assignment3.pdf
Mignesh Birdi Assignment3.pdf
 
Leip103
Leip103Leip103
Leip103
 
Interactive financial analytics with vix(cboe)
Interactive financial analytics with vix(cboe)Interactive financial analytics with vix(cboe)
Interactive financial analytics with vix(cboe)
 
27. mathematical, date and time functions in VB Script
27. mathematical, date and time  functions in VB Script27. mathematical, date and time  functions in VB Script
27. mathematical, date and time functions in VB Script
 
R Programming Intro
R Programming IntroR Programming Intro
R Programming Intro
 
Time Series Analysis:Basic Stochastic Signal Recovery
Time Series Analysis:Basic Stochastic Signal RecoveryTime Series Analysis:Basic Stochastic Signal Recovery
Time Series Analysis:Basic Stochastic Signal Recovery
 
SQL: Query optimization in practice
SQL: Query optimization in practiceSQL: Query optimization in practice
SQL: Query optimization in practice
 
Introduction to python programming 1
Introduction to python programming   1Introduction to python programming   1
Introduction to python programming 1
 
Effective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPyEffective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPy
 
Using PostgreSQL statistics to optimize performance
Using PostgreSQL statistics to optimize performance Using PostgreSQL statistics to optimize performance
Using PostgreSQL statistics to optimize performance
 
Chapter 1 Basic Concepts
Chapter 1 Basic ConceptsChapter 1 Basic Concepts
Chapter 1 Basic Concepts
 
On Beyond (PostgreSQL) Data Types
On Beyond (PostgreSQL) Data TypesOn Beyond (PostgreSQL) Data Types
On Beyond (PostgreSQL) Data Types
 
Databases with SQLite3.pdf
Databases with SQLite3.pdfDatabases with SQLite3.pdf
Databases with SQLite3.pdf
 
OOP program questions with answers
OOP program questions with answersOOP program questions with answers
OOP program questions with answers
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings
 
2D array
2D array2D array
2D array
 
Chapter 16-spreadsheet1 questions and answer
Chapter 16-spreadsheet1  questions and answerChapter 16-spreadsheet1  questions and answer
Chapter 16-spreadsheet1 questions and answer
 

Kürzlich hochgeladen

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Kürzlich hochgeladen (20)

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 

Postgresql İndex on Expression

  • 1. Mesut ÖNCEL Software Developer mstoncel @mesutoncel mesutoncel mesutoncel91@gmail.com @mesutoncel
  • 4. Expression Index CREATE INDEX idx_name on table_name (expression)
  • 5. CREATE TABLE user_data AS SELECT d as date, 'user_' || replace((d :: date) :: text, '-', '') ||'@gmail.com' email, md5(d :: text) as padding, replace((d :: date) :: text, '-', '') :: int as number FROM generate_series(timestamp '1800-01-01', timestamp '2200-01-01', interval '1 day') s (d); date email pading number 1800-01-01 00:00:00.000000 user_18000101@gmail.com 18077793d1afc397046f46adfaeab411 18000101 1800-01-02 00:00:00.000000 user_18000102@gmail.com 14368f03d495281d3a3d33e02c1bf80c 18000102 1800-01-03 00:00:00.000000 user_18000103@gmail.com dcc6b0efdbacbb4540671a50a33744d2 18000103 1800-01-04 00:00:00.000000 user_18000104@gmail.com 6999a16531d1e33f244cc894613a0c8d 18000104 1800-01-05 00:00:00.000000 user_18000105@gmail.com 8685fb2051aa8cd05db09a150fb74095 18000105 1800-01-06 00:00:00.000000 user_18000106@gmail.com 02b1e445353227c019aa6ef8c027c744 18000106 1800-01-07 00:00:00.000000 user_18000107@gmail.com 3c898ba68d6249a819257fa0799b0bac 18000107 1800-01-08 00:00:00.000000 user_18000108@gmail.com 9322fd00eadfff94e90f582dd0ed12d8 18000108 1800-01-09 00:00:00.000000 user_18000109@gmail.com 830787e882375bdb0a5b526b90d998fa 18000109
  • 6. EXPLAIN ANALYZE select * from user_data where upper(email) ='USER' Seq Scan on user_data (cost=0.00..3995.47 rows=730 width=65) (actual time=96.941..96.941 rows=0 loops=1) Filter: (upper(email) = 'USER'::text) Rows Removed by Filter: 146098 Planning time: 0.248 ms Execution time: 96.970 ms
  • 7. CREATE INDEX idx_user_email on user_data (upper(email)) Bitmap Heap Scan on user_data (cost=22.08..1406.12 rows=730 width=65) (actual time=0.062..0.062 rows=0 loops=1) Recheck Cond: (upper(email) = 'USER'::text) -> Bitmap Index Scan on idx_user_email (actual time=0.059..0.059 rows=0 loops=1) Index Cond: (upper(email) = ‘USER'::text) Planning time: 1.172 ms Execution time: 0.097 ms EXPLAIN ANALYZE select * from user_data where upper(email) ='USER'
  • 8. EXPLAIN ANALYZE select * from user_data order by (email || padding) desc Sort (cost=24153.43..24518.68 rows=146098 width=101) (actual time=3486.804..4286.983 rows=146098 loops=1) Sort Key: ((email || padding)) DESC Sort Method: external merge Disk: 19616kB -> Seq Scan on user_data (cost=0.00..3630.22 rows=146098 width=101) (actual time=0.018..66.519 rows=146098 loops=1) Planning time: 0.160 ms Execution time: 4313.415 ms
  • 9. create index idx_col_text on user_data ((email || padding)) EXPLAIN ANALYZE select * from user_data order by (email || padding) desc Index Scan Backward using idx_col_text on user_data (cost=0.42..15313.14 rows=146098 width=101) (a Planning time: 0.218 ms Execution time: 90.887 ms
  • 10. explain analyze select * from user_data where number::text like '18000%' Seq Scan on user_data (cost=0.00..4360.72 rows=730 width=69) (actual time=0.015..69.488 rows=273 loops=1) Filter: ((number)::text ~~ '18000%'::text) Rows Removed by Filter: 145825 Planning time: 0.144 ms Execution time: 69.519 ms explain analyze select * from user_data where number::text like '18000%' create index idx_user_data_b_tree on user_data ((number::text)) Seq Scan on user_data (cost=0.00..4360.72 rows=730 width=69) (actual time=0.135..65.767 rows=273 loops=1) Filter: ((number)::text ~~ '18000%'::text) Rows Removed by Filter: 145825 Planning time: 0.704 ms Execution time: 65.930 ms
  • 11. CREATE INDEX idx_faults_uname_varchar_pattern ON user_data ((number::text) varchar_pattern_ops) EXPLAIN ANALYZE select * from user_data where number::text like '18000%' Bitmap Heap Scan on user_data (cost=19.90..1405.77 rows=730 width=69) (actual time=0.151..0.351 rows=273 loops=1) Filter: ((number)::text ~~ '18000%'::text) Heap Blocks: exact=4 -> Bitmap Index Scan on idx_faults_uname_varchar_pattern (cost=0.00..19.72 rows=730 width=0) (actual time=0.120..0.120 rows=273 lo Index Cond: (((number)::text ~>=~ '18000'::text) AND ((number)::text ~<~ '18001'::text)) Planning time: 0.910 ms Execution time: 0.414 ms
  • 12. Kişisel fonksiyonlarınızı da kullanabilirsiniz. Tek şartımız var :) Oluşturduğunuz fonksiyon Immutable olmalı! CREATE FUNCTION special_function(num int) RETURNS text AS $$ BEGIN RETURN upper(num::text) ; END $$ LANGUAGE 'plpgsql' IMMUTABLE;
  • 13. CREATE INDEX idx_special_func on user_data (special_function(number)) EXPLAIN ANALYZE select * from user_data where special_function(number) = '18000' Bitmap Heap Scan on user_data (cost=18.08..1582.79 rows=730 width=69) (actual time=0.097..0.097 rows=0 loops=1) Recheck Cond: (special_function(number) = '18000'::text) -> Bitmap Index Scan on idx_special_func (cost=0.00..17.90 rows=730 width=0) (actual time=0.090..0.090 rows=0 loops=1) Index Cond: (special_function(number) = '18000'::text) Planning time: 0.197 ms Execution time: 0.256 ms
  • 14. EXPLAIN ANALYZE select email from user_data where lower(email) > 'user18' and date_part('month'::text, date) = '1' and number=2 Seq Scan on user_data (cost=0.00..5091.20 rows=1 width=24) (actual time=34.569..34.569 rows=0 loops=1) Filter: ((number = 2) AND (lower(email) > 'user18'::text) AND (date_part('month'::text, date) = '1'::double precision)) Rows Removed by Filter: 146098 Planning time: 0.189 ms Execution time: 34.608 ms
  • 15. CREATE INDEX idx_multiple_column on user_data (lower(email), extract(month from date), number) Index Scan using idx_multiple_column on user_data (cost=0.42..2021.17 rows=1 width=24) (actual time=149.422..149.422 rows=0 loops Index Cond: ((lower(email) > 'user18'::text) AND (date_part('month'::text, date) = '1'::double precision) AND (number = 2)) Planning time: 0.522 ms Execution time: 149.454 ms
  • 16. EXPLAIN ANALYZE select email from user_data where lower(email) > 'user18' and extract(month from date) = 1 Seq Scan on user_data (cost=0.00..4725.96 rows=243 width=24) (actual time=0.028..259.265 rows=12401 loops=1) Filter: ((lower(email) > 'user18'::text) AND (date_part('month'::text, date) = '1'::double precision)) Rows Removed by Filter: 133697 Planning time: 0.063 ms Execution time: 259.923 ms
  • 17. CREATE INDEX idx_multiple_column on user_data (lower(email), extract(month from date)) EXPLAIN ANALYZE select email from user_data where lower(email) > 'user18' and extract(month from date) = 1 Bitmap Heap Scan on user_data (cost=1675.47..2349.16 rows=243 width=24) (actual time=127.902..130.773 rows=12401 loops=1) Recheck Cond: ((lower(email) > 'user18'::text) AND (date_part('month'::text, date) = '1'::double precision)) Heap Blocks: exact=544 -> Bitmap Index Scan on idx_multiple_column (cost=0.00..1675.41 rows=243 width=0) (actual time=127.811..127.811 rows=12401 loops=1) Index Cond: ((lower(email) > 'user18'::text) AND (date_part('month'::text, date) = '1'::double precision)) Planning time: 0.395 ms Execution time: 131.268 ms
  • 18. create index idx_float_price on booking ((data ->> ‘amount')) select created_at from booking where data ->> 'amount'> '100';