Skip to content
Snippets Groups Projects
Commit 26ff5659 authored by Gandalf's avatar Gandalf
Browse files

[JES] Update schema to update the creation of an index (currently partial but...

[JES] Update schema to update the creation of an index (currently partial but we decided we'd prefer to have the full index since many posts are not 'deleted'); add comments to sql queries to aid in tracking down slow ones from interfaces like pghero (queries get truncated and it's not obvious which one pghero is referring to, but a comment at the beginning of the query will always be displayed so there's no guessing)
parent 6f29716c
No related branches found
No related tags found
5 merge requests!456Release candidate v1 24,!230Setup monitoring with pghero,!135Enable postgres monitoring on CI server,!16Dk issue 3 concurrent block query rebase,!15Dk issue 3 concurrent block query
...@@ -88,7 +88,7 @@ def build_metadata(): ...@@ -88,7 +88,7 @@ def build_metadata():
sa.ForeignKeyConstraint(['parent_id'], ['hive_posts.id'], name='hive_posts_fk3'), sa.ForeignKeyConstraint(['parent_id'], ['hive_posts.id'], name='hive_posts_fk3'),
sa.UniqueConstraint('author', 'permlink', name='hive_posts_ux1'), sa.UniqueConstraint('author', 'permlink', name='hive_posts_ux1'),
sa.Index('hive_posts_ix3', 'author', 'depth', 'id', postgresql_where=sql_text("is_deleted = '0'")), # API: author blog/comments sa.Index('hive_posts_ix3', 'author', 'depth', 'id', postgresql_where=sql_text("is_deleted = '0'")), # API: author blog/comments
sa.Index('hive_posts_ix4', 'parent_id', 'id', postgresql_where=sql_text("is_deleted = '0'")), # API: fetching children sa.Index('hive_posts_ix4', 'parent_id', 'id'), #postgresql_where=sql_text("is_deleted = '0'")), # API: fetching children #[JES] We decided we want the full index since posts can be deleted/undeleted
sa.Index('hive_posts_ix5', 'id', postgresql_where=sql_text("is_pinned = '1' AND is_deleted = '0'")), # API: pinned post status sa.Index('hive_posts_ix5', 'id', postgresql_where=sql_text("is_pinned = '1' AND is_deleted = '0'")), # API: pinned post status
sa.Index('hive_posts_ix6', 'community_id', 'id', postgresql_where=sql_text("community_id IS NOT NULL AND is_pinned = '1' AND is_deleted = '0'")), # API: community pinned sa.Index('hive_posts_ix6', 'community_id', 'id', postgresql_where=sql_text("community_id IS NOT NULL AND is_pinned = '1' AND is_deleted = '0'")), # API: community pinned
) )
......
...@@ -85,7 +85,7 @@ async def get_post(context, author, permlink, observer=None): ...@@ -85,7 +85,7 @@ async def get_post(context, author, permlink, observer=None):
valid_account(author) valid_account(author)
valid_permlink(permlink) valid_permlink(permlink)
sql = SELECT_FRAGMENT + """ WHERE hive_posts_cache.author = :author AND hive_posts_cache.permlink = :permlink AND NOT hive_posts.is_deleted """ sql = "---bridge_api.get_post\n" + SELECT_FRAGMENT + """ WHERE hive_posts_cache.author = :author AND hive_posts_cache.permlink = :permlink AND NOT hive_posts.is_deleted """
result = await db.query_all(sql, author=author, permlink=permlink) result = await db.query_all(sql, author=author, permlink=permlink)
assert len(result) == 1, 'invalid author/permlink or post not found in cache' assert len(result) == 1, 'invalid author/permlink or post not found in cache'
...@@ -134,6 +134,8 @@ async def get_ranked_posts(context, sort, start_author='', start_permlink='', ...@@ -134,6 +134,8 @@ async def get_ranked_posts(context, sort, start_author='', start_permlink='',
sql = SELECT_FRAGMENT + """ WHERE NOT hive_posts_cache.is_paidout AND NOT hive_posts.is_deleted AND hive_posts_cache.is_grayed sql = SELECT_FRAGMENT + """ WHERE NOT hive_posts_cache.is_paidout AND NOT hive_posts.is_deleted AND hive_posts_cache.is_grayed
AND hive_posts_cache.payout > 0 %s ORDER BY hive_posts_cache.payout DESC, post_id LIMIT :limit """ AND hive_posts_cache.payout > 0 %s ORDER BY hive_posts_cache.payout DESC, post_id LIMIT :limit """
sql = "---bridge_api.get_ranked_posts\n" + sql
if start_author and start_permlink: if start_author and start_permlink:
if sort == 'trending': if sort == 'trending':
sql = sql % """ AND hive_posts_cache.sc_trend <= (SELECT sc_trend FROM hive_posts_cache WHERE permlink = :permlink AND author = :author) sql = sql % """ AND hive_posts_cache.sc_trend <= (SELECT sc_trend FROM hive_posts_cache WHERE permlink = :permlink AND author = :author)
...@@ -233,7 +235,7 @@ async def get_account_posts(context, sort, account, start_author='', start_perml ...@@ -233,7 +235,7 @@ async def get_account_posts(context, sort, account, start_author='', start_perml
# pylint: disable=unused-variable # pylint: disable=unused-variable
observer_id = await get_account_id(db, observer) if observer else None # TODO observer_id = await get_account_id(db, observer) if observer else None # TODO
sql = SELECT_FRAGMENT + """ %s """ sql = "---bridge_api.get_account_posts\n" + SELECT_FRAGMENT + """ %s """
if start_author and start_permlink: if start_author and start_permlink:
sql = sql % """ WHERE hive_posts_cache.post_id < (SELECT post_id FROM hive_posts_cache WHERE author = :author AND permlink = :permlink) %s""" sql = sql % """ WHERE hive_posts_cache.post_id < (SELECT post_id FROM hive_posts_cache WHERE author = :author AND permlink = :permlink) %s"""
else: else:
......
...@@ -14,6 +14,8 @@ log = logging.getLogger(__name__) ...@@ -14,6 +14,8 @@ log = logging.getLogger(__name__)
@return_error_info @return_error_info
async def get_discussion(context, author, permlink): async def get_discussion(context, author, permlink):
"""Modified `get_state` thread implementation.""" """Modified `get_state` thread implementation."""
# New index was created: hive_posts_parent_id_btree (CREATE INDEX "hive_posts_parent_id_btree" ON hive_posts btree(parent_id)
# We thougth this would be covered by "hive_posts_ix4" btree (parent_id, id) WHERE is_deleted = false but it was not
db = context['db'] db = context['db']
author = valid_account(author) author = valid_account(author)
......
...@@ -118,7 +118,7 @@ async def get_content(context, author: str, permlink: str): ...@@ -118,7 +118,7 @@ async def get_content(context, author: str, permlink: str):
valid_account(author) valid_account(author)
valid_permlink(permlink) valid_permlink(permlink)
sql = """ ---get_content """ + SELECT_FRAGMENT + """ sql = """ ---get_content\n""" + SELECT_FRAGMENT + """
WHERE hive_posts_cache.author = :author AND hive_posts_cache.permlink = :permlink AND NOT hive_posts.is_deleted WHERE hive_posts_cache.author = :author AND hive_posts_cache.permlink = :permlink AND NOT hive_posts.is_deleted
""" """
result = await db.query_all(sql, author=author, permlink=permlink) result = await db.query_all(sql, author=author, permlink=permlink)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment