Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XFX0T-0006hW-9E for pgsql-performance@arkaria.postgresql.org; Thu, 07 Aug 2014 23:22:01 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XFX0S-0001lL-OP for pgsql-performance@arkaria.postgresql.org; Thu, 07 Aug 2014 23:22:00 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XFX0Q-0001iR-V7 for pgsql-performance@postgresql.org; Thu, 07 Aug 2014 23:21:59 +0000 Received: from mail-wi0-x22f.google.com ([2a00:1450:400c:c05::22f]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1XFX0N-0001IC-Ub for pgsql-performance@postgresql.org; Thu, 07 Aug 2014 23:21:57 +0000 Received: by mail-wi0-f175.google.com with SMTP id ho1so153729wib.8 for ; Thu, 07 Aug 2014 16:21:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:content-type:content-transfer-encoding:subject:message-id:date :to:mime-version; bh=66ijhQPrGlea8AKng2R4qVHPscrpHtaelwAUMcAQ7TA=; b=kNWnCr267EFpOyl41t6EvJ7ZHKmzEoJdU20gO1wKx+YANPdP6l3qOrrVSg+Dc26sBs V9sIbhl3EZgIJbPi7umqHVvfHCdSavUMNqefcxKxOQLKk0uIs468NQypx7mdFKXutTs/ cHDylnK+1kB7KKGSXER0X47BUAgYd4ANr/Far7z8Pvp7zI2WYvFJtHk72ni4xS6mNCOV FaJcnktav1HAMdxDpBhLT3mo3+4uScUSdMdXquqNKYhnm3s6rDIvSyXGd/zASl5kd+2m ZEoR6EKGpmmILbxjq0zqCMiTw+PlLQAiJxiGdtgzG4Xn2geIUDFGrpECeLc8FmenR4HM FL6g== X-Received: by 10.194.62.140 with SMTP id y12mr27996686wjr.27.1407453713970; Thu, 07 Aug 2014 16:21:53 -0700 (PDT) Received: from [192.168.1.4] ([178.124.207.68]) by mx.google.com with ESMTPSA id fb8sm1089027wib.15.2014.08.07.16.21.52 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 07 Aug 2014 16:21:53 -0700 (PDT) From: Evgeniy Shishkin Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Subject: two table join with order by on both tables attributes Message-Id: <8501437C-8756-47B8-8691-CFD97717ACBB@gmail.com> Date: Fri, 8 Aug 2014 02:21:51 +0300 To: "pgsql-performance@postgresql.org list" Mime-Version: 1.0 (Mac OS X Mail 8.0 \(1971.5\)) X-Mailer: Apple Mail (2.1971.5) X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org Hello, suppose you have two very simple tables with fk dependency, by which we joi= n them and another attribute for sorting like this select * from users join notifications on users.id=3Dnotifications.user_id= ORDER BY users.priority desc ,notifications.priority desc limit 10; Very typical web query. No matter which composite indexes i try, postgresql can not make efficient = nested loop plan using indexes. It chooses all sorts of seq scans and hash joins or merge join and always a= sort node and then a limit 10. Neither plan provides acceptable performance. And tables tend to grow =3D\ Can anybody suggest something or explain this behavior? --=20 Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance