ブログを作成していますが、問題があります。粘着性のある投稿がいくつかあるはずです。私が望むのは、最初にスティッキーポストを取得し、次に残りを取得することだけです.
機能するクエリの1つは
select * from
(
(select *,true as st from blog where "stickyUntil" > current_timestamp)
UNION all
(SELECT *,false as st from blog where "stickyUntil" < current_timestamp or "stickyUntil" is null )
) q
order by st desc, "stickyUntil" DESC ,publish DESC OFFEST x LIMIT z
workz のもう 1 つの簡単なクエリは次のとおりです。
select * from blog order by case when "stickyUntil" > current_timestamp then "stickyUntil" end desc nulls last, publish desc;
しかし、これは200.000行をメモリ内でソートすることを強制し、それほど速くはありません..
それを最適化する方法はありますか??
2 つの別々のクエリを使用する方がよいでしょうか? ありがとう