From 946b1139129c9c3be6a042a606a1d65741a9f85c Mon Sep 17 00:00:00 2001 From: steve-chavez Date: Thu, 11 May 2023 21:14:42 -0300 Subject: [PATCH] add function inlining --- docs/index.rst | 5 +++ docs/references/api/stored_procedures.rst | 39 +++++++++++++++++++++++ docs/releases/v11.0.1.rst | 5 +++ postgrest.dict | 4 +++ 4 files changed, 53 insertions(+) diff --git a/docs/index.rst b/docs/index.rst index 34890d57d..35601c1c5 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -82,6 +82,11 @@ Leak-proof Abstraction There is no ORM involved. Creating new views happens in SQL with known performance implications. A database administrator can now create an API from scratch with no custom programming. +Business Logic in Database Functions +------------------------------------ + +There is nothing "business" about keeping data segregated across piles of layers. Use database functions to process data and get the performance benefits of data colocality and reduced network roundtrips. + One Thing Well -------------- diff --git a/docs/references/api/stored_procedures.rst b/docs/references/api/stored_procedures.rst index 3bb971ab3..fcf42fed5 100644 --- a/docs/references/api/stored_procedures.rst +++ b/docs/references/api/stored_procedures.rst @@ -340,6 +340,45 @@ A function that returns a table type can be filtered using the same filters as : curl "http://localhost:3000/rpc/best_films_2017?rating=gt.8&order=title.desc" +.. _function_inlining: + +Function Inlining +~~~~~~~~~~~~~~~~~ + +A function that follows the `rules for inlining `_ will also inline :ref:`filters `, :ref:`order ` and :ref:`limits `. + +For example, for the following function: + +.. code-block:: postgres + + create function getallprojects() returns setof projects + language sql stable + as $$ + select * from projects; + $$; + +Let's get its :ref:`explain_plan` when calling it with filters applied: + +.. tabs:: + + .. code-tab:: http + + GET /rpc/getallprojects?id=eq.1 HTTP/1.1 + Accept: application/vnd.pgrst.plan + + .. code-tab:: bash Curl + + curl "http://localhost:3000/rpc/getallprojects?id=eq.1" \ + -H "Accept: application/vnd.pgrst.plan" + +.. code-block:: psql + + Aggregate (cost=8.18..8.20 rows=1 width=112) + -> Index Scan using projects_pkey on projects (cost=0.15..8.17 rows=1 width=40) + Index Cond: (id = 1) + +Notice there's no "Function Scan" node in the plan, which tells us it has been inlined. + .. _scalar_functions: Scalar functions diff --git a/docs/releases/v11.0.1.rst b/docs/releases/v11.0.1.rst index 6818c5fdb..10257fa85 100644 --- a/docs/releases/v11.0.1.rst +++ b/docs/releases/v11.0.1.rst @@ -17,6 +17,11 @@ Inserts - New :ref:`bulk_insert_default`. +Functions +~~~~~~~~~ + +- Filters on Table-Valued Functions are now guaranteed to be inlined. See :ref:`function_inlining`. + Horizontal Filtering ~~~~~~~~~~~~~~~~~~~~ diff --git a/postgrest.dict b/postgrest.dict index 6803c01be..92a3b4b87 100644 --- a/postgrest.dict +++ b/postgrest.dict @@ -19,6 +19,7 @@ Cardano cd centric changelog +colocality ClojureScript cloudfared config @@ -62,6 +63,8 @@ HTTP HTTPS HV Ibarluzea +Inlining +inlined Integrations ilike imatch @@ -147,6 +150,7 @@ refactor Reloadable Remo requester's +roundtrips RESTful RestSharp RLS