Re: How to optimize SELECT query with multiple CASE statements?

From: Alexander Farber <alexander(dot)farber(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to optimize SELECT query with multiple CASE statements?
Date: 2016-10-31 15:46:14
Message-ID: CAADeyWjnHtbpajxy6wcfJt2-3yifF2JmZcShvJg5ucZmktUF_w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi Geoff,

On Mon, Oct 31, 2016 at 4:21 PM, Geoff Winkless <pgsqladmin(at)geoff(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joshua Kehn 2016-10-31 15:57:32 Validity of using the test_decoding plugin for production?
Previous Message Alban Hertroys 2016-10-31 15:36:09 Re: initdb createuser commands