Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vJXVI-00ANaO-0Y for pgsql-general@arkaria.postgresql.org; Thu, 13 Nov 2025 13:36:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vJXUG-001cyE-2u for pgsql-general@arkaria.postgresql.org; Thu, 13 Nov 2025 13:35:44 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vJXUG-001cy6-1J for pgsql-general@lists.postgresql.org; Thu, 13 Nov 2025 13:35:44 +0000 Received: from mail-francecentralazon11013012.outbound.protection.outlook.com ([40.107.162.12] helo=PA4PR04CU001.outbound.protection.outlook.com) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vJXUC-007XuL-0R for pgsql-general@lists.postgresql.org; Thu, 13 Nov 2025 13:35:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sg6dCqOfIvp4ZIR7tV+YSz3Uo1gCUhuRgImDoC6G0ZoFlZxVhH//g2BdMMTUqxWXB1hyUqDKT3PGrD+UD9cwujmYs/cQ0i4uQHbDwHeyzjFFCFyZnI34xmU/qhqtQFhCU9szATufOsML1dPmtkHkh+uE6sS9VSnAbvb2lRgSS0BzMAvJq6oLr0DmAZIYcy2+zzEmfRRNxLnJ6f/q5wEnw2jHUcSWlwa4N3W+rq1dBexyRm6fqZobKtQVk7jqhGNk5QOPh4Rdp5NZyCtdN6CW9uWj32WgxCkRU9en+Aki8iWMoNOlq17UXJS/isky8iXBvWtZHDWCBTvtTD0vX5QoiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=tCWhwYdBR9KCQoTs3mzU764rwam4sdEFJy7popW7l2Q=; b=aE9TCVJAw+pAMrhDKqGJ5es41jn9bCbvT6KTTt/AcJLIxFPcbamyfCoxFB6XzUND++fPYNUN5yGD3QNuuz0OYLfJO0FYAxl3dGh9Z1NDemDIh0fnLp6pUt27hk/bZDqZYf+EORh4Pl8zRiNNF3LJOIJBghrWo8NOdrH6IH6dXIJmjQylP6k0iKiGSx6DE6+xbLr7CO+wsV+itZdfJiU8836aUV9FiOCrmgjWNi+xlRW5ICtu8HbB/FwrhTq+ZKfviZeCzwHWmk+uFyZsVxLfeqVp3k9a8HzfI9HveOY+ccXPY9OnQsEiqwP3SKj6RME/gGb5HQgQ+w9k7FbRACsYPw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oliver.agency; dmarc=pass action=none header.from=oliver.agency; dkim=pass header.d=oliver.agency; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oliver.agency; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tCWhwYdBR9KCQoTs3mzU764rwam4sdEFJy7popW7l2Q=; b=x3wMPzRiIdOYRxDZF0EjhcM7afLtN3wUhsk6FemPiPOkQc8MFm5y7vYQ73RmyVgFgWu039J0WoTtH2wYZasbquoPcJnGKbnUYVjAPx5jxqQTuVG6vx+PwY72ZnrS3RvKhrqf9Q8c8+MPb3A8gfwUlUzoTdJHV2v0012NLJBIm+k= Received: from VI6PPFA4BECA431.EURP251.PROD.OUTLOOK.COM (2603:10a6:808:1::160) by AS8P251MB0295.EURP251.PROD.OUTLOOK.COM (2603:10a6:20b:34f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9320.15; Thu, 13 Nov 2025 13:35:36 +0000 Received: from VI6PPFA4BECA431.EURP251.PROD.OUTLOOK.COM ([fe80::1872:3e05:fa85:e64e]) by VI6PPFA4BECA431.EURP251.PROD.OUTLOOK.COM ([fe80::1872:3e05:fa85:e64e%6]) with mapi id 15.20.9320.013; Thu, 13 Nov 2025 13:35:36 +0000 From: Zahir Lalani To: "pgsql-general@lists.postgresql.org" Subject: Forcing Index usage Thread-Topic: Forcing Index usage Thread-Index: AdxUoQ5QzWxg3H74Sdeo/SokfWuzQA== Date: Thu, 13 Nov 2025 13:35:36 +0000 Message-ID: Accept-Language: en-US, en-GB Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-bromium-msgid: a38f0f05-a970-4a1d-bffb-1bfa1e11bb07 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oliver.agency; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI6PPFA4BECA431:EE_|AS8P251MB0295:EE_ x-ms-office365-filtering-correlation-id: 8e5369be-d7df-4034-7b0a-08de22b9875d x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0;ARA:13230040|1800799024|10070799003|376014|366016|38070700021|8096899003; x-microsoft-antispam-message-info: =?us-ascii?Q?72xYN/C5vIFfK+1gCGcoL03bHLp1FPRtD7hg7Fm9Fd0KXxDqNKgNyJDxzyKN?= =?us-ascii?Q?1ChB4brqjbDABRqHBGB2e8bnuGiBgiQ0OxRoSuBfrajQYj+VOjQuRY39V6m/?= =?us-ascii?Q?Kb4rKkEiCoyQ5oJ/nPQgy2UTCjYvZwNtkdO9uS7SkgZYXI0QwDReSKZIrcva?= =?us-ascii?Q?ky+qr1M4dvFEHUw0ign/pO0g1U6oZOfjHZVIcZp0IyXnkPG1WrgJipQx3joZ?= =?us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fJILgD6rHEemUV7OCxqMp?= =?us-ascii?Q?X8N4Y+ePSxggf+//CFVVbL3rjdjdeRLF0Wuly6Bx+4MU4L/gVEZpvoyW+F6E?= =?us-ascii?Q?Bs9jLw/CPix1dDGAp91ewPOy+LvLEjNM4Nam2Bjwi687FwHe+7qlxM1kPlvl?= =?us-ascii?Q?/01oF61KEfnywWbWZK7hyrWCqUpJ2Sl9bKQ46O04TzipC+5RnEG0aa/6qaMl?= =?us-ascii?Q?KK21f8MH0EeGdJaWAYUKSfvFVqVUl2AdwkKNRnP1Hybf3wDPupEVBQ9DEiOY?= =?us-ascii?Q?ECR9F+dnNGiji+geuMQg5aOZy3KxB8dG4ksWHjqJopcmWDOY9x5LJ0xBqHmH?= =?us-ascii?Q?s7rc5jK8k/JtoPoomT5LehD33BZnqdKIetWtSnh7M+zWlcmVPkIA5Ua7rx+h?= =?us-ascii?Q?eSoju4uaiphTsGwvCHNdmNOuCMGgNOZLeOy5?= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI6PPFA4BECA431.EURP251.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(10070799003)(376014)(366016)(38070700021)(8096899003);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?xZqv8AVtb2u5kqkfeaaqXuqixWaYfmeFIHavFMduOaJ4s6e659/aSdOXauV9?= =?us-ascii?Q?wW7YyNZAZfP3skkVVnNNKBklqGXc7lxIjrWz+OYQnSOZ1v79NxsqFamQvsij?= =?us-ascii?Q?VXXjbF35cqWVzbcLSBdChkXZxM8bHY+l8kptLRPYQq4cOAAyoxARA/hq3/wn?= =?us-ascii?Q?v05xs4Tgp/iBjCFgWH7VCPxKnKWrOaQEUfRQXhBzZivwTT+rVwLhRa+GrPwD?= =?us-ascii?Q?GcZCMt64Uv48tUcVf2OLc9Vhru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q?jWwNjGy1Um7C6o2dgcXan8T6EUQVbA7nGMZFEU653WmxkLPz+udOA7K3tHSV?= =?us-ascii?Q?HSNDeCA5elLCbp4B3eOh2ZpyRc2hmslg2T0A6mWqFy5D3Gk6CKknSUN5AWmo?= =?us-ascii?Q?cNQ+WqkRsjnvXNSl+SvgNf1Md5NLtp67YfdMtax0R9Cj4SBNznhGSubebyM5?= =?us-ascii?Q?cDTuYFd1yenuhUN8lbmYoxMBzAKJNHPABOu5pcb2QoI9bXqFTc0GuBYZ317l?= =?us-ascii?Q?7EhUYQ3Buv9OEMNjhcHA/igUUFzx+z9vg5AgaK0SMxyGDMQ1+47B7ATAdtQf?= =?us-ascii?Q?u3q6+CDyFvcXHqWg44uIf8bg8MH5sGn4LdUFbgGyDYkAkht5Zhr5yl8w6QbZ?= =?us-ascii?Q?cVJ68kbLZWGl/Ldj7mRrvXFuxnB4G8zW7LRX8OdxZ7vg+5kUccNlOngkuq/r?= =?us-ascii?Q?OMg+YU/8PTWleOY5l8XPD5ZOXMn+CAkE4HEbLW0VkRfyMmYVWTjn+G7bPKSf?= =?us-ascii?Q?QJDsvIZmlqdcvWs80NHk5fcq6t9x6nzfo6xeSfd/oqpN?= Content-Type: multipart/alternative; boundary="_000_VI6PPFA4BECA43135879DAC4554E69C07AFA7CDAVI6PPFA4BECA431_" MIME-Version: 1.0 X-OriginatorOrg: oliver.agency X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: VI6PPFA4BECA431.EURP251.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: 8e5369be-d7df-4034-7b0a-08de22b9875d X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Nov 2025 13:35:36.8112 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: e519c2e6-bc6d-4fdf-8d9c-923c2f002385 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: RL3Nv4d+BJyAR7p6NNSs3qQAUxW9UEG5YnauM78Uqynbw38O1i18uIa5qPnICc8xZUwiODCmgKqZmU4ZmBpnJV+G3WSifpJXJfQxa1ud8O4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8P251MB0295 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --_000_VI6PPFA4BECA43135879DAC4554E69C07AFA7CDAVI6PPFA4BECA431_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hello all Have a very frustrating issue - we are seeing the same results in our PG17 = UAT and PG14 Live setups (we are in transition). (I can provide the query planner but not doing here in case its too much in= fo) Here is the query in question which we have re-written to try and get bette= r outcomes - this is a type-ahead lookup and the test below responds to the= first three letters "tes" The CTE runs in about 1.5s and the code below runs in around 1.2s which is = acceptable The problem is as soon as we add in the "parent_id" join -- ****** AND js.parent_id =3D jt.id -- looks for status ba= sed on job type, 4 type def looks for job statuses According to the query planner, this reverts to a seq scan and the time goe= s up to 30s! There are individual indexes on the 3 fields for JS (ctypes) as well as a c= omposite key specifically designed for this use case. However, nothing we do seems to force it to use the indexes, this line alwa= ys goes down the sequential scan route. Any suggestions would be welcome. If the planner will help, I can provide b= oth for the mode with and without the line in question. Thank you with search as ( select j.id, j.fk_job_type, j.fk_status, j.job_number, j.cr= eative_name from jobs as j where (j.search_tsv @@ (to_tsquery('tes'||':*'))) AND j.fk_job_context_type =3D 1 -- jobs AND (j.is_template IS FALSE) AND j.is_deleted IS FALSE AND j.fk_parent_id IS NULL -- Exclude the s= ub jobs AND j.is_encrypted IS FALSE AND (j.fk_owning_agency_org =3D ANY('{11126,87326,11129,11131,11144,111= 34,62158,9649,63095,52685,103238,52449,56928,86885,52457,71727,40489,65669,= 36795,87213,51241,63980,63981,39903,60062,52456,68995,69010,60535,63979,656= 67,69002,40997,39475}') OR j.fk_agency_org =3D ANY('{11126,87326,11129,1113= 1,11144,11134,62158,9649,63095,52685,103238,52449,56928,86885,52457,71727,4= 0489,65669,36795,87213,51241,63980,63981,39903,60062,52456,68995,69010,6053= 5,63979,65667,69002,40997,39475}')) ) SELECT j.id AS seq_id, j.job_number AS job_number, j.creative_name AS creative_name, campaign.id, campaign.plan_number, campaign.name as campaign_name FROM search as j INNER JOI= N "public".relationship_module AS planning_job_relation ON planning_job_relation.fk_child_id=3D j.id -- the campaign/job re= lationship AND planning_job_relation.fk_child_entity_id =3D 2 -- jobs AND planning_job_relation.fk_parent_entity_id =3D 1 -- plannin= g INNER JOIN "public".planning AS campaign ON campaign.id =3D planning_job_relation.fk_parent_id -- get the c= ampaign details INNER JOIN "public".c_types AS jt ON jt.local_id =3D j.fk_job_type AND jt.fk_type_def =3D 3 -- looks for job types INNER JOIN "public".c_types AS js ON js.local_id =3D j.fk_status AND js.fk_type_def =3D 4 -- ****** AND js.parent_id =3D jt.id-- looks for status bas= ed on job type, 4 type def looks for job statuses -- WHERE 1=3D1 AND js.object_key_area_id NOT IN (7, 8, 37) -- completed jobs = =3D 7, cancelled jobs =3D 8, Client delivery confirmed jobs =3D 37. AND campaign.fk_status NOT IN (1502, 1504, 1506) -- completed p= lanning =3D 1502, Cancelled planning =3D 1504, Client delivery confirmed = =3D 1506 AND js.object_key_area_id NOT IN (7, 8, 37) ORDER BY j.id desc LIMIT 500; Z --_000_VI6PPFA4BECA43135879DAC4554E69C07AFA7CDAVI6PPFA4BECA431_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Hello all

 

Have a very frustrating issue – we are seeing = the same results in our PG17 UAT and PG14 Live setups (we are in transition= ).

 

(I can provide the query planner but not doing here = in case its too much info)

 

Here is the query in question which we have re-writt= en to try and get better outcomes – this is a type-ahead lookup and t= he test below responds to the first three letters “tes”

The CTE runs in about 1.5s and the code below runs i= n around 1.2s which is acceptable

The problem is as soon as we add in the “paren= t_id” join

 

        &nbs= p;       -- ****** AND js.parent_id =3D jt.id= -- looks for status based on job type, 4 type def looks for job statuses

 

According to the query planner, this reverts to a se= q scan and the time goes up to 30s!

There are individual indexes on the 3 fields for JS = (ctypes) as well as a composite key specifically designed for this use case= .

 

However, nothing we do seems to force it to use the = indexes, this line always goes down the sequential scan route.

 

Any suggestions would be welcome. If the planner wil= l help, I can provide both for the mode with and without the line in questi= on. Thank you

 

with search as (

 

        &nbs= p;       select j.id, j.fk_job_type, j.fk_sta= tus, j.job_number, j.creative_name

        &nbs= p;       from jobs as j

        &nbs= p;       where (j.search_tsv @@ (to_tsquery('= tes'||':*')))

        &nbs= p;            &= nbsp;          AND j.fk_job_co= ntext_type =3D 1 -- jobs

        &nbs= p;            &= nbsp;          AND (j.is_templ= ate IS FALSE)

        &nbs= p;            &= nbsp;          AND j.is_delete= d IS FALSE

        &nbs= p;            &= nbsp;          AND j.fk_parent= _id IS NULL -- Exclude the sub jobs

        &nbs= p;            &= nbsp;          AND j.is_encryp= ted IS FALSE

    AND (j.fk_owning_agency_org =3D A= NY('{11126,87326,11129,11131,11144,11134,62158,9649,63095,52685,103238,5244= 9,56928,86885,52457,71727,40489,65669,36795,87213,51241,63980,63981,39903,6= 0062,52456,68995,69010,60535,63979,65667,69002,40997,39475}') OR j.fk_agency_org =3D ANY('{11126,87326,11129,11131,11144,11134,62158,964= 9,63095,52685,103238,52449,56928,86885,52457,71727,40489,65669,36795,87213,= 51241,63980,63981,39903,60062,52456,68995,69010,60535,63979,65667,69002,409= 97,39475}'))          &nb= sp;            =         

 

)

 

 

        SELECT

        &nbs= p;   j.id AS seq_id,

        &nbs= p;   j.job_number AS job_number,

        &nbs= p;   j.creative_name AS creative_name,

        &nbs= p;   campaign.id,

        &nbs= p;   campaign.plan_number,

        &nbs= p;   campaign.name as campaign_name

 

        FROM sear= ch as j

        &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;    

        &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;       INNER JOIN "public".relationshi= p_module AS planning_job_relation ON

        &nbs= p;  planning_job_relation.fk_child_id=3D j.id -- the campaign/job rela= tionship

        &nbs= p;   AND planning_job_relation.fk_child_entity_id =3D  2 -- = jobs

        &nbs= p;   AND planning_job_relation.fk_parent_entity_id =3D 1 -- = planning

        &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;           

        &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;       

        INNER JOI= N "public".planning AS campaign ON

        &nbs= p;   campaign.id =3D planning_job_relation.fk_parent_id -- get th= e campaign details

 

         INN= ER JOIN "public".c_types AS jt ON

        &nbs= p;    jt.local_id =3D j.fk_job_type

        &nbs= p;    AND jt.fk_type_def =3D 3 -- looks for job types

 

 

        &nbs= p;    INNER JOIN "public".c_types AS js ON

        &nbs= p;        js.local_id =3D j.fk_status

        &nbs= p;       AND js.fk_type_def =3D 4 =

        &nbs= p;       -- ****** AND js.parent_id =3D jt.id= -- looks for status based on job type, 4 type def looks for job statuses

--

        WHER= E 1=3D1

        &nbs= p;   AND js.object_key_area_id NOT IN (7, 8, 37) -- completed job= s =3D 7, cancelled jobs =3D 8, Client delivery confirmed jobs =3D 37.<= /o:p>

        &nbs= p;   AND campaign.fk_status NOT IN (1502, 1504, 1506) -- complete= d planning =3D 1502, Cancelled planning =3D 1504, Client delivery confirmed= =3D 1506  

 AND js.object_key= _area_id NOT IN (7, 8, 37)

 

        &nbs= p;  

        ORDE= R BY j.id desc

        LIMIT 500= ;

 

Z

--_000_VI6PPFA4BECA43135879DAC4554E69C07AFA7CDAVI6PPFA4BECA431_--