Skip to content

Commit

Permalink
Optimize GetRefs, correct and add indexes on ref table (#1284)
Browse files Browse the repository at this point in the history
* Correct index on ref table, add path index for get refs optimization

* Fix gorm tags on ref table

* Fix typo

* fix goose migration tags

* add pg_trgm extension
  • Loading branch information
din-mukhammed authored Oct 8, 2023
1 parent e005129 commit f028050
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
4 changes: 2 additions & 2 deletions code/go/0chain.net/blobbercore/reference/ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ type Ref struct {
Type string `gorm:"column:type;size:1" dirlist:"type" filelist:"type"`
AllocationID string `gorm:"column:allocation_id;size:64;not null;index:idx_path_alloc,priority:1;index:idx_parent_path_alloc,priority:1;index:idx_validation_alloc,priority:1" dirlist:"allocation_id" filelist:"allocation_id"`
LookupHash string `gorm:"column:lookup_hash;size:64;not null;index:idx_lookup_hash" dirlist:"lookup_hash" filelist:"lookup_hash"`
Name string `gorm:"column:name;size:100;not null;index:idx_name_gin:gin" dirlist:"name" filelist:"name"`
Path string `gorm:"column:path;size:1000;not null;index:idx_path_alloc,priority:2;index:path_idx" dirlist:"path" filelist:"path"`
Name string `gorm:"column:name;size:100;not null;index:idx_name_gin" dirlist:"name" filelist:"name"` // uses GIN tsvector index for full-text search
Path string `gorm:"column:path;size:1000;not null;index:idx_path_alloc,priority:2;index:path_idx;index:idx_path_gin_trgm" dirlist:"path" filelist:"path"`
FileMetaHash string `gorm:"column:file_meta_hash;size:64;not null" dirlist:"file_meta_hash" filelist:"file_meta_hash"`
Hash string `gorm:"column:hash;size:64;not null" dirlist:"hash" filelist:"hash"`
NumBlocks int64 `gorm:"column:num_of_blocks;not null;default:0" dirlist:"num_of_blocks" filelist:"num_of_blocks"`
Expand Down
1 change: 0 additions & 1 deletion code/go/0chain.net/swagger.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

## Content negotiation


### URI Schemes
* http
* https
Expand Down
20 changes: 20 additions & 0 deletions goose/migrations/002_correct_and_add_indexes.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- +goose Up

-- Enable pg_trgm extension
CREATE EXTENSION IF NOT EXISTS pg_trgm;

-- Dropping incorrect index on the 'name' column
DROP INDEX IF EXISTS "idx_name_gin:gin";

-- Creating a new GIN index for full-text search on the 'name' column
CREATE INDEX idx_name_gin ON public.reference_objects
USING gin(to_tsvector('english', name));

-- Creating a new GIN index for trigram matching on the 'path' column
CREATE INDEX idx_path_gin_trgm ON public.reference_objects USING gin(path gin_trgm_ops);

-- +goose Down

DROP INDEX IF EXISTS idx_path_gin_trgm;
DROP INDEX IF EXISTS idx_name_gin;
CREATE INDEX IF NOT EXISTS "idx_name_gin:gin" ON public.reference_objects USING btree (name);

0 comments on commit f028050

Please sign in to comment.