Improving query to use indexes better. Fixes #5101
[fix] Broken groups management by #4308
Merge pull request #5120 from Hackwar/extensiontable

Improving query to use indexes better. Fixes #5101
Merge pull request #5152 from phproberto/broken-groups

[fix] Broken groups management by #4308