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 1kEJO1-0003yc-US for pgsql-performance@arkaria.postgresql.org; Fri, 04 Sep 2020 21:36:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kEJNz-0007Md-AJ for pgsql-performance@arkaria.postgresql.org; Fri, 04 Sep 2020 21:36:43 +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 1kEJNy-0007MW-Td for pgsql-performance@lists.postgresql.org; Fri, 04 Sep 2020 21:36:43 +0000 Received: from mail-ej1-x644.google.com ([2a00:1450:4864:20::644]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kEJNv-0007v9-EK for pgsql-performance@lists.postgresql.org; Fri, 04 Sep 2020 21:36:41 +0000 Received: by mail-ej1-x644.google.com with SMTP id m22so10385496eje.10 for ; Fri, 04 Sep 2020 14:36:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=eodNvgXN6FF+qIxaPhQW4FPlhte2Mxedz6Pcb7wTgyw=; b=VkLpGETYQu8KmD7galmuw8bA4BYm9ZFgFw/ruoVL5vHoku3FxpcGZMo+Ovk+BlpmA1 BvZ53XrryGIFldp9NNl9DOuRPZYzqzGCjCNfn80VsOSTNhyo98b7gmnoXmr3LtwQfLPW BXJJILH1dlANjpSNMFzQV0mB9baBBIBRZmGGSSAGoH79s4GKetWZYsCEuVVXE8CE92Gb /qZHuwdPGz45Yi0ef07Wg6tEr31ERgbDMWlhJNCZzOO1rtfdjkK7KO+RInUispfklqMz JPAQILd5Sl0cgjQ01AV0KTA78wO3LEUf6v9BCKaA1xRphUBHjUVTGsmWUqDSGUI4/3SI lE1Q== 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; bh=eodNvgXN6FF+qIxaPhQW4FPlhte2Mxedz6Pcb7wTgyw=; b=Gl0QIeNuJANQzS59SnbLziZf+8pHbMa7By8BRzofP5S5UWxD/zSLsUQ1yIz4vPXEDo SVwsvHma45xjT8oAee9qEKCc+v3LrivNHb5P3/Y4F2jFTmGhIAhZ3h0QKdYZyQKjZ5+8 kygqYgAfasv0y1E0PyeN4RdGm8r3LODZBSqmiiYZL40m6qltYLMplOcAruMwd7s2LdXS ElKsRbbPE/7mfloEkhtv13j37sTAZXOSTSr7EbaRU51ALzO3BZHqdlEUnVv1hLGtjmjm feblMMIiM/3/XJ7RBv//1nrhy/OtYQNsQTXb27HlCkpjJX6yK4ahtsfNIX6Cc7ZS0jZ4 7PwA== X-Gm-Message-State: AOAM530byT1Hi6l62oXWXWq+8AasEiiPhHFIoLNV3q3ywi6/k5gcdbE0 V0K6qiD1QGV+ojlU44IrWCjY0w== X-Google-Smtp-Source: ABdhPJyt7/a9OGCuJDdCq5IyzpsRM2qgNQRyp+JeWntuf0roPYh3RAXQYoDd3Zdhm7akbgWfBpwyRg== X-Received: by 2002:a17:906:69c1:: with SMTP id g1mr9268913ejs.285.1599255397784; Fri, 04 Sep 2020 14:36:37 -0700 (PDT) Received: from localhost (ip-86-49-253-216.net.upcbroadband.cz. [86.49.253.216]) by smtp.gmail.com with ESMTPSA id g90sm7768373edd.64.2020.09.04.14.36.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 14:36:37 -0700 (PDT) Date: Fri, 4 Sep 2020 23:36:35 +0200 From: Tomas Vondra To: Nagaraj Raj Cc: Pgsql Performance Subject: Re: Query performance issue Message-ID: <20200904213635.hvz2pxmmj3tatv26@development> References: <975305787.3395625.1599254321500.ref@mail.yahoo.com> <975305787.3395625.1599254321500@mail.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <975305787.3395625.1599254321500@mail.yahoo.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, Sep 04, 2020 at 09:18:41PM +0000, Nagaraj Raj wrote: > I have a query which will more often run on DB and very slow and it is doing 'seqscan'. I was trying to optimize it by adding indexes in different ways but nothing helps. >Any suggestions? > 1) It's rather difficult to read the query plan as it's mangled by your e-mail client. I recommend to check how to prevent the client from doing that, or attaching the plan as a file. 2) The whole query takes ~3500ms, and the seqscan only accounts for ~200ms, so it's very clearly not the main issue. 3) Most of the time is spent in sort, so the one thing you can do is either increasing work_mem, or adding index providing that ordering. Even better if you include all necessary columns to allow IOS. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services