Planner can't seem to use partial function indexes with parameter from join

From: Alastair McKinley <a(dot)mckinley(at)analyticsengines(dot)com>
To: "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Planner can't seem to use partial function indexes with parameter from join
Date: 2019-04-14 09:55:25
Message-ID: DB6PR0202MB290432AFFAE8727D136C8D67E32A0@DB6PR0202MB2904.eurprd02.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello all,

I am having quite an interesting problem trying to get the planner to use my indexes as intended in my setup.
I am using partial functional indexes that have a different function parameter based on the record type.

A dynamically generated query using unions that are more explicit about index usage is significantly faster (10-50x) that my preferred plain sql approach using joins.

I have reduced my scenario to a minimal test case with inline comments to illustrate the issue here https://gist.github.com/a-mckinley/1b0e95142789cbc09121b71a83d03f45

Is there something that I am missing to allow the planner to use the underlying indexes? Or is the scenario too complex and should I stick with dynamic sql?

Best regards,

Alastair

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ron 2019-04-14 12:58:22 Re: Trigger when user logs in
Previous Message Peter J. Holzer 2019-04-14 09:05:52 Re: Trigger when user logs in