SlideShare ist ein Scribd-Unternehmen logo
1 von 24
Downloaden Sie, um offline zu lesen
PostgreSQL Extensibility




        Jeff Davis,
       Truviso, Inc.
Introduction
●   Many businesses have needs that are specific
    to the industry or to the business itself
    –   Not always met by generic tools offered by a DBMS
●   People in that business know best how to solve
    those problems
●   But those people may not be database engine
    developers
And Also...




When implementing a workaround on a running
system, you want every possible option available.
Outline
●   How to solve domain-specific problems
    –   Solutions should be as seamless as a native
        feature, not bolted on.
●   How to make those solutions perform like a
    special-purpose solution
●   How to build complete features without
    modifying the core database engine
●   Where these features fit into the PostgreSQL
    development landscape
Extensibility Overview
●   Functions – procedural code that can be written
    in a variety of languages
●   Operators – define the behavior of your type
    and allow it to be usefully indexed
●   Types – input/output
●   Index Support – define sophisticated indexing
    behavior for your data type
●   Procedural languages
Functions
●   Can be written in a variety of languages
    –   PL/pgSQL, C, Perl, Python, and more
●   Fundamental part of extensibility architecture
●   Used for
    –   Operators
    –   Type input/output functions
    –   Index support routines
    –   etc.
Operators
●   Allowable characters
    –   +-*/<>=~!@#%^&|`?
●   Can be infix, postfix, or prefix
●   Allow index searches
Types
●   Types help you represent data the way that
    makes sense to your business
●   User-defined types are given all the power of
    native types
    –   Not slower
    –   Not less flexible
    –   Not less indexable
●   Define input/output, storage, etc.
Index Access Methods
●   BTree
●   GiST
●   GIN
●   You implement your specialized indexing
    algorithm using index support functions
●   You don't need to worry about low level details
    like page splits or the transaction log (WAL)
Example: PostGIS
●   Spatial data – implements OpenGIS
    –   Collections of lines, points, polygons, etc.
●   Important queries
    –   Contains
    –   Overlaps
●   Existing data types can't represent the data
    effectively
●   BTree can't index effectively, no useful total
    order for spatial types
PostGIS: Types
●   Geometry type can hold
    –   points
    –   linestrings
    –   polygons
    –   etc.
●   A single geometry value can hold a
    combination of all of those
PostGIS: operators
●   && - overlaps
●   << - strictly left of
●   >> - strictly right of
●   ~= - is the same as
●   ~ - contains
●   @ - is contained by
PostGIS: indexes
●   Uses GiST, a sophisticated generalized index
    access method with a tree structure.
●   GiST is much more general than BTree. It can
    search for matches based on what makes
    sense for your problem, using algorithms that
    you supply via functions.
●   Still has all the safety of the write-ahead log.
Example: DBI-Link
●   Allows you to access any data source available
    via Perl's DBI
●   Remote data is seen as a table in PostgreSQL
●   How?
DBI-Link: PL/Perlu
●   PL/Perlu is the “untrusted” (i.e. not sandboxed)
    version of the perl procedural language.
●   Can execute arbitrary code, including creating
    sockets, etc.
●   And therefore, it can use Perl's DBI to access
    any data over a network.
DBI-Link: SRFs
●   DBI-Link uses Set Returning Functions, or
    SRFs
●   Function returns multiple rows to PostgreSQL
●   Is used in place of a table.
Example: PL/proxy
●   Access remote PostgreSQL data
●   Designed to be easy to retrieve data from many
    different PostgreSQL nodes
●   Supports partitioning
●   Implemented as its own language
PL/proxy: example


CREATE OR REPLACE FUNCTION
    get_user_email(i_username text)
RETURNS SETOF text AS $$
  CLUSTER 'usercluster';
  RUN ON hashtext(i_username) ;
  SELECT email FROM users
    WHERE username = i_username;
$$ LANGUAGE plproxy;
Example: Full Text Search
●   Search for matches within a document.
●   The primary query is “contains”
●   Problem: BTree unsuitable, documents do not
    have a useful total order.
●   Problem: Text type is unsuitable
    –   Lists the same word many times, doesn't eliminate
        stopwords
    –   Doesn't equate words with same root
Full Text Search: Types
●   tsquery – type suitable for representing queries
    –   to_tsquery('bears & eat')
    –   'bear' & 'eat'
●   tsvector – document representation suitable for
    indexed searches
    –   to_tsvector('Bears eat everything.')
    –   'eat':2 'bear':1 'everyth':3
Full Text Search: Indexes
●   Indexable Operator - @@
    –   Means “matches the query”
●   Index Access methods
    –   GIN – better query performance and scalability
    –   GiST – better update performance
●   GiST is such a generic index interface, it can be
    used for indexing spatial data and full text data
Full Text Search: 8.3
●   Full Text Search lived as a fully functional
    separate module, including index support, since
    2002.
●   Was very successful and useful to many people
●   Included in PostgreSQL 8.3
●   The fact that such a major feature was fully
    functional completely outside of the core
    PostgreSQL product shows the power of the
    extensible architecture.
Development Landscape
●   Variety of projects outside of PostgreSQL core
    –   http://www.pgfoundry.org
●   Advantages
    –   Separate release cycle
    –   Separate development
    –   Users can pick and choose what fits them best
        among alternative solutions
●   Disadvantages
    –   Can't extend SQL language
Conclusion
●   Extensibility allows people with knowledge in
    specific problem domains to create major
    features without dealing with database
    internals.
●   More efficient development by making
    independent projects
●   Enables businesses to solve practical problems
    quickly and cheaply, without extensive error-
    prone “glue” code.
●   Doesn't require interrupting normal operation!

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (7)

The Lumber Mill - XSLT For Your Templates
The Lumber Mill  - XSLT For Your TemplatesThe Lumber Mill  - XSLT For Your Templates
The Lumber Mill - XSLT For Your Templates
 
Xml
XmlXml
Xml
 
Xml dom
Xml domXml dom
Xml dom
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
XML
XMLXML
XML
 
Gettext i18n system - internationalization for gettext
Gettext i18n system - internationalization for gettextGettext i18n system - internationalization for gettext
Gettext i18n system - internationalization for gettext
 
Introduction to DB design
Introduction to DB designIntroduction to DB design
Introduction to DB design
 

Andere mochten auch

pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLCommand Prompt., Inc
 
Not Just UNIQUE: Generalized Index Constraints
Not Just UNIQUE: Generalized Index ConstraintsNot Just UNIQUE: Generalized Index Constraints
Not Just UNIQUE: Generalized Index ConstraintsCommand Prompt., Inc
 
Mastering PostgreSQL Administration
Mastering PostgreSQL AdministrationMastering PostgreSQL Administration
Mastering PostgreSQL AdministrationCommand Prompt., Inc
 
PostgreSQL High Availability via SLONY and PG POOL II
PostgreSQL High Availability via SLONY and PG POOL IIPostgreSQL High Availability via SLONY and PG POOL II
PostgreSQL High Availability via SLONY and PG POOL IICommand Prompt., Inc
 
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...Command Prompt., Inc
 
configuring a warm standby, the easy way
configuring a warm standby, the easy wayconfiguring a warm standby, the easy way
configuring a warm standby, the easy wayCommand Prompt., Inc
 
Replication using PostgreSQL Replicator
Replication using PostgreSQL ReplicatorReplication using PostgreSQL Replicator
Replication using PostgreSQL ReplicatorCommand Prompt., Inc
 
Implementing the Future of PostgreSQL Clustering with Tungsten
Implementing the Future of PostgreSQL Clustering with TungstenImplementing the Future of PostgreSQL Clustering with Tungsten
Implementing the Future of PostgreSQL Clustering with TungstenCommand Prompt., Inc
 
Python utilities for data presentation
Python utilities for data presentationPython utilities for data presentation
Python utilities for data presentationCommand Prompt., Inc
 
Elephant Roads: a tour of Postgres forks
Elephant Roads: a tour of Postgres forksElephant Roads: a tour of Postgres forks
Elephant Roads: a tour of Postgres forksCommand Prompt., Inc
 
Howdah - An Application using Pylons, PostgreSQL, Simpycity and Exceptable
Howdah - An Application using Pylons, PostgreSQL, Simpycity and ExceptableHowdah - An Application using Pylons, PostgreSQL, Simpycity and Exceptable
Howdah - An Application using Pylons, PostgreSQL, Simpycity and ExceptableCommand Prompt., Inc
 

Andere mochten auch (20)

pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
Not Just UNIQUE: Generalized Index Constraints
Not Just UNIQUE: Generalized Index ConstraintsNot Just UNIQUE: Generalized Index Constraints
Not Just UNIQUE: Generalized Index Constraints
 
Basic Query Tuning Primer
Basic Query Tuning PrimerBasic Query Tuning Primer
Basic Query Tuning Primer
 
Bucardo
BucardoBucardo
Bucardo
 
The PostgreSQL Query Planner
The PostgreSQL Query PlannerThe PostgreSQL Query Planner
The PostgreSQL Query Planner
 
Mastering PostgreSQL Administration
Mastering PostgreSQL AdministrationMastering PostgreSQL Administration
Mastering PostgreSQL Administration
 
PostgreSQL High Availability via SLONY and PG POOL II
PostgreSQL High Availability via SLONY and PG POOL IIPostgreSQL High Availability via SLONY and PG POOL II
PostgreSQL High Availability via SLONY and PG POOL II
 
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...
 
Pg migrator
Pg migratorPg migrator
Pg migrator
 
Go replicator
Go replicatorGo replicator
Go replicator
 
configuring a warm standby, the easy way
configuring a warm standby, the easy wayconfiguring a warm standby, the easy way
configuring a warm standby, the easy way
 
Replication using PostgreSQL Replicator
Replication using PostgreSQL ReplicatorReplication using PostgreSQL Replicator
Replication using PostgreSQL Replicator
 
Implementing the Future of PostgreSQL Clustering with Tungsten
Implementing the Future of PostgreSQL Clustering with TungstenImplementing the Future of PostgreSQL Clustering with Tungsten
Implementing the Future of PostgreSQL Clustering with Tungsten
 
Backup and-recovery2
Backup and-recovery2Backup and-recovery2
Backup and-recovery2
 
Python utilities for data presentation
Python utilities for data presentationPython utilities for data presentation
Python utilities for data presentation
 
A Practical Multi-Tenant Cluster
A Practical Multi-Tenant ClusterA Practical Multi-Tenant Cluster
A Practical Multi-Tenant Cluster
 
Temporal Data
Temporal DataTemporal Data
Temporal Data
 
Elephant Roads: a tour of Postgres forks
Elephant Roads: a tour of Postgres forksElephant Roads: a tour of Postgres forks
Elephant Roads: a tour of Postgres forks
 
Howdah - An Application using Pylons, PostgreSQL, Simpycity and Exceptable
Howdah - An Application using Pylons, PostgreSQL, Simpycity and ExceptableHowdah - An Application using Pylons, PostgreSQL, Simpycity and Exceptable
Howdah - An Application using Pylons, PostgreSQL, Simpycity and Exceptable
 
Introduction to triggers
Introduction to triggersIntroduction to triggers
Introduction to triggers
 

Ähnlich wie PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules, Performance, and More!

PostgreSQL - Object Relational Database
PostgreSQL - Object Relational DatabasePostgreSQL - Object Relational Database
PostgreSQL - Object Relational DatabaseMubashar Iqbal
 
What’s New In PostgreSQL 9.3
What’s New In PostgreSQL 9.3What’s New In PostgreSQL 9.3
What’s New In PostgreSQL 9.3Pavan Deolasee
 
Benefits of using software design patterns and when to use design pattern
Benefits of using software design patterns and when to use design patternBenefits of using software design patterns and when to use design pattern
Benefits of using software design patterns and when to use design patternBeroza Paul
 
Introduction to PostgreSQL
Introduction to PostgreSQLIntroduction to PostgreSQL
Introduction to PostgreSQLJim Mlodgenski
 
Text search with Elasticsearch on AWS
Text search with Elasticsearch on AWSText search with Elasticsearch on AWS
Text search with Elasticsearch on AWSŁukasz Przybyłek
 
A Modern Interface for Data Science on Postgres/Greenplum - Greenplum Summit ...
A Modern Interface for Data Science on Postgres/Greenplum - Greenplum Summit ...A Modern Interface for Data Science on Postgres/Greenplum - Greenplum Summit ...
A Modern Interface for Data Science on Postgres/Greenplum - Greenplum Summit ...VMware Tanzu
 
Active Data Stores at 30,000ft
Active Data Stores at 30,000ftActive Data Stores at 30,000ft
Active Data Stores at 30,000ftJeffrey Sica
 
No sql bigdata and postgresql
No sql bigdata and postgresqlNo sql bigdata and postgresql
No sql bigdata and postgresqlZaid Shabbir
 
Tutorial: Implementing your first Postgres extension | PGConf EU 2019 | Burak...
Tutorial: Implementing your first Postgres extension | PGConf EU 2019 | Burak...Tutorial: Implementing your first Postgres extension | PGConf EU 2019 | Burak...
Tutorial: Implementing your first Postgres extension | PGConf EU 2019 | Burak...Citus Data
 
Ledingkart Meetup #2: Scaling Search @Lendingkart
Ledingkart Meetup #2: Scaling Search @LendingkartLedingkart Meetup #2: Scaling Search @Lendingkart
Ledingkart Meetup #2: Scaling Search @LendingkartMukesh Singh
 
Towards More Flexible Enterprise Information Systems
Towards More Flexible Enterprise Information SystemsTowards More Flexible Enterprise Information Systems
Towards More Flexible Enterprise Information SystemsCONFENIS 2012
 
Search engines in the industry
Search engines in the industrySearch engines in the industry
Search engines in the industryTommaso Teofili
 
PostgreSQL and Redis - talk at pgcon 2013
PostgreSQL and Redis - talk at pgcon 2013PostgreSQL and Redis - talk at pgcon 2013
PostgreSQL and Redis - talk at pgcon 2013Andrew Dunstan
 
PostgreSQL: present and near future
PostgreSQL: present and near futurePostgreSQL: present and near future
PostgreSQL: present and near futureNaN-tic
 
Postgres в основе вашего дата-центра, Bruce Momjian (EnterpriseDB)
Postgres в основе вашего дата-центра, Bruce Momjian (EnterpriseDB)Postgres в основе вашего дата-центра, Bruce Momjian (EnterpriseDB)
Postgres в основе вашего дата-центра, Bruce Momjian (EnterpriseDB)Ontico
 
DITA Quick Start for Authors - Part I
DITA Quick Start for Authors - Part IDITA Quick Start for Authors - Part I
DITA Quick Start for Authors - Part ISuite Solutions
 
GDG Helwan Introduction to python
GDG Helwan Introduction to pythonGDG Helwan Introduction to python
GDG Helwan Introduction to pythonMohamed Hegazy
 
Architecting Database by Jony Sugianto (Detik.com)
Architecting Database by Jony Sugianto (Detik.com)Architecting Database by Jony Sugianto (Detik.com)
Architecting Database by Jony Sugianto (Detik.com)Tech in Asia ID
 

Ähnlich wie PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules, Performance, and More! (20)

PostgreSQL - Object Relational Database
PostgreSQL - Object Relational DatabasePostgreSQL - Object Relational Database
PostgreSQL - Object Relational Database
 
What’s New In PostgreSQL 9.3
What’s New In PostgreSQL 9.3What’s New In PostgreSQL 9.3
What’s New In PostgreSQL 9.3
 
Benefits of using software design patterns and when to use design pattern
Benefits of using software design patterns and when to use design patternBenefits of using software design patterns and when to use design pattern
Benefits of using software design patterns and when to use design pattern
 
Introduction to PostgreSQL
Introduction to PostgreSQLIntroduction to PostgreSQL
Introduction to PostgreSQL
 
Text search with Elasticsearch on AWS
Text search with Elasticsearch on AWSText search with Elasticsearch on AWS
Text search with Elasticsearch on AWS
 
A Modern Interface for Data Science on Postgres/Greenplum - Greenplum Summit ...
A Modern Interface for Data Science on Postgres/Greenplum - Greenplum Summit ...A Modern Interface for Data Science on Postgres/Greenplum - Greenplum Summit ...
A Modern Interface for Data Science on Postgres/Greenplum - Greenplum Summit ...
 
Active Data Stores at 30,000ft
Active Data Stores at 30,000ftActive Data Stores at 30,000ft
Active Data Stores at 30,000ft
 
No sql bigdata and postgresql
No sql bigdata and postgresqlNo sql bigdata and postgresql
No sql bigdata and postgresql
 
Toolboxes for data scientists
Toolboxes for data scientistsToolboxes for data scientists
Toolboxes for data scientists
 
Tutorial: Implementing your first Postgres extension | PGConf EU 2019 | Burak...
Tutorial: Implementing your first Postgres extension | PGConf EU 2019 | Burak...Tutorial: Implementing your first Postgres extension | PGConf EU 2019 | Burak...
Tutorial: Implementing your first Postgres extension | PGConf EU 2019 | Burak...
 
PostgreSQL and MySQL
PostgreSQL and MySQLPostgreSQL and MySQL
PostgreSQL and MySQL
 
Ledingkart Meetup #2: Scaling Search @Lendingkart
Ledingkart Meetup #2: Scaling Search @LendingkartLedingkart Meetup #2: Scaling Search @Lendingkart
Ledingkart Meetup #2: Scaling Search @Lendingkart
 
Towards More Flexible Enterprise Information Systems
Towards More Flexible Enterprise Information SystemsTowards More Flexible Enterprise Information Systems
Towards More Flexible Enterprise Information Systems
 
Search engines in the industry
Search engines in the industrySearch engines in the industry
Search engines in the industry
 
PostgreSQL and Redis - talk at pgcon 2013
PostgreSQL and Redis - talk at pgcon 2013PostgreSQL and Redis - talk at pgcon 2013
PostgreSQL and Redis - talk at pgcon 2013
 
PostgreSQL: present and near future
PostgreSQL: present and near futurePostgreSQL: present and near future
PostgreSQL: present and near future
 
Postgres в основе вашего дата-центра, Bruce Momjian (EnterpriseDB)
Postgres в основе вашего дата-центра, Bruce Momjian (EnterpriseDB)Postgres в основе вашего дата-центра, Bruce Momjian (EnterpriseDB)
Postgres в основе вашего дата-центра, Bruce Momjian (EnterpriseDB)
 
DITA Quick Start for Authors - Part I
DITA Quick Start for Authors - Part IDITA Quick Start for Authors - Part I
DITA Quick Start for Authors - Part I
 
GDG Helwan Introduction to python
GDG Helwan Introduction to pythonGDG Helwan Introduction to python
GDG Helwan Introduction to python
 
Architecting Database by Jony Sugianto (Detik.com)
Architecting Database by Jony Sugianto (Detik.com)Architecting Database by Jony Sugianto (Detik.com)
Architecting Database by Jony Sugianto (Detik.com)
 

Mehr von Command Prompt., Inc

Normalization: A Workshop for Everybody Pt. 2
Normalization: A Workshop for Everybody Pt. 2Normalization: A Workshop for Everybody Pt. 2
Normalization: A Workshop for Everybody Pt. 2Command Prompt., Inc
 
Normalization: A Workshop for Everybody Pt. 1
Normalization: A Workshop for Everybody Pt. 1Normalization: A Workshop for Everybody Pt. 1
Normalization: A Workshop for Everybody Pt. 1Command Prompt., Inc
 
Integrating PostGIS in Web Applications
Integrating PostGIS in Web ApplicationsIntegrating PostGIS in Web Applications
Integrating PostGIS in Web ApplicationsCommand Prompt., Inc
 
Postgres for MySQL (and other database) people
Postgres for MySQL (and other database) peoplePostgres for MySQL (and other database) people
Postgres for MySQL (and other database) peopleCommand Prompt., Inc
 
Building Grails applications with PostgreSQL
Building Grails applications with PostgreSQLBuilding Grails applications with PostgreSQL
Building Grails applications with PostgreSQLCommand Prompt., Inc
 
Not Just UNIQUE: Exclusion Constraints
Not Just UNIQUE: Exclusion ConstraintsNot Just UNIQUE: Exclusion Constraints
Not Just UNIQUE: Exclusion ConstraintsCommand Prompt., Inc
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLCommand Prompt., Inc
 

Mehr von Command Prompt., Inc (12)

5 Steps to PostgreSQL Performance
5 Steps to PostgreSQL Performance5 Steps to PostgreSQL Performance
5 Steps to PostgreSQL Performance
 
Normalization: A Workshop for Everybody Pt. 2
Normalization: A Workshop for Everybody Pt. 2Normalization: A Workshop for Everybody Pt. 2
Normalization: A Workshop for Everybody Pt. 2
 
Normalization: A Workshop for Everybody Pt. 1
Normalization: A Workshop for Everybody Pt. 1Normalization: A Workshop for Everybody Pt. 1
Normalization: A Workshop for Everybody Pt. 1
 
Integrating PostGIS in Web Applications
Integrating PostGIS in Web ApplicationsIntegrating PostGIS in Web Applications
Integrating PostGIS in Web Applications
 
Postgres for MySQL (and other database) people
Postgres for MySQL (and other database) peoplePostgres for MySQL (and other database) people
Postgres for MySQL (and other database) people
 
Building Grails applications with PostgreSQL
Building Grails applications with PostgreSQLBuilding Grails applications with PostgreSQL
Building Grails applications with PostgreSQL
 
Pg amqp
Pg amqpPg amqp
Pg amqp
 
Not Just UNIQUE: Exclusion Constraints
Not Just UNIQUE: Exclusion ConstraintsNot Just UNIQUE: Exclusion Constraints
Not Just UNIQUE: Exclusion Constraints
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
Database Hardware Benchmarking
Database Hardware BenchmarkingDatabase Hardware Benchmarking
Database Hardware Benchmarking
 
Vertically Challenged
Vertically ChallengedVertically Challenged
Vertically Challenged
 
Simpycity and Exceptable
Simpycity and ExceptableSimpycity and Exceptable
Simpycity and Exceptable
 

PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules, Performance, and More!

  • 1. PostgreSQL Extensibility Jeff Davis, Truviso, Inc.
  • 2. Introduction ● Many businesses have needs that are specific to the industry or to the business itself – Not always met by generic tools offered by a DBMS ● People in that business know best how to solve those problems ● But those people may not be database engine developers
  • 3. And Also... When implementing a workaround on a running system, you want every possible option available.
  • 4. Outline ● How to solve domain-specific problems – Solutions should be as seamless as a native feature, not bolted on. ● How to make those solutions perform like a special-purpose solution ● How to build complete features without modifying the core database engine ● Where these features fit into the PostgreSQL development landscape
  • 5. Extensibility Overview ● Functions – procedural code that can be written in a variety of languages ● Operators – define the behavior of your type and allow it to be usefully indexed ● Types – input/output ● Index Support – define sophisticated indexing behavior for your data type ● Procedural languages
  • 6. Functions ● Can be written in a variety of languages – PL/pgSQL, C, Perl, Python, and more ● Fundamental part of extensibility architecture ● Used for – Operators – Type input/output functions – Index support routines – etc.
  • 7. Operators ● Allowable characters – +-*/<>=~!@#%^&|`? ● Can be infix, postfix, or prefix ● Allow index searches
  • 8. Types ● Types help you represent data the way that makes sense to your business ● User-defined types are given all the power of native types – Not slower – Not less flexible – Not less indexable ● Define input/output, storage, etc.
  • 9. Index Access Methods ● BTree ● GiST ● GIN ● You implement your specialized indexing algorithm using index support functions ● You don't need to worry about low level details like page splits or the transaction log (WAL)
  • 10. Example: PostGIS ● Spatial data – implements OpenGIS – Collections of lines, points, polygons, etc. ● Important queries – Contains – Overlaps ● Existing data types can't represent the data effectively ● BTree can't index effectively, no useful total order for spatial types
  • 11. PostGIS: Types ● Geometry type can hold – points – linestrings – polygons – etc. ● A single geometry value can hold a combination of all of those
  • 12. PostGIS: operators ● && - overlaps ● << - strictly left of ● >> - strictly right of ● ~= - is the same as ● ~ - contains ● @ - is contained by
  • 13. PostGIS: indexes ● Uses GiST, a sophisticated generalized index access method with a tree structure. ● GiST is much more general than BTree. It can search for matches based on what makes sense for your problem, using algorithms that you supply via functions. ● Still has all the safety of the write-ahead log.
  • 14. Example: DBI-Link ● Allows you to access any data source available via Perl's DBI ● Remote data is seen as a table in PostgreSQL ● How?
  • 15. DBI-Link: PL/Perlu ● PL/Perlu is the “untrusted” (i.e. not sandboxed) version of the perl procedural language. ● Can execute arbitrary code, including creating sockets, etc. ● And therefore, it can use Perl's DBI to access any data over a network.
  • 16. DBI-Link: SRFs ● DBI-Link uses Set Returning Functions, or SRFs ● Function returns multiple rows to PostgreSQL ● Is used in place of a table.
  • 17. Example: PL/proxy ● Access remote PostgreSQL data ● Designed to be easy to retrieve data from many different PostgreSQL nodes ● Supports partitioning ● Implemented as its own language
  • 18. PL/proxy: example CREATE OR REPLACE FUNCTION get_user_email(i_username text) RETURNS SETOF text AS $$ CLUSTER 'usercluster'; RUN ON hashtext(i_username) ; SELECT email FROM users WHERE username = i_username; $$ LANGUAGE plproxy;
  • 19. Example: Full Text Search ● Search for matches within a document. ● The primary query is “contains” ● Problem: BTree unsuitable, documents do not have a useful total order. ● Problem: Text type is unsuitable – Lists the same word many times, doesn't eliminate stopwords – Doesn't equate words with same root
  • 20. Full Text Search: Types ● tsquery – type suitable for representing queries – to_tsquery('bears & eat') – 'bear' & 'eat' ● tsvector – document representation suitable for indexed searches – to_tsvector('Bears eat everything.') – 'eat':2 'bear':1 'everyth':3
  • 21. Full Text Search: Indexes ● Indexable Operator - @@ – Means “matches the query” ● Index Access methods – GIN – better query performance and scalability – GiST – better update performance ● GiST is such a generic index interface, it can be used for indexing spatial data and full text data
  • 22. Full Text Search: 8.3 ● Full Text Search lived as a fully functional separate module, including index support, since 2002. ● Was very successful and useful to many people ● Included in PostgreSQL 8.3 ● The fact that such a major feature was fully functional completely outside of the core PostgreSQL product shows the power of the extensible architecture.
  • 23. Development Landscape ● Variety of projects outside of PostgreSQL core – http://www.pgfoundry.org ● Advantages – Separate release cycle – Separate development – Users can pick and choose what fits them best among alternative solutions ● Disadvantages – Can't extend SQL language
  • 24. Conclusion ● Extensibility allows people with knowledge in specific problem domains to create major features without dealing with database internals. ● More efficient development by making independent projects ● Enables businesses to solve practical problems quickly and cheaply, without extensive error- prone “glue” code. ● Doesn't require interrupting normal operation!