Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kcr96-0000cP-T9 for pgsql-general@arkaria.postgresql.org; Wed, 11 Nov 2020 14:30:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kcr95-0003LN-9i for pgsql-general@arkaria.postgresql.org; Wed, 11 Nov 2020 14:30:47 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kcr94-0003KU-SR for pgsql-general@lists.postgresql.org; Wed, 11 Nov 2020 14:30:47 +0000 Received: from mail-ed1-x52b.google.com ([2a00:1450:4864:20::52b]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kcr8z-0003aM-75 for pgsql-general@lists.postgresql.org; Wed, 11 Nov 2020 14:30:45 +0000 Received: by mail-ed1-x52b.google.com with SMTP id p93so2485706edd.7 for ; Wed, 11 Nov 2020 06:30:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=datylon-com.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=sP5lehOrTLw+TuL5Uyf0D3PlrHG8der5Vd1rPg57xiw=; b=0Ilvs6UPgIYrZkAZrvuuLEQ+GkLhpfTPBnndRP1lDGxf1GKuVxhSh+veZywFYOCqBs vEDBNQ8JAKU8vMIwNaWsNBGUqaNTo5sAxY/n2HY+vk057EnWTGJ4+WQOuQNrll/BzRHj 8ZTn18keA8TkNmqfpPxZGS+agyfC1TwndlvdUoCg5YhiU/Xj10pKNvx4C3T0RHrd3ZPS xR7J0kM4EZjd96GKyNCsUe9Eb/CKpK7tnEkvA2uu54kV6U71mh53Q/7iHofa/c9XUTD1 oAbNIp++cIAmXQW+yb/a4F/jA8y5alMulq1QAq3EEKM4KsAYuHNLY9YdclydgIoELE/W M3lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=sP5lehOrTLw+TuL5Uyf0D3PlrHG8der5Vd1rPg57xiw=; b=tXsXDHPY8Bn49QF/Sd2HMsSffslFK8BAzSgwrn7g/Hgg/5WYgUm45maIX68DnnpkL2 zl8mVs1S+ZTKSG5zAj+6wQTe8do0YXXYCJuIgqxUpNQm8xlJ+xIFRXfiXNtrCR1d8kpl HLTlqXHtPZoMmEWNK3WQXxKW6ABlhNYvgjclf1wJq8hfpnbgW8bcv9NXzV8Z3H9zHpou EHuK0jPwPa3FShIycoHAx9J3MF+xs87ypzGfCl2u9o1NQyeQq1RQaj41eJfktKLjhMXX 3JyS29yS7EB0TV2FsJwE3OMwU45dQynhIqEcr9QJZAfDgMkz9LxDgezsngQ1m3A3pPHq cObQ== X-Gm-Message-State: AOAM532sFAmYK1cQvZTr9xg5B2W2qjLL0K8R+ymjkk5L3EnF3ega5q80 scpRUmvcoAtcXlHgDIsTR8iFBQ== X-Google-Smtp-Source: ABdhPJzf0j7mjl3uKWavw576so2C15slULjKm6i+VOA68FUb57e75tmpNAKmALG1qCEHnTQXuSRD2g== X-Received: by 2002:aa7:cb4c:: with SMTP id w12mr5200133edt.309.1605105039646; Wed, 11 Nov 2020 06:30:39 -0800 (PST) Received: from [192.169.1.6] (84-198-87-90.access.telenet.be. [84.198.87.90]) by smtp.gmail.com with ESMTPSA id b12sm992999edn.86.2020.11.11.06.30.38 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Nov 2020 06:30:39 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) Subject: Re: Execution plan does not use index From: Peter Coppens In-Reply-To: Date: Wed, 11 Nov 2020 15:30:37 +0100 Cc: Pavel Stehule , PostgreSQL General Content-Transfer-Encoding: quoted-printable Message-Id: <96DF1F02-C91B-4960-87C4-4E3BA2EC594A@datylon.com> References: <1C729C96-97BB-46CF-9457-876DCC395923@datylon.com> <64AAA8DD-FD2F-4DFC-BDA4-109C024609B1@datylon.com> <70D29A79-C968-4310-B4D7-3203A739F261@datylon.com> To: Michael Lewis X-Mailer: Apple Mail (2.3608.120.23.2.4) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >=20 > Ahhh. You don't have a single column index on the timestamp value or a = multi column one with timestamp first. No wonder the subquery didn't = help. My apologies for not realizing that before. Thanks for satisfying = my curiosity why it didn't perform like it should. Certainly, that index = may or may not be worth creating and maintaining. Indeed. Typical queries use both device id and a timestamp range. Only = in some queries more than a few devices are needed. >=20 > Obviously the 3 days worth of data is also too high (just quick and = safe). Depending on what your server timezone vs the the most divergent = timezone on a device, that could be tightened up. Regardless. If the 5 = seconds runtime you got to with the correlated subquery on the where = clause is sufficient, then no need to continue I suppose. Yeah, I am ok with the performance now. The overall query where this = was extracted from (and which had multiple full table scans) went from = more than 2 hours to 30 seconds. Given it=E2=80=99s a daily =E2=80=98async= =E2=80=99 report that is sufficient. >=20 > It seems odd to me to not do any basic adjustment of random_page_cost = though. It isn't a magic number that the core team know to be perfect. = It is a baseline that is likely to be quite different for each use case = and server config. While there are no hard and fast rules and absolute = right answers, it seems prudent to at least follow the advice of the = community and lower it a ways if storage is ssd style and/or cache hits = are quite high. Ic. Well I don=E2=80=99t mine experimenting with it, and will certainly = remember it next time. I guess I was demotivated because I read lot=E2=80=99= s of warnings but these might have been about disabling sequential scans = and not about page cost settings.