Skip to content

Commit

Permalink
add tests for inlining
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-chavez committed Feb 25, 2023
1 parent 46ff14f commit 3e86be1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions test/spec/Feature/Query/PlanSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import Network.Wai.Test (SResponse (..))

import Data.Aeson.Lens
import Data.Aeson.QQ
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as LBS
import qualified Data.Text as T
import Network.HTTP.Types
import Test.Hspec hiding (pendingWith)
import Test.Hspec.Wai
Expand Down Expand Up @@ -358,6 +360,26 @@ spec actualPgVersion = do

liftIO $ planCost r `shouldSatisfy` (< 5.85)

context "function inlining" $ do
it "should inline a zero argument function" $ do
r <- request methodGet "/rpc/getallusers?id=eq.1"
[(hAccept, "application/vnd.pgrst.plan")] ""

let resBody = simpleBody r

liftIO $ do
resBody `shouldSatisfy` (\t -> T.isInfixOf "Index Scan using users_pkey on users" (decodeUtf8 $ BS.toStrict t))

it "should inline a function with arguments" $ do
r <- request methodGet "/rpc/getitemrange?min=10&max=15"
[(hAccept, "application/vnd.pgrst.plan")] ""

let resBody = simpleBody r

liftIO $ do
-- a Seq Scan ensures the function is inlined as the plan uses the underlying table
resBody `shouldSatisfy` (\t -> T.isInfixOf "Seq Scan on items" (decodeUtf8 $ BS.toStrict t))

disabledSpec :: SpecWith ((), Application)
disabledSpec =
it "doesn't work if db-plan-enabled=false(the default)" $ do
Expand Down
2 changes: 1 addition & 1 deletion test/spec/fixtures/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1894,7 +1894,7 @@ CREATE TABLE test.openapi_defaults(
create function add_them(a integer, b integer)
returns integer as $$
select a + b;
$$ language sql stable;
$$ language sql;

create or replace function root() returns json as $_$
declare
Expand Down

0 comments on commit 3e86be1

Please sign in to comment.