HackerTrans
トップ新着トレンドコメント過去質問紹介求人

jiaaro

no profile record

投稿

Neon PostgreSQL Tutorial

neon.com
1 ポイント·投稿者 jiaaro·10 か月前·0 コメント

コメント

jiaaro
·5 か月前·議論
Exists is a useful tool that you should certainly know how to use. Whether or not it's faster than distinct depends on the rest of the query. I've optimized queries where distinct is faster than exists. It's been some time, but I think it boils down to the relative sizes of the tables and how many of the exists queries actually find something (and how often they find more than one something).

Also, some databases (like clickhouse) allow for `any` joins which avoid producing duplicate rows. For example:

    select author.*
    from author
    inner any join book on (
        book.author_id = author.id 
        and book.title like 'Book%'
    )