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 1go6aP-0007P3-Sk for pgsql-general@arkaria.postgresql.org; Mon, 28 Jan 2019 13:04:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1go6aO-0000QU-6u for pgsql-general@arkaria.postgresql.org; Mon, 28 Jan 2019 13:04:24 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1go6aN-0000QN-T9 for pgsql-general@lists.postgresql.org; Mon, 28 Jan 2019 13:04:24 +0000 Received: from mail-ot1-x330.google.com ([2607:f8b0:4864:20::330]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1go6aL-0003HQ-BL for pgsql-general@lists.postgresql.org; Mon, 28 Jan 2019 13:04:23 +0000 Received: by mail-ot1-x330.google.com with SMTP id 81so14541224otj.2 for ; Mon, 28 Jan 2019 05:04:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=aC3bzJBrcOghFSan94g5BlxIA2TauvOsJYCiJVlK8gM=; b=WVeOCckAlk01AWU8P1EPXy22e/ftkrfP1Avi8DhXa9L5WBBiYfVeVRt4q1Mum3zCMX /EQ+Pf92LVn7C0uXa8R35Ur8wDmT5rtQfhV02hEPo0XWgaBHrGWZnCIHqTm5mPinGv6d G+YOUZTqFcSDA1OzJvEQXGk0nL7qM4ToLXuO0LKBUfhad53BWNIiso6a/72C5ku0Ss8p 22/xlW7ZrvezkeJgdkRkr9JGRRwOuNhqjfTAnhYu6Ey1lr/xLYS1tpaYtTBqKj+Ze8kC R6IYcXEnM8EiuviJ++cB6e/GhnZCuKKIYFiD3TtC4Ep4L1D/NnKNv+O+l8IibLbQRFSn JxBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=aC3bzJBrcOghFSan94g5BlxIA2TauvOsJYCiJVlK8gM=; b=tEdjBLSKa8B5ijvssv4Z176dhWHsOGAHNlOviadnLj+6e80jpY9bX51roLuKpUK0l+ 7dTqJOCoS5gb9P1wZggdgKK6QJkryltYkARWYiXsyXkA4n8iuBqFdIdUPPuHvgOBvt6C GOwqsT5j5HZroPqAsnpcNrhRwZhWMrNn+b0+GklbvnhDiUno0gsyMMsVXEFBrNHPoOnL /O8wvD9RyLK9tkzFM2/g0echdrCzk0kv+P3/Ynngl8NHFpV/5/O3+ofbPtrZusckMAYK gVW6/qbiSCrtC6VkKBSSh5IS/x1UsbUrj9hh3CEtxcBjJKqs+Kp9HGY5APfZWJBbSBu1 rdew== X-Gm-Message-State: AJcUukd6jPWuHdoFMRJrftVN/pyZJilXf8B9MP2jKY7kN9cuYy1VZp2w OT66xS/Fv36mdAhsdv7Z8Xm20gJj X-Google-Smtp-Source: ALg8bN4rwKFfjK0qPmz0kbKVhGVjuAD3c4rwpZwT2+i/XSxycqEjhSWMr9umTz9KjywH+T/dvMh4SQ== X-Received: by 2002:a9d:6f8e:: with SMTP id h14mr15647603otq.241.1548680659013; Mon, 28 Jan 2019 05:04:19 -0800 (PST) Received: from [192.168.1.10] (ip70-171-116-89.no.no.cox.net. [70.171.116.89]) by smtp.googlemail.com with ESMTPSA id v3sm6147666oib.57.2019.01.28.05.04.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 05:04:18 -0800 (PST) Subject: Re: Regarding query execution for long time To: pgsql-general@lists.postgresql.org References: From: Ron Message-ID: <041e270e-2426-4b33-682d-231057c7c71e@gmail.com> Date: Mon, 28 Jan 2019 07:04:17 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 1/28/19 6:20 AM, Durgamahesh Manne wrote: > Hi > > below query is being executed for long time > > Select > distinct ltrim(rtrim(ssnumber)), CL.iInsightClientId, > ltrim(rtrim(TFA.client_account_key)) as vchAccountNumber, > concat(TFA.first_name, ' ', TFA.last_name) as vchAccountName, > concat('AP:TIAA', TFA.routing_number) as vchRepLabel, > null as vchOpenDate, TFA.address1 as vchAccountTiteLine2, > TFA.address2 as vchAccountTitleLine3,null as vchAccountType, > TFA.address1 as vchPrimaryContact, 'TIAA-CREF' as Custodian, > TFA.routing_number as vchCustodian_RepId, null as vchCustodianRepName, > CONCAT ('TIAA-CREF:',ltrim(rtrim(client_account_key)),':', > ltrim(rtrim(ssnumber))) as vchAccountKey, > null as vchFeedsAccountType > from accounts as TFA > join client3 as CL on ltrim(rtrim(Cl.vchssnumber))=ltrim(rtrim(TFA.ssnumber)) > left join account3 as AC on > ltrim(rtrim(AC."vchCustodianAccountNumber"))=ltrim(rtrim(TFA.client_account_key)) > where AC."iInsightAccountID" is null; > >  query is being executed for long time even after i have created required > indexes on columns of the tables > please help for fast query execution I bet this is what's causing your troubles: on ltrim(rtrim(Cl.vchssnumber))=ltrim(rtrim(TFA.ssnumber)) The query optimizer probably can't use indexes on those tables. -- Angular momentum makes the world go 'round.