Open romanstingler opened 1 year ago
Hi,
There are 2 limitations here explaining the behavior. First, pg_qualstats itself for now only tracks "simple" quals, e.g. things of the form column operator column
or column operator constant
. So with your example there's unfortunately nothing stored by pg_qualstats that the advisor could try to handle.
Then, even if more complex quals were handled by pg_qualstats, the advisor for now only tries to suggest indexes on one or multiple columns, but nothing more complex. So functional indexes wouldn't be handled anyway, same for partial indexes.
Clearly things could be improved, and I will try to look at it. But right now I'm not really sure of how exactly we could track complex expression. For instance if there's a function call using multiple columns, trying to attach the expr to all columns wouldn't be easy.
I butchered together some SQL statements :)
CREATE TABLE json_test(body jsonb);
create INDEX ON "json_test" using btree ((body -> 'specValue' ->>'text'));
This should create a table with a JSONB column. Generate some random data and query a field within the JSON data (explain commented out). At the end, there is the code to create a BTREE index on the field in the where clause (condition in where is the same as the index). With the index, you can use the explain statement from above and see that the index should be used.
Such queries are not covered by the index advisor.