Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iPDm2-0004uM-1X for pgsql-performance@arkaria.postgresql.org; Mon, 28 Oct 2019 22:46:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iPDlz-00082Z-Po for pgsql-performance@arkaria.postgresql.org; Mon, 28 Oct 2019 22:46:03 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iPDlz-00082S-5h for pgsql-performance@lists.postgresql.org; Mon, 28 Oct 2019 22:46:03 +0000 Received: from mail-yw1-xc43.google.com ([2607:f8b0:4864:20::c43]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iPDls-00077H-8k for pgsql-performance@lists.postgresql.org; Mon, 28 Oct 2019 22:46:02 +0000 Received: by mail-yw1-xc43.google.com with SMTP id d192so4431034ywa.1 for ; Mon, 28 Oct 2019 15:45:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=yMLQ9T1g58mhfx85PKO3d/AIfgOWtDcQHlrKIhz9si8=; b=HRrGZaeI3S24z3KOfVCs0t9qKpDsf8BPIo3n0MPX8CBQd3/aHdKYOyv9xCKcMVODbR HZ6wdYUHEdoOlU0yeHeCMfYX6VyNvl+IEoQ8JH4akgKE1H7jAWeEqCG4lEXXksbx7Au/ UQ8eNU/9QPdrhCLdMv6VzvJa9B26vf8mhRUv8nipprrFDp78cgs6YqpQrFLpY18nDXtI 2uOh1rhLMpMA9MGGXImJLoKfEEEXRtTWL56zKR45+QEcDWPUtNUUq/qobNfI75dKKHCz wreSQFuqg1euswIyB7mMK35xiw2dZc02lcV8Ne9lH0zZgyIgNSbTzQF6rRVNRy8+kdAv 9hng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=yMLQ9T1g58mhfx85PKO3d/AIfgOWtDcQHlrKIhz9si8=; b=SAYlEX74ya1C+3m0t9e7I7OsKHszqy8juY8XuXLr5U1DnnLG3aYqluai5rGs/1ti5g Qe1NblUVpvNt/Z0Ew34H0MinajiLEbPbr5M20CD4smWa93NTO1/rcgzFIR48hbS5bpy5 i7SGBKiJN+fNzKSXCsVarJR+WjjF/aUsAmx8zZaivuYydOsHhQ8GbNUJ9u8M1k+IPAUg 2Qxl3KcC5q2gN6P9rOeZIjyCTjhYH9ckbDN2ambqAl7Qw/5MbX/D4ynFXNCaaUB+sFuX IAh/GCGLhsSKI+x2ixRxqJ6XDzMnPQGUvcbgBuf+aR/eiCeU23if9mSTj2np3Kg84ruY Iuxw== X-Gm-Message-State: APjAAAUzrJOzDy53RjMbpwxuf+Ekg4WaunmzGN1353PdniumOA9IwPBJ lUetwRC+sIXBvp3Pj4Ov3qrWPg== X-Google-Smtp-Source: APXvYqwTmm+urFQW7pjOxBbx9/7t2JzwVkdkWvGbnbdLOdewDKVWl0hgZtCVPXpkblJB3eLewrISyA== X-Received: by 2002:a0d:f041:: with SMTP id z62mr3077059ywe.46.1572302755473; Mon, 28 Oct 2019 15:45:55 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id a6sm6317163ywh.106.2019.10.28.15.45.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Oct 2019 15:45:54 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id 5C430801065; Mon, 28 Oct 2019 17:45:53 -0500 (CDT) Date: Mon, 28 Oct 2019 17:45:53 -0500 From: Justin Pryzby To: Craig James Cc: pgsql-performance@lists.postgresql.org Subject: Re: UNION causes horrible plan on JOIN Message-ID: <20191028224553.GP23808@telsasoft.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, Oct 28, 2019 at 03:40:58PM -0700, Craig James wrote: > On Postgres 9.6 (config below), I have a case I don't understand: three > tables that can be separately queried in milliseconds, but when put > together into one view using UNION, take 150 seconds to query. Here's the > rough idea (actual details below): Do you want UNION ALL ? UNION without ALL distintifies the output. https://www.postgresql.org/docs/current/sql-select.html#SQL-UNION Justin