From 43c653ac297e5b78117f65c0953a608708b4fff9 Mon Sep 17 00:00:00 2001
From: Marcin Ickiewicz <mickiewicz@syncad.com>
Date: Mon, 2 Nov 2020 13:43:31 +0100
Subject: [PATCH] speed up bridge_get_ranked_post_by_created_for_tag

Workaround with 'id + 0'  which previously speed up the query
after some time fails and has to be removed because it slow down
get_ranked_post.
---
 hive/db/sql_scripts/bridge_get_ranked_post_for_tag.sql | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hive/db/sql_scripts/bridge_get_ranked_post_for_tag.sql b/hive/db/sql_scripts/bridge_get_ranked_post_for_tag.sql
index 2cf4c8203..820f36aea 100644
--- a/hive/db/sql_scripts/bridge_get_ranked_post_for_tag.sql
+++ b/hive/db/sql_scripts/bridge_get_ranked_post_for_tag.sql
@@ -55,7 +55,8 @@ BEGIN
           JOIN hive_posts hp1 ON hp1.id = hpt.post_id
           JOIN hive_accounts_view ha ON hp1.author_id = ha.id
       WHERE hpt.tag_id = __hive_tag AND hp1.counter_deleted = 0 AND hp1.depth = 0 AND NOT ha.is_grayed AND ( __post_id = 0 OR hp1.id < __post_id )
-      ORDER BY hp1.id + 0 DESC
+      --ORDER BY hp1.id + 0 DESC -- this workaround helped the query to better choose indexes, but after some time it started to significally slow down
+      ORDER BY hp1.id DESC
       LIMIT _limit
   ) as created
   JOIN hive_posts_view hp ON hp.id = created.id
-- 
GitLab