django-mysql
django-mysql copied to clipboard
Index hint for nested queries (bound to alias)
Summary:
Index hint should remember which table it was applied. Solution:
- on each aliases changing in query also change alias in index hint
- at rewriting stage modify SQL according the alias
Checklist:
- [x] Docs updated, or N/A
- [x] Line added to HISTORY.rst, or N/A
- [x] Added extra items to checklist as applicable
- [x] All commits squashed into one.
Test Plan:
- added tests for nested queries up to 3 level generated by Django ORM
- added test for raw SQL query
Known issue:
For nested queries like this (without any JOIN):
SomeModel.objects.filter(pk__in=SomeModel.objects.all())
Django will not assign alias to any table, so index hint will be always applied to outer query. But it looks like queries like this are useless.
This is nice and looks good. A quick glance doesn't reveal anything problematic, but I'll give it a bit more testing during the week!
Can someone share the status of this patch? Is the issue addressed by some other PR, or is it just left unfixed for some reason?
I've been meaning to review this but it's quite a big chunk of stuff to understand at once (and after this time, rebase). And I've never had the issue myself, and I guess I've always had higher impact things to work on.
If you want to rebase it that would be a helpful start; even more helpful would be running it in your app (dev, or staigng, or even prod) and seeing if you encounter any issues not addressed by tests.
Thanks for the update, Adam!
I'm currently working to upgrade a project from ancient times (Django 1.9 + A forked django-mysql 1.0.9 with this PR applied) so I can't contribute to the upstream at this point. But I'll be happy to return to this issue when I can.