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 1iW0Gx-0006Ya-Kl for pgsql-general@arkaria.postgresql.org; Sat, 16 Nov 2019 15:46:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iW0Gw-0004l6-10 for pgsql-general@arkaria.postgresql.org; Sat, 16 Nov 2019 15:46:02 +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 1iW0Gv-0004kz-Gt for pgsql-general@lists.postgresql.org; Sat, 16 Nov 2019 15:46:01 +0000 Received: from mail-oi1-x231.google.com ([2607:f8b0:4864:20::231]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iW0GR-0002pA-D7 for pgsql-general@lists.postgresql.org; Sat, 16 Nov 2019 15:46:00 +0000 Received: by mail-oi1-x231.google.com with SMTP id v138so11386730oif.6 for ; Sat, 16 Nov 2019 07:45:31 -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=dhd4UW6t3gCKdGsApMIP1zhsFSq2llLNhDoeZBI/Ztc=; b=KdX49RPPS6T1tTyVzxUrIVZVH7GbYXRUqSOhTH0jJ7IOIsD1u1DgWewi7tq1d2WJuT UPQclmYU9a8Qd9ekDIFUiniHjhSN5I/74iEuY4O45DMDeTTPLWMGu8OHqs0Oa0PDs6/j oXQyOUlOo+IJcu0hN37wU2H1aWtt7wLQZ74n3IKZx4MUqBymbWEOa1PrxMd844GsgHov +tfGlDZPR5A7SLLiSKufdRvl3o71vajk/ESpl6Ec4pNWSSSU9qz3O6E0h3uOJ5AIpS1+ 5GkBzCegAYUH1NTWtEKrx+XXluKVBs1hdRCauvS0ibcJiKPuxbY/vlIj39UpWJXjxE2b rcBw== 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=dhd4UW6t3gCKdGsApMIP1zhsFSq2llLNhDoeZBI/Ztc=; b=TsT32GZUR/m0UrbRg0jjXBEGh1+J5650x6NCQSMI/lEtRNhcvnh/ldEdFrGklDdcER jeMZslqQJHRN7/+a6fsS1cW9A33JgG1doP7Z4+MB3q6kZ0SgvqVvCHVkmEj5OvHLccYz ml8WoNeuMg6cBZzurRTkkq2P/Ta/O7mm7wtiI3GzyN9R6zIJPfKYJ2lFNxlQxq4/xr8j IHe0GKWzxA1BCSmrhHwOtN3Lz1oklm2cUoSLDE+6oJVglMcyDA+k3grsqKO2fAu80id0 YYJ1bPz32+XgRd3/dbGpf4TpMgyA2cL+FNA601eIRxia1wrSbNvrj8pb4nsDn4Nw440b 1vZQ== X-Gm-Message-State: APjAAAXnhKkXUnbdG+yiXyxagKmWE/wWF+BtkY8iAkfHwHE4oMPUwnFl H3eLkKyzu7vtGDCMH1XffRfLJ/O4LIk= X-Google-Smtp-Source: APXvYqwj/UxPwyCJyQVOxUPiJMY1k7ahwoTnDNKFpStGBxS2K60SEO/dCDFERuFKtQjUYHSg/Se+6g== X-Received: by 2002:aca:f141:: with SMTP id p62mr12504188oih.3.1573919130266; Sat, 16 Nov 2019 07:45:30 -0800 (PST) Received: from [192.168.1.10] (ip70-186-126-197.no.no.cox.net. [70.186.126.197]) by smtp.googlemail.com with ESMTPSA id k18sm3959007oij.32.2019.11.16.07.45.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 16 Nov 2019 07:45:29 -0800 (PST) Subject: Re: Function performance degrades after repeated execution To: pgsql-general@lists.postgresql.org References: From: Ron Message-ID: <7f0d6a8b-bf7e-a2bb-a248-62239c67fee8@gmail.com> Date: Sat, 16 Nov 2019 09:45:28 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 11/16/19 8:22 AM, Dave Roberge wrote: > Hi, > > We've been troubleshooting a slow running function in our postgres database. I've been able to boil it down to the simplest function possible. It looks like this: > > FOR rec IN select 1 as matchval FROM table1 t1, table2 t2 > join table3 t3 on t3.col = t2.col > WHERE t1.col = id > LOOP > IF rec.matchval > 0 THEN > co := co + 1; > END IF; > if co % 100 = 0 then > raise notice 'match value %', co; > end if; > END LOOP; Where are you joining table1 to either table2 or table3? -- Angular momentum makes the world go 'round.