SlideShare a Scribd company logo
1 of 18
Download to read offline
© 2013 EDB All rights reserved. 1
I know greater-than-or-equal-to when I see it!
Noah Misch | 2014-05-22
>= <>&&
<@
© 2014 EDB All rights reserved. 2
■ Index access methods (pg_am)
− Type-independent; specific to certain index layout
− btree, hash, gist, gin, spgist
■ Operator classes (pg_opclass)
− Specific to a data type + index access method
− Tightly related: operator families (pg_opfamily)
− int4_ops, text_ops
Layers of Index Support
© 2014 EDB All rights reserved. 3
■ In general: ties a data type to an access method
■ The case of btree: comparison function and operators
What is an operator class?
CREATE TABLE t (c date PRIMARY KEY);
INSERT INTO t VALUES ('2014-01-01');
INSERT INTO t VALUES ('2015-01-01');
...
-- <(date,date) operator
SELECT * FROM t WHERE c < current_date;
© 2014 EDB All rights reserved. 4
■ Extends operator support to multiple data types
■ Relevant for btree and hash only
What is an operator family?
CREATE TABLE t (c date PRIMARY KEY);
INSERT INTO t VALUES ('2014-01-01');
INSERT INTO t VALUES ('2015-01-01');
...
-- <(date,timestamptz) operator
SELECT * FROM t WHERE c < now();
© 2014 EDB All rights reserved. 5
■ FUNCTION entries maintain the index
■ List of OPERATOR qualified to exploit the index
■ “equal-sign operator” vs. “equality operator”
btree int4_ops walk-through
CREATE OPERATOR FAMILY integer_ops USING btree;
CREATE OPERATOR CLASS int4_ops
DEFAULT FOR TYPE integer
USING btree FAMILY integer_ops AS
FUNCTION 1 btint4cmp(integer, integer),
OPERATOR 1 <,
OPERATOR 2 <=,
OPERATOR 3 =,
OPERATOR 4 >=,
OPERATOR 5 >;
© 2014 EDB All rights reserved. 6
System Catalog Representation
pg_am
btree
pg_opclass
int4_ops
pg_opfamily
integer_ops
pg_opclass
int2_ops
pg_amproc
btint4cmp
pg_amproc
btint24cmp
pg_amproc
btint2cmp
pg_amop
<(int4,int4)
pg_amop
<(int2,int4)
pg_amop
<(int2,int2)
© 2014 EDB All rights reserved. 7
■ btree: other sort orders
− text_pattern_ops
■ hash: not done in practice
■ gin, gist, spgist:
fruitful opportunities
Multiple Operator Classes
© 2014 EDB All rights reserved. 8
ORDER BY
-- uses btree text_ops
ORDER BY textcol;
-- uses btree text_pattern_ops
ORDER BY textcol USING ~<~;
-- can use e.g. gist_trgm_ops
ORDER BY textcol <-> 'search condition';
© 2014 EDB All rights reserved. 9
■ UNION
■ GROUP BY, DISTINCT
■ array, composite type comparisons
■ Choice of default equality semantics is important
Equality
[local] test=# SELECT DISTINCT x
FROM unnest(array[1.00, 1.1, 1.0]) t(x);
x
──────
1.1
1.00
(2 rows)
© 2014 EDB All rights reserved. 10
■ Operator names like “=” and “<” are not special ...
■ … excepting CASE, IN, IS DISTINCT FROM, etc
Equality Surprises
[local] test=# SELECT DISTINCT x
FROM unnest(array['(1,1),(0,0)',
'(2,2),(1,1)']::box[]) t(x);
ERROR: could not identify an equality
operator for type box
[local] test=# SELECT '(1,1),(0,0)'::box IN
('(2,2),(1,1)'::box);
?column?
──────────
t
© 2014 EDB All rights reserved. 11
Merge Join
[local] test=# SET enable_hashjoin = off;
SET
[local] test=# EXPLAIN (costs off)
SELECT opfmethod, opfname, array_agg(amopopr)
FROM pg_amop ao JOIN pg_opfamily f
ON amopfamily = f.oid GROUP BY 1,2;
QUERY PLAN
─────────────────────────────────────────────
HashAggregate
Group Key: f.opfmethod, f.opfname
-> Merge Join
Merge Cond: (f.oid = ao.amopfamily)
-> Sort
Sort Key: f.oid
-> Seq Scan on pg_opfamily f
-> Sort
Sort Key: ao.amopfamily
-> Seq Scan on pg_amop ao
© 2014 EDB All rights reserved. 12
Hash Join
[local] test=# EXPLAIN (costs off)
SELECT opfmethod, opfname, array_agg(amopopr)
FROM pg_amop ao JOIN pg_opfamily f
ON amopfamily = f.oid GROUP BY 1,2;
QUERY PLAN
─────────────────────────────────────────────
HashAggregate
Group Key: f.opfmethod, f.opfname
-> Hash Join
Hash Cond: (ao.amopfamily = f.oid)
-> Seq Scan on pg_amop ao
-> Hash
-> Seq Scan on pg_opfamily f
© 2014 EDB All rights reserved. 13
■ Don't hard-code “=”
■ Which equality semantics?
− btree/hash default equality
− exact match (output comparison; record_image_ops)
■ Do look up equality by operator class
− backend: TYPECACHE_EQ_OPR
− frontend: copy its algorithm
■ Not all types have these operations
Writing Generic Data Type Consumers
© 2014 EDB All rights reserved. 14
■ Choice of default equality semantics is important
− Option to omit them entirely (xml, json, box)
■ Try to include a default btree operator class
■ Default hash operator class is then easy
■ Other access methods are situation-specific
− gin for container-like types
− gist often starts with the search strategy, not the type
Implementing Data Types
© 2014 EDB All rights reserved. 15
Questions?
© 2014 EDB All rights reserved. 16
■ http://www.postgresql.org/docs/current/static/xindex.html
■ contrib/btree_gist, contrib/btree_gin
■ Other built-in and contrib operator classes
■ ATAddForeignKeyConstraint()
Further Reading
© 2014 EDB All rights reserved. 17
hash int4_ops
CREATE OPERATOR CLASS int4_ops
DEFAULT FOR TYPE integer
USING hash FAMILY integer_ops AS
FUNCTION 1 hashint4(integer),
OPERATOR 1 =;
© 2014 EDB All rights reserved. 18
Array Element Searches: gin _int4_ops
CREATE OPERATOR CLASS _int4_ops
DEFAULT FOR TYPE integer[]
USING gin FAMILY array_ops AS
STORAGE integer,
FUNCTION 1 btint4cmp(integer,integer),
FUNCTION 2 ginarrayextract(...),
FUNCTION 3 ginqueryarrayextract(...),
FUNCTION 4 ginarrayconsistent(...),
OPERATOR 1 &&(anyarray,anyarray),
OPERATOR 2 @>(anyarray,anyarray),
OPERATOR 3 <@(anyarray,anyarray),
OPERATOR 4 =(anyarray,anyarray);

More Related Content

Similar to I know greater-than-or-equal-to when I see it! (PGCon 2014)

Perl 6 command line scripting
Perl 6 command line scriptingPerl 6 command line scripting
Perl 6 command line scriptingSimon Proctor
 
Server Independent Programming
Server Independent ProgrammingServer Independent Programming
Server Independent ProgrammingZendCon
 
Reading The Source Code of Presto
Reading The Source Code of PrestoReading The Source Code of Presto
Reading The Source Code of PrestoTaro L. Saito
 
Oracle Release 12 E-Business Suite Patching Best Practices
Oracle Release 12 E-Business Suite Patching Best PracticesOracle Release 12 E-Business Suite Patching Best Practices
Oracle Release 12 E-Business Suite Patching Best PracticesScott Jenner
 
2010 07-28-testing-zf-apps
2010 07-28-testing-zf-apps2010 07-28-testing-zf-apps
2010 07-28-testing-zf-appsVenkata Ramana
 
Getting started with php
Getting started with phpGetting started with php
Getting started with phpJoe Ferguson
 
download presentation
download presentationdownload presentation
download presentationwebhostingguy
 
Postgres.foreign.data.wrappers.2015
Postgres.foreign.data.wrappers.2015Postgres.foreign.data.wrappers.2015
Postgres.foreign.data.wrappers.2015EDB
 
power point presentation on pig -hadoop framework
power point presentation on pig -hadoop frameworkpower point presentation on pig -hadoop framework
power point presentation on pig -hadoop frameworkbhargavi804095
 
Gruter_TECHDAY_2014_03_ApacheTajo (in Korean)
Gruter_TECHDAY_2014_03_ApacheTajo (in Korean)Gruter_TECHDAY_2014_03_ApacheTajo (in Korean)
Gruter_TECHDAY_2014_03_ApacheTajo (in Korean)Gruter
 
Na pomezi php a vue.js
Na pomezi php a vue.jsNa pomezi php a vue.js
Na pomezi php a vue.jsPeckaDesign.cz
 
メタプログラミングRuby輪読会 1-4章(復習), 5.1~5.3章
メタプログラミングRuby輪読会 1-4章(復習), 5.1~5.3章メタプログラミングRuby輪読会 1-4章(復習), 5.1~5.3章
メタプログラミングRuby輪読会 1-4章(復習), 5.1~5.3章Jumpei Yokota
 
Week05
Week05Week05
Week05hccit
 
Как мы сделали PHP 7 в два раза быстрее PHP 5 / Дмитрий Стогов (Zend Technolo...
Как мы сделали PHP 7 в два раза быстрее PHP 5 / Дмитрий Стогов (Zend Technolo...Как мы сделали PHP 7 в два раза быстрее PHP 5 / Дмитрий Стогов (Zend Technolo...
Как мы сделали PHP 7 в два раза быстрее PHP 5 / Дмитрий Стогов (Zend Technolo...Ontico
 
Bug Bounty Hunter Methodology - Nullcon 2016
Bug Bounty Hunter Methodology - Nullcon 2016Bug Bounty Hunter Methodology - Nullcon 2016
Bug Bounty Hunter Methodology - Nullcon 2016bugcrowd
 
2021.laravelconf.tw.slides2
2021.laravelconf.tw.slides22021.laravelconf.tw.slides2
2021.laravelconf.tw.slides2LiviaLiaoFontech
 

Similar to I know greater-than-or-equal-to when I see it! (PGCon 2014) (20)

Perl 6 command line scripting
Perl 6 command line scriptingPerl 6 command line scripting
Perl 6 command line scripting
 
Server Independent Programming
Server Independent ProgrammingServer Independent Programming
Server Independent Programming
 
Reading The Source Code of Presto
Reading The Source Code of PrestoReading The Source Code of Presto
Reading The Source Code of Presto
 
Oracle Release 12 E-Business Suite Patching Best Practices
Oracle Release 12 E-Business Suite Patching Best PracticesOracle Release 12 E-Business Suite Patching Best Practices
Oracle Release 12 E-Business Suite Patching Best Practices
 
Php training in chandigarh
Php  training in chandigarhPhp  training in chandigarh
Php training in chandigarh
 
2010 07-28-testing-zf-apps
2010 07-28-testing-zf-apps2010 07-28-testing-zf-apps
2010 07-28-testing-zf-apps
 
Getting started with php
Getting started with phpGetting started with php
Getting started with php
 
Zend Framework 2 Patterns
Zend Framework 2 PatternsZend Framework 2 Patterns
Zend Framework 2 Patterns
 
download presentation
download presentationdownload presentation
download presentation
 
Postgres.foreign.data.wrappers.2015
Postgres.foreign.data.wrappers.2015Postgres.foreign.data.wrappers.2015
Postgres.foreign.data.wrappers.2015
 
power point presentation on pig -hadoop framework
power point presentation on pig -hadoop frameworkpower point presentation on pig -hadoop framework
power point presentation on pig -hadoop framework
 
Gruter_TECHDAY_2014_03_ApacheTajo (in Korean)
Gruter_TECHDAY_2014_03_ApacheTajo (in Korean)Gruter_TECHDAY_2014_03_ApacheTajo (in Korean)
Gruter_TECHDAY_2014_03_ApacheTajo (in Korean)
 
Na pomezi php a vue.js
Na pomezi php a vue.jsNa pomezi php a vue.js
Na pomezi php a vue.js
 
8.4 Upcoming Features
8.4 Upcoming Features 8.4 Upcoming Features
8.4 Upcoming Features
 
メタプログラミングRuby輪読会 1-4章(復習), 5.1~5.3章
メタプログラミングRuby輪読会 1-4章(復習), 5.1~5.3章メタプログラミングRuby輪読会 1-4章(復習), 5.1~5.3章
メタプログラミングRuby輪読会 1-4章(復習), 5.1~5.3章
 
Week05
Week05Week05
Week05
 
Как мы сделали PHP 7 в два раза быстрее PHP 5 / Дмитрий Стогов (Zend Technolo...
Как мы сделали PHP 7 в два раза быстрее PHP 5 / Дмитрий Стогов (Zend Technolo...Как мы сделали PHP 7 в два раза быстрее PHP 5 / Дмитрий Стогов (Zend Technolo...
Как мы сделали PHP 7 в два раза быстрее PHP 5 / Дмитрий Стогов (Zend Technolo...
 
Bug Bounty Hunter Methodology - Nullcon 2016
Bug Bounty Hunter Methodology - Nullcon 2016Bug Bounty Hunter Methodology - Nullcon 2016
Bug Bounty Hunter Methodology - Nullcon 2016
 
PigHive.pptx
PigHive.pptxPigHive.pptx
PigHive.pptx
 
2021.laravelconf.tw.slides2
2021.laravelconf.tw.slides22021.laravelconf.tw.slides2
2021.laravelconf.tw.slides2
 

More from EDB

Cloud Migration Paths: Kubernetes, IaaS, or DBaaS
Cloud Migration Paths: Kubernetes, IaaS, or DBaaSCloud Migration Paths: Kubernetes, IaaS, or DBaaS
Cloud Migration Paths: Kubernetes, IaaS, or DBaaSEDB
 
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr UnternehmenDie 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr UnternehmenEDB
 
Migre sus bases de datos Oracle a la nube
Migre sus bases de datos Oracle a la nube Migre sus bases de datos Oracle a la nube
Migre sus bases de datos Oracle a la nube EDB
 
EFM Office Hours - APJ - July 29, 2021
EFM Office Hours - APJ - July 29, 2021EFM Office Hours - APJ - July 29, 2021
EFM Office Hours - APJ - July 29, 2021EDB
 
Benchmarking Cloud Native PostgreSQL
Benchmarking Cloud Native PostgreSQLBenchmarking Cloud Native PostgreSQL
Benchmarking Cloud Native PostgreSQLEDB
 
Las Variaciones de la Replicación de PostgreSQL
Las Variaciones de la Replicación de PostgreSQLLas Variaciones de la Replicación de PostgreSQL
Las Variaciones de la Replicación de PostgreSQLEDB
 
NoSQL and Spatial Database Capabilities using PostgreSQL
NoSQL and Spatial Database Capabilities using PostgreSQLNoSQL and Spatial Database Capabilities using PostgreSQL
NoSQL and Spatial Database Capabilities using PostgreSQLEDB
 
Is There Anything PgBouncer Can’t Do?
Is There Anything PgBouncer Can’t Do?Is There Anything PgBouncer Can’t Do?
Is There Anything PgBouncer Can’t Do?EDB
 
Data Analysis with TensorFlow in PostgreSQL
Data Analysis with TensorFlow in PostgreSQLData Analysis with TensorFlow in PostgreSQL
Data Analysis with TensorFlow in PostgreSQLEDB
 
Practical Partitioning in Production with Postgres
Practical Partitioning in Production with PostgresPractical Partitioning in Production with Postgres
Practical Partitioning in Production with PostgresEDB
 
A Deeper Dive into EXPLAIN
A Deeper Dive into EXPLAINA Deeper Dive into EXPLAIN
A Deeper Dive into EXPLAINEDB
 
IOT with PostgreSQL
IOT with PostgreSQLIOT with PostgreSQL
IOT with PostgreSQLEDB
 
A Journey from Oracle to PostgreSQL
A Journey from Oracle to PostgreSQLA Journey from Oracle to PostgreSQL
A Journey from Oracle to PostgreSQLEDB
 
Psql is awesome!
Psql is awesome!Psql is awesome!
Psql is awesome!EDB
 
EDB 13 - New Enhancements for Security and Usability - APJ
EDB 13 - New Enhancements for Security and Usability - APJEDB 13 - New Enhancements for Security and Usability - APJ
EDB 13 - New Enhancements for Security and Usability - APJEDB
 
Comment sauvegarder correctement vos données
Comment sauvegarder correctement vos donnéesComment sauvegarder correctement vos données
Comment sauvegarder correctement vos donnéesEDB
 
Cloud Native PostgreSQL - Italiano
Cloud Native PostgreSQL - ItalianoCloud Native PostgreSQL - Italiano
Cloud Native PostgreSQL - ItalianoEDB
 
New enhancements for security and usability in EDB 13
New enhancements for security and usability in EDB 13New enhancements for security and usability in EDB 13
New enhancements for security and usability in EDB 13EDB
 
Best Practices in Security with PostgreSQL
Best Practices in Security with PostgreSQLBest Practices in Security with PostgreSQL
Best Practices in Security with PostgreSQLEDB
 
Cloud Native PostgreSQL - APJ
Cloud Native PostgreSQL - APJCloud Native PostgreSQL - APJ
Cloud Native PostgreSQL - APJEDB
 

More from EDB (20)

Cloud Migration Paths: Kubernetes, IaaS, or DBaaS
Cloud Migration Paths: Kubernetes, IaaS, or DBaaSCloud Migration Paths: Kubernetes, IaaS, or DBaaS
Cloud Migration Paths: Kubernetes, IaaS, or DBaaS
 
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr UnternehmenDie 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
 
Migre sus bases de datos Oracle a la nube
Migre sus bases de datos Oracle a la nube Migre sus bases de datos Oracle a la nube
Migre sus bases de datos Oracle a la nube
 
EFM Office Hours - APJ - July 29, 2021
EFM Office Hours - APJ - July 29, 2021EFM Office Hours - APJ - July 29, 2021
EFM Office Hours - APJ - July 29, 2021
 
Benchmarking Cloud Native PostgreSQL
Benchmarking Cloud Native PostgreSQLBenchmarking Cloud Native PostgreSQL
Benchmarking Cloud Native PostgreSQL
 
Las Variaciones de la Replicación de PostgreSQL
Las Variaciones de la Replicación de PostgreSQLLas Variaciones de la Replicación de PostgreSQL
Las Variaciones de la Replicación de PostgreSQL
 
NoSQL and Spatial Database Capabilities using PostgreSQL
NoSQL and Spatial Database Capabilities using PostgreSQLNoSQL and Spatial Database Capabilities using PostgreSQL
NoSQL and Spatial Database Capabilities using PostgreSQL
 
Is There Anything PgBouncer Can’t Do?
Is There Anything PgBouncer Can’t Do?Is There Anything PgBouncer Can’t Do?
Is There Anything PgBouncer Can’t Do?
 
Data Analysis with TensorFlow in PostgreSQL
Data Analysis with TensorFlow in PostgreSQLData Analysis with TensorFlow in PostgreSQL
Data Analysis with TensorFlow in PostgreSQL
 
Practical Partitioning in Production with Postgres
Practical Partitioning in Production with PostgresPractical Partitioning in Production with Postgres
Practical Partitioning in Production with Postgres
 
A Deeper Dive into EXPLAIN
A Deeper Dive into EXPLAINA Deeper Dive into EXPLAIN
A Deeper Dive into EXPLAIN
 
IOT with PostgreSQL
IOT with PostgreSQLIOT with PostgreSQL
IOT with PostgreSQL
 
A Journey from Oracle to PostgreSQL
A Journey from Oracle to PostgreSQLA Journey from Oracle to PostgreSQL
A Journey from Oracle to PostgreSQL
 
Psql is awesome!
Psql is awesome!Psql is awesome!
Psql is awesome!
 
EDB 13 - New Enhancements for Security and Usability - APJ
EDB 13 - New Enhancements for Security and Usability - APJEDB 13 - New Enhancements for Security and Usability - APJ
EDB 13 - New Enhancements for Security and Usability - APJ
 
Comment sauvegarder correctement vos données
Comment sauvegarder correctement vos donnéesComment sauvegarder correctement vos données
Comment sauvegarder correctement vos données
 
Cloud Native PostgreSQL - Italiano
Cloud Native PostgreSQL - ItalianoCloud Native PostgreSQL - Italiano
Cloud Native PostgreSQL - Italiano
 
New enhancements for security and usability in EDB 13
New enhancements for security and usability in EDB 13New enhancements for security and usability in EDB 13
New enhancements for security and usability in EDB 13
 
Best Practices in Security with PostgreSQL
Best Practices in Security with PostgreSQLBest Practices in Security with PostgreSQL
Best Practices in Security with PostgreSQL
 
Cloud Native PostgreSQL - APJ
Cloud Native PostgreSQL - APJCloud Native PostgreSQL - APJ
Cloud Native PostgreSQL - APJ
 

Recently uploaded

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 

Recently uploaded (20)

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 

I know greater-than-or-equal-to when I see it! (PGCon 2014)

  • 1. © 2013 EDB All rights reserved. 1 I know greater-than-or-equal-to when I see it! Noah Misch | 2014-05-22 >= <>&& <@
  • 2. © 2014 EDB All rights reserved. 2 ■ Index access methods (pg_am) − Type-independent; specific to certain index layout − btree, hash, gist, gin, spgist ■ Operator classes (pg_opclass) − Specific to a data type + index access method − Tightly related: operator families (pg_opfamily) − int4_ops, text_ops Layers of Index Support
  • 3. © 2014 EDB All rights reserved. 3 ■ In general: ties a data type to an access method ■ The case of btree: comparison function and operators What is an operator class? CREATE TABLE t (c date PRIMARY KEY); INSERT INTO t VALUES ('2014-01-01'); INSERT INTO t VALUES ('2015-01-01'); ... -- <(date,date) operator SELECT * FROM t WHERE c < current_date;
  • 4. © 2014 EDB All rights reserved. 4 ■ Extends operator support to multiple data types ■ Relevant for btree and hash only What is an operator family? CREATE TABLE t (c date PRIMARY KEY); INSERT INTO t VALUES ('2014-01-01'); INSERT INTO t VALUES ('2015-01-01'); ... -- <(date,timestamptz) operator SELECT * FROM t WHERE c < now();
  • 5. © 2014 EDB All rights reserved. 5 ■ FUNCTION entries maintain the index ■ List of OPERATOR qualified to exploit the index ■ “equal-sign operator” vs. “equality operator” btree int4_ops walk-through CREATE OPERATOR FAMILY integer_ops USING btree; CREATE OPERATOR CLASS int4_ops DEFAULT FOR TYPE integer USING btree FAMILY integer_ops AS FUNCTION 1 btint4cmp(integer, integer), OPERATOR 1 <, OPERATOR 2 <=, OPERATOR 3 =, OPERATOR 4 >=, OPERATOR 5 >;
  • 6. © 2014 EDB All rights reserved. 6 System Catalog Representation pg_am btree pg_opclass int4_ops pg_opfamily integer_ops pg_opclass int2_ops pg_amproc btint4cmp pg_amproc btint24cmp pg_amproc btint2cmp pg_amop <(int4,int4) pg_amop <(int2,int4) pg_amop <(int2,int2)
  • 7. © 2014 EDB All rights reserved. 7 ■ btree: other sort orders − text_pattern_ops ■ hash: not done in practice ■ gin, gist, spgist: fruitful opportunities Multiple Operator Classes
  • 8. © 2014 EDB All rights reserved. 8 ORDER BY -- uses btree text_ops ORDER BY textcol; -- uses btree text_pattern_ops ORDER BY textcol USING ~<~; -- can use e.g. gist_trgm_ops ORDER BY textcol <-> 'search condition';
  • 9. © 2014 EDB All rights reserved. 9 ■ UNION ■ GROUP BY, DISTINCT ■ array, composite type comparisons ■ Choice of default equality semantics is important Equality [local] test=# SELECT DISTINCT x FROM unnest(array[1.00, 1.1, 1.0]) t(x); x ────── 1.1 1.00 (2 rows)
  • 10. © 2014 EDB All rights reserved. 10 ■ Operator names like “=” and “<” are not special ... ■ … excepting CASE, IN, IS DISTINCT FROM, etc Equality Surprises [local] test=# SELECT DISTINCT x FROM unnest(array['(1,1),(0,0)', '(2,2),(1,1)']::box[]) t(x); ERROR: could not identify an equality operator for type box [local] test=# SELECT '(1,1),(0,0)'::box IN ('(2,2),(1,1)'::box); ?column? ────────── t
  • 11. © 2014 EDB All rights reserved. 11 Merge Join [local] test=# SET enable_hashjoin = off; SET [local] test=# EXPLAIN (costs off) SELECT opfmethod, opfname, array_agg(amopopr) FROM pg_amop ao JOIN pg_opfamily f ON amopfamily = f.oid GROUP BY 1,2; QUERY PLAN ───────────────────────────────────────────── HashAggregate Group Key: f.opfmethod, f.opfname -> Merge Join Merge Cond: (f.oid = ao.amopfamily) -> Sort Sort Key: f.oid -> Seq Scan on pg_opfamily f -> Sort Sort Key: ao.amopfamily -> Seq Scan on pg_amop ao
  • 12. © 2014 EDB All rights reserved. 12 Hash Join [local] test=# EXPLAIN (costs off) SELECT opfmethod, opfname, array_agg(amopopr) FROM pg_amop ao JOIN pg_opfamily f ON amopfamily = f.oid GROUP BY 1,2; QUERY PLAN ───────────────────────────────────────────── HashAggregate Group Key: f.opfmethod, f.opfname -> Hash Join Hash Cond: (ao.amopfamily = f.oid) -> Seq Scan on pg_amop ao -> Hash -> Seq Scan on pg_opfamily f
  • 13. © 2014 EDB All rights reserved. 13 ■ Don't hard-code “=” ■ Which equality semantics? − btree/hash default equality − exact match (output comparison; record_image_ops) ■ Do look up equality by operator class − backend: TYPECACHE_EQ_OPR − frontend: copy its algorithm ■ Not all types have these operations Writing Generic Data Type Consumers
  • 14. © 2014 EDB All rights reserved. 14 ■ Choice of default equality semantics is important − Option to omit them entirely (xml, json, box) ■ Try to include a default btree operator class ■ Default hash operator class is then easy ■ Other access methods are situation-specific − gin for container-like types − gist often starts with the search strategy, not the type Implementing Data Types
  • 15. © 2014 EDB All rights reserved. 15 Questions?
  • 16. © 2014 EDB All rights reserved. 16 ■ http://www.postgresql.org/docs/current/static/xindex.html ■ contrib/btree_gist, contrib/btree_gin ■ Other built-in and contrib operator classes ■ ATAddForeignKeyConstraint() Further Reading
  • 17. © 2014 EDB All rights reserved. 17 hash int4_ops CREATE OPERATOR CLASS int4_ops DEFAULT FOR TYPE integer USING hash FAMILY integer_ops AS FUNCTION 1 hashint4(integer), OPERATOR 1 =;
  • 18. © 2014 EDB All rights reserved. 18 Array Element Searches: gin _int4_ops CREATE OPERATOR CLASS _int4_ops DEFAULT FOR TYPE integer[] USING gin FAMILY array_ops AS STORAGE integer, FUNCTION 1 btint4cmp(integer,integer), FUNCTION 2 ginarrayextract(...), FUNCTION 3 ginqueryarrayextract(...), FUNCTION 4 ginarrayconsistent(...), OPERATOR 1 &&(anyarray,anyarray), OPERATOR 2 @>(anyarray,anyarray), OPERATOR 3 <@(anyarray,anyarray), OPERATOR 4 =(anyarray,anyarray);