@dorian_yugabyte Thanks for your response. Below is my schema structure
CREATE TABLE public.posts (
id uuid NOT NULL,
title varchar(255) NOT NULL,
is_private bool NOT NULL,
member_id uuid NOT NULL,
association_id uuid NOT NULL,
association_type public.enum_posts_association_type NOT NULL,
is_active public.enum_posts_is_active NULL DEFAULT 'inactive'::enum_posts_is_active,
is_deleted timestamptz NULL,
created_at timestamptz NULL DEFAULT now(),
updated_at timestamptz NULL DEFAULT now(),
description text NULL,
comment_count int8 NULL DEFAULT 0,
reaction_count int8 NULL DEFAULT 0,
external_links jsonb NULL DEFAULT '{}'::jsonb,
CONSTRAINT posts_pkey PRIMARY KEY (id)
);
CREATE INDEX ix_posts_associationid ON public.posts USING lsm (association_id HASH) WHERE ((is_active = 'active'::enum_posts_is_active) AND (is_deleted IS NULL));
**explain** **analyse**
**select** * **FROM** "posts" **AS** "post"
**WHERE** "post"."is_deleted" **IS** **null**
**and** "post".is_active = 'active'
**AND** "post"."association_type" = 'organization'
**AND** "post"."association_id" = '1a3ae463-03c3-414a-b540-a3d480b0c167'
Seq Scan on posts post (cost=0.00..107.50 rows=1000 width=677) (actual time=21.506..2781.863 rows=5 loops=1)
Filter: ((is_deleted IS NULL) AND (is_active = 'active'::enum_posts_is_active) AND (association_type = 'organization'::enum_posts_association_type) AND (association_id = '1a3ae463-03c3-414a-b540-a3d480b0c167'::uuid))
Rows Removed by Filter: 269944
Planning Time: 0.050 ms
Execution Time: 2781.912 ms
Peak Memory Usage: 72 kB
I just copied the same data to another table with same schema structure and index using below statements
CREATE TABLE public.posts_tmp (
id uuid NOT NULL,
title varchar(255) NOT NULL,
is_private bool NOT NULL,
member_id uuid NOT NULL,
association_id uuid NOT NULL,
association_type public.enum_posts_association_type NOT NULL,
is_active public.enum_posts_is_active NULL DEFAULT 'inactive'::enum_posts_is_active,
is_deleted timestamptz NULL,
created_at timestamptz NULL DEFAULT now(),
updated_at timestamptz NULL DEFAULT now(),
description text NULL,
comment_count int8 NULL DEFAULT 0,
reaction_count int8 NULL DEFAULT 0,
external_links jsonb NULL DEFAULT '{}'::jsonb,
CONSTRAINT posts_pkey_tmp PRIMARY KEY (id)
);
CREATE INDEX ix_posts_associationid_tmp ON public.posts_tmp USING lsm (association_id HASH) WHERE ((is_active = 'active'::enum_posts_is_active) AND (is_deleted IS NULL));
INSERT INTO posts_tmp
SELECT * FROM posts
Now with the new table it generated the better execution plan.
**explain** **analyse**
**select** * **FROM** posts_tmp "post"
**WHERE** "post"."is_deleted" **IS** **null**
**and** "post".is_active = 'active'
**AND** "post"."association_type" = 'organization'
**AND** "post"."association_id" = '1a3ae463-03c3-414a-b540-a3d480b0c167'
Index Scan using ix_posts_associationid_tmp on posts_tmp post (cost=0.00..5.04 rows=10 width=677) (actual time=1.463..1.484 rows=5 loops=1)
Index Cond: (association_id = '1a3ae463-03c3-414a-b540-a3d480b0c167'::uuid)
Filter: (association_type = 'organization'::enum_posts_association_type)
Planning Time: 0.073 ms
Execution Time: 1.532 ms
Peak Memory Usage: 8 kB