count(*) is faster than count(1)

This commit is contained in:
Joe Nelson
2016-10-23 20:44:42 -07:00
parent 09b63eafad
commit 9dddd144a4
+3 -3
View File
@@ -248,7 +248,7 @@ callProc qi params selectQuery countQuery _ countTotal isSingle =
{countResultF} AS total_result_set, {countResultF} AS total_result_set,
pg_catalog.count(_postgrest_t) AS page_total, pg_catalog.count(_postgrest_t) AS page_total,
case case
when pg_catalog.count(1) > 1 then when pg_catalog.count(*) > 1 then
{bodyF} {bodyF}
else else
coalesce(((array_agg(row_to_json(_postgrest_t)))[1]->{_procName})::character varying, {bodyF}) coalesce(((array_agg(row_to_json(_postgrest_t)))[1]->{_procName})::character varying, {bodyF})
@@ -263,7 +263,7 @@ callProc qi params selectQuery countQuery _ countTotal isSingle =
_assignment (n,v) = pgFmtIdent n <> ":=" <> insertableValue v _assignment (n,v) = pgFmtIdent n <> ":=" <> insertableValue v
_callSql = [qc|select * from {fromQi qi}({_args}) |] :: Text _callSql = [qc|select * from {fromQi qi}({_args}) |] :: Text
_countExpr = if countTotal _countExpr = if countTotal
then [qc|(select pg_catalog.count(1) from {sourceCTEName})|] then [qc|(select pg_catalog.count(*) from {sourceCTEName})|]
else "null::bigint" :: Text else "null::bigint" :: Text
decodeProc = HD.maybeRow procRow decodeProc = HD.maybeRow procRow
procRow = (,,) <$> HD.nullableValue HD.int8 <*> HD.value HD.int8 procRow = (,,) <$> HD.nullableValue HD.int8 <*> HD.value HD.int8
@@ -307,7 +307,7 @@ requestToCountQuery :: Schema -> DbRequest -> SqlQuery
requestToCountQuery _ (DbMutate _) = undefined requestToCountQuery _ (DbMutate _) = undefined
requestToCountQuery schema (DbRead (Node (Select _ _ conditions _ _, (mainTbl, _, _)) _)) = requestToCountQuery schema (DbRead (Node (Select _ _ conditions _ _, (mainTbl, _, _)) _)) =
unwords [ unwords [
"SELECT pg_catalog.count(1)", "SELECT pg_catalog.count(*)",
"FROM ", fromQi qi, "FROM ", fromQi qi,
("WHERE " <> intercalate " AND " ( map (pgFmtCondition qi) localConditions )) `emptyOnNull` localConditions ("WHERE " <> intercalate " AND " ( map (pgFmtCondition qi) localConditions )) `emptyOnNull` localConditions
] ]