jazzband / django-waffle

A feature flipper for Django
https://waffle.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.12k stars 258 forks source link

Query using Seq Scan instead of Index Scan #499

Closed hendrikschneider closed 6 months ago

hendrikschneider commented 6 months ago

I saw in the model that the field name is having a unique attribute set, which should also enable an index on this field. While debugging my db requests, I've noticed that the the query from the html template tag is using a seq scan instead of a lookup.

` Limit (cost=0.00..1.06 rows=1 width=320) (actual time=0.015..0.017 rows=1 loops=1)

-> Seq Scan on waffle_flag (cost=0.00..1.06 rows=1 width=320) (actual time=0.014..0.015 rows=1 loops=1) Filter: ((name)::text = 'show_github_sha'::text) Rows Removed by Filter: 36 Planning Time: 0.299 ms Execution Time: 0.039 ms

`

I would propose that we add the db_index=True to the name field so that look ups are using an index and are way faster than a seq scan.