Skip to content
Snippets Groups Projects
Commit 3f143a41 authored by Michal Zander's avatar Michal Zander
Browse files

Restore blocks index on hash column

parent aabcfa1d
No related branches found
No related tags found
1 merge request!282Restore blocks index on hash column
Pipeline #113919 passed
-- \ \ / /_\ | _ \ \| |_ _| \| |/ __| -- noqa: disable=LT02, PRS
-- \ \/\/ / _ \| / .` || || .` | (_ |
-- \_/\_/_/ \_\_|_\_|\_|___|_|\_|\___| -- used by get_input_type (search for block_num by block's hash)
-- SELECT hive.register_index_dependency(
-- this file is only executed at startup if the function hafbe_indexes.do_haf_indexes_exist() 'hafbe_app',
-- returns true. This function has a list of the indexes created in this file, and returns $$
-- true if they all exist. If you add, remove, or rename an index created in this file, you CREATE UNIQUE INDEX IF NOT EXISTS uq_blocks_hash ON hafd.blocks USING btree (hash);
-- must make a corresponding change in that function $$
-- );
-- We do this because the ANALYZE at the end of this file is slow, and only needs to be run
-- if we actually created any indexes.
-- Note, for each index below, we first check and see if it exists but is invalid; if so, we drop it.
-- That will cause it to be recreated by the subsequent CREATE IF NOT EXISTS
-- We could chec/drop all of the indexes in a single DO block at the top of the file, which might
-- look cleaner. But I figure this way, someone doing cut & paste is more likely to grab both the
-- drop and the create.
--example template
DO $$
BEGIN
IF EXISTS(SELECT 1 FROM pg_index WHERE NOT indisvalid AND indexrelid = (SELECT oid FROM pg_class WHERE relname = 'example_idx')) THEN
RAISE NOTICE 'Dropping invalid index example_idx, it will be recreated';
DROP INDEX hive.example_idx;
END IF;
END
$$;
--CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS example_idx ON hive.example_table USING btree (example_column);
-- When you create expression indexes, you need to call ANALYZE to force postgresql to generate statistics on those expressions
--ANALYZE VERBOSE hive.example_table;
...@@ -217,6 +217,11 @@ register_commentsearch_indexes() { ...@@ -217,6 +217,11 @@ register_commentsearch_indexes() {
psql "$POSTGRES_ACCESS_ADMIN" -v "ON_ERROR_STOP=on" -f "$backend/hafbe_commentsearch_indexes.sql" psql "$POSTGRES_ACCESS_ADMIN" -v "ON_ERROR_STOP=on" -f "$backend/hafbe_commentsearch_indexes.sql"
} }
register_haf_indexes() {
echo 'Registering haf indexes...'
psql "$POSTGRES_ACCESS_ADMIN" -v "ON_ERROR_STOP=on" -f "$db_dir/create_haf_indexes.sql"
}
SCRIPT_DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" SCRIPT_DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")"
account_dump="$SCRIPT_DIR/../account_dump" account_dump="$SCRIPT_DIR/../account_dump"
...@@ -238,6 +243,7 @@ if [ "$ONLY_APPS" -eq 0 ]; then ...@@ -238,6 +243,7 @@ if [ "$ONLY_APPS" -eq 0 ]; then
if [ "$BLOCKSEARCH_INDEXES" = "true" ]; then if [ "$BLOCKSEARCH_INDEXES" = "true" ]; then
register_blocksearch_indexes register_blocksearch_indexes
fi fi
register_haf_indexes
register_commentsearch_indexes register_commentsearch_indexes
fi fi
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