{"type":"rich","html":"<div style=\"width: 640; height: 426; font-family: sans-serif,arial,freesans;\" ><div id=\"shared_container_896918988\" class=\"shared_container\"><div id=\"shared_header_896918988\" class=\"shared_header\"><a href=\"https:\/\/pluspora.com\/u\/jochen\"><img src=\"https:\/\/hub.netzgemeinde.eu\/photo\/08cd1e575cdbc0f88cb0ca03e04091e9-6\" alt=\"Jochen Spieker\" height=\"32\" width=\"32\" loading=\"lazy\" \/><\/a><span><a href=\"https:\/\/pluspora.com\/u\/jochen\">Jochen Spieker<\/a>  wrote the following  <a href=\"https:\/\/hub.netzgemeinde.eu\/display\/26fc3ae058b30137457b005056264835\">Beitrag <\/a><span class=\"autotime\" title=\"2019-05-14T22:16:59+02:00\">Tue, 14 May 2019 22:16:59 +0200<\/span><\/span><\/div><div id=\"reshared-content-896918988\" class=\"reshared-content\">So how would you optimize such a statement? AFAICT you could get rid of one JOIN because s_user_attributes is unused. But I still think any database should be able to do this and the rest quickly given the right indexes. I assume that s_user.id is a primary key which should make the ORDER BY and LIMIT easy.<br \/><br \/>And how would you implement paging over a result set over distinct HTTP requests? You could argue that this functionality does not make sense in the first place if you are talking about more than a few hundred users. But requirements are, unfortunately, often not in a developer's power to decide. Also, if you are customizing off-the-shelf software, you typically do not have (much) control over the schema.<br \/><br \/>Again with slightly better formatting:<br \/>SELECT DISTINCT s0_.id AS id_0, s1_.name AS name_1, s2_.description AS description_2, s3_.countryname AS countryname_3, s0_.id AS id_4 <br \/>FROM s_user s0_<br \/>LEFT JOIN s_core_shops s1_ ON s0_.subshopID = s1_.id<br \/>LEFT JOIN s_user_addresses s4_ ON s0_.default_billing_address_id = s4_.id<br \/>LEFT JOIN s_core_countries s3_ ON s4_.country_id = s3_.id<br \/>LEFT JOIN s_user_attributes s5_ ON s0_.id = s5_.userID<br \/>LEFT JOIN s_core_customergroups s2_ ON s0_.customergroup = s2_.groupkey <br \/>ORDER BY s0_.id DESC LIMIT 20 OFFSET 0<br \/><br \/>I think you could argue that you should not be doing what the developer is doing in the first place. But I fail to see how the statement itself could be done any better except for the one superfluous JOIN. Care to enlighten me?<br \/><br \/>(And yes, I work in software development and know this very situation quite well. I help run an e-commerce site with tens of million registered users and a few tables with 10e8 rows. I have my fair share of &quot;It was fast in my VM&quot; stories, but this does not look like one to me or at least that is not the whole story.)<\/div><\/div><br \/><\/div>","width":640,"height":426}