pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kevin Grittner <kgrittn@ymail.com>
To: Robert DiFalco <robert.difalco@gmail.com>
To: pgsql-performance@postgresql.org <pgsql-performance@postgresql.org>
Subject: Re: Create one query out of two
Date: Sun, 18 Aug 2013 13:23:41 -0700 (PDT)
Message-ID: <1376857421.73679.YahooMailNeo@web162906.mail.bf1.yahoo.com> (raw)
In-Reply-To: <CAAXGW-zQhcidwZRhgsmmECOtNQQJm8xXwsjVq0vi2Wa5iUMeTA@mail.gmail.com>
References: <CAAXGW-zQhcidwZRhgsmmECOtNQQJm8xXwsjVq0vi2Wa5iUMeTA@mail.gmail.com>
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-performance>

Robert DiFalco <robert.difalco@gmail.com> wrote:>

> UPDATE contacts SET user_id = u.id
>    FROM my_users u 
>    JOIN phone_numbers pn ON u.phone_significant = pn.significant 
>    WHERE contacts.owner_id = 7 AND contacts.user_id IS NULL
>    AND contacts.id = pn.ref_contact_id;
>
> UPDATE contacts SET user_id = u.id
>    FROM my_users u 
>    JOIN email_addresses em ON u.email = em.email 
>    WHERE contacts.owner_id = 7 AND contacts.user_id IS NULL
>    AND contacts.id = em.ref_contact_id;
>
> They are running slower than I'd like them to even though I have
> indices on user_id, owner_id, email, and significant.

Have you tried those queries with an index like this?:

CREATE INDEX contacts_owner_null_user
  ON contacts (owner_id)
  WHERE user_id IS NULL;

--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance



view thread (3+ messages)

Message-ID: <1376857421.73679.YahooMailNeo@web162906.mail.bf1.yahoo.com>
Permalink:  ../1376857421.73679.YahooMailNeo@web162906.mail.bf1.yahoo.com/
Also on:    postgresql.org/message-id/1376857421.73679.YahooMailNeo@web162906.mail.bf1.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: kgrittn@ymail.com, robert.difalco@gmail.com
  Subject: Re: Create one query out of two
  In-Reply-To: <1376857421.73679.YahooMailNeo@web162906.mail.bf1.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox