@@ -455,6 +455,80 @@ spec actualPgVersion = do
455455 nextValSnip `shouldBe`
456456 Just [aesonQQ | ["jsonb_agg((jsonb_build_object('id', nextval('\"Surr_Gen_Default_Upsert_id_seq\"'::regclass)) || elem.value))"] |]
457457
458+ describe " count preference plan costs" $ do
459+ context " tables with count=exact" $ do
460+ it " shows only 1 count aggregate when no limits/max-rows are set" $ do
461+ _ <- request methodPost " /tiobe_pls"
462+ [(" Prefer" ," resolution=merge-duplicates" ), (" Accept" ," application/vnd.pgrst.plan+json" )]
463+ (getInsertDataForTiobePlsTable 1000 )
464+
465+ r <- request methodGet " /tiobe_pls"
466+ ((" Prefer" , " count=exact" ) : acceptHdrs " application/vnd.pgrst.plan+json; for=\" application/json\" ; options=analyze;" ) " "
467+
468+ let resBody = simpleBody r
469+ resHeaders = simpleHeaders r
470+ totalCost = planCost r
471+ aggregateQty = subtract 1 $ length $ T. splitOn " Aggregate" (decodeUtf8 $ LBS. toStrict resBody)
472+
473+ liftIO $ do
474+ resHeaders `shouldSatisfy` elem (" Content-Type" , " application/vnd.pgrst.plan+json; for=\" application/json\" ; options=analyze; charset=utf-8" )
475+ totalCost `shouldSatisfy` (< 33.0 )
476+ aggregateQty `shouldBe` 1
477+
478+ it " shows relevant count aggregates when limits are set" $ do
479+ _ <- request methodPost " /tiobe_pls"
480+ [(" Prefer" ," resolution=merge-duplicates" ), (" Accept" ," application/vnd.pgrst.plan+json" )]
481+ (getInsertDataForTiobePlsTable 1000 )
482+
483+ r <- request methodGet " /tiobe_pls?limit=1000"
484+ ((" Prefer" , " count=exact" ) : acceptHdrs " application/vnd.pgrst.plan+json; for=\" application/json\" ; options=analyze;" ) " "
485+
486+ let resBody = simpleBody r
487+ resHeaders = simpleHeaders r
488+ totalCost = planCost r
489+ aggregateQty = subtract 1 $ length $ T. splitOn " Aggregate" (decodeUtf8 $ LBS. toStrict resBody)
490+
491+ liftIO $ do
492+ resHeaders `shouldSatisfy` elem (" Content-Type" , " application/vnd.pgrst.plan+json; for=\" application/json\" ; options=analyze; charset=utf-8" )
493+ totalCost `shouldSatisfy` (> 49.0 )
494+ aggregateQty `shouldSatisfy` (> 1 )
495+
496+ context " functions with count=exact" $ do
497+ it " shows only 1 count aggregate when no limits/max-rows are set" $ do
498+ _ <- request methodPost " /tiobe_pls"
499+ [(" Prefer" ," resolution=merge-duplicates" ), (" Accept" ," application/vnd.pgrst.plan+json" ), (" Prefer" , " return=representation" )]
500+ (getInsertDataForTiobePlsTable 1000 )
501+
502+ r <- request methodGet " /rpc/get_tiobe_pls"
503+ ((" Prefer" , " count=exact" ) : acceptHdrs " application/vnd.pgrst.plan+json; for=\" application/json\" ; options=analyze;" ) " "
504+
505+ let resBody = simpleBody r
506+ resHeaders = simpleHeaders r
507+ totalCost = planCost r
508+ aggregateQty = subtract 1 $ length $ T. splitOn " Aggregate" (decodeUtf8 $ LBS. toStrict resBody)
509+
510+ liftIO $ do
511+ resHeaders `shouldSatisfy` elem (" Content-Type" , " application/vnd.pgrst.plan+json; for=\" application/json\" ; options=analyze; charset=utf-8" )
512+ totalCost `shouldSatisfy` (< 38.0 )
513+ aggregateQty `shouldBe` 1
514+
515+ it " shows relevant count aggregates when limits are set" $ do
516+ _ <- request methodPost " /tiobe_pls"
517+ [(" Prefer" ," resolution=merge-duplicates" ), (" Accept" ," application/vnd.pgrst.plan+json" )]
518+ (getInsertDataForTiobePlsTable 1000 )
519+
520+ r <- request methodGet " /rpc/get_tiobe_pls?limit=1000"
521+ ((" Prefer" , " count=exact" ) : acceptHdrs " application/vnd.pgrst.plan+json; for=\" application/json\" ; options=analyze;" ) " "
522+
523+ let resBody = simpleBody r
524+ resHeaders = simpleHeaders r
525+ totalCost = planCost r
526+ aggregateQty = subtract 1 $ length $ T. splitOn " Aggregate" (decodeUtf8 $ LBS. toStrict resBody)
527+
528+ liftIO $ do
529+ resHeaders `shouldSatisfy` elem (" Content-Type" , " application/vnd.pgrst.plan+json; for=\" application/json\" ; options=analyze; charset=utf-8" )
530+ totalCost `shouldSatisfy` (> 67.0 )
531+ aggregateQty `shouldSatisfy` (> 1 )
458532
459533disabledSpec :: SpecWith (() , Application )
460534disabledSpec =
0 commit comments