Re: How to optimize SELECT query with multiple CASE statements? - Mailing list pgsql-general

From Alexander Farber
Subject Re: How to optimize SELECT query with multiple CASE statements?
Date
Msg-id CAADeyWjnHtbpajxy6wcfJt2-3yifF2JmZcShvJg5ucZmktUF_w@mail.gmail.com
Whole thread Raw
In response to Re: How to optimize SELECT query with multiple CASE statements?  (Geoff Winkless <pgsqladmin@geoff.dj>)
Responses Re: How to optimize SELECT query with multiple CASE statements?  (Geoff Winkless <pgsqladmin@geoff.dj>)
List pgsql-general
Hi Geoff,

On Mon, Oct 31, 2016 at 4:21 PM, Geoff Winkless <pgsqladmin@geoff.dj> wrote:

You could break the game table apart into game and gameplayer.

That's more "normal" and fits much more nicely, IMO, and you could
then resolve the CASE by using joins between game and (twice)
gameplayer:

SELECT ...
FROM game INNER JOIN gameplayer AS myplayer ON
game.gameid=myplayer.gameid AND myplayer.uid=in_uid
INNER JOIN gameplayer AS otherplayer ON game.gameid=otherplayer.gameid
AND otherplayer.uid!=in_uid
...

Then all the other tables simply join to myplayer and otherplayer.


do you mean, instead of having player1, player2 columns in the words_games table (as in my current schema https://gist.github.com/afarber/c40b9fc5447335db7d24 ) - I should move the player stuff (uid, hand, score) to a separate table and then JOIN them?

Regards
Alex

pgsql-general by date:

Previous
From: Alban Hertroys
Date:
Subject: Re: initdb createuser commands
Next
From: Joshua Kehn
Date:
Subject: Validity of using the test_decoding plugin for production?