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 1mTF07-0002wv-WB for pgsql-general@arkaria.postgresql.org; Thu, 23 Sep 2021 03:02:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mTF06-0002nI-V6 for pgsql-general@arkaria.postgresql.org; Thu, 23 Sep 2021 03:02:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mTF06-0002n9-Lz for pgsql-general@lists.postgresql.org; Thu, 23 Sep 2021 03:02:18 +0000 Received: from mail-qt1-x82a.google.com ([2607:f8b0:4864:20::82a]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mTF04-0008RW-AY for pgsql-general@lists.postgresql.org; Thu, 23 Sep 2021 03:02:18 +0000 Received: by mail-qt1-x82a.google.com with SMTP id u21so4875185qtw.8 for ; Wed, 22 Sep 2021 20:02:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :references:from:in-reply-to:content-transfer-encoding; bh=514+XXnPKU8q8nOPTP1HJp+Z7NkpnjhKALMtWWW1c2I=; b=ZzFK+Xb6o+S0jE3YHl0tnXQzKewzvwUX6MwRuYnRqUWuu55WuDK3EcSM879IT6bglh wk6CLDTVgqq+1PKywm6G8HxWqw9sUI0SMSVJreMOw+S32ZVhE35lZ2OPxz1/pUudK3B4 /z2iNSMOGZEkrOEZDsXUeex1dO/LDfF1b18b8ZxS4On19lvYv1ucKX52FlxPSZluRlCb vkE14mFZcHFwgvjHQcZ+br0yCy6oDrl8XR5WG7h0W6oOIZxKO+bK63hTdGlOum8LyK8P E9wOQyG2f5XtBDSxOz1rvtLaz/LWDEB84BqMcxdPUWnLHIFdOeole1xM213AtEqBb4KK eGIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=514+XXnPKU8q8nOPTP1HJp+Z7NkpnjhKALMtWWW1c2I=; b=DaJMXaV7NkeHneSP9zY3qkmwo/Ylcl8ax9bQfS0a70mFbhSn5hkjwcXN4kC+XH10dj OO1IRw70ridmxV4uLnKkXq87kCyhbUnusU2blZMESX8mXfXZO7Fj2Y7z0TcRifSsT0Ou 2aiHyR/esrMSTk5CbvKIvIJ8FX7LhXkQPTm2y3kOUMBOocRX5Cx1i6K69dMRX5DI1j8S kHC+V5AKZZdwVpb4yOw01KWZQI2XxUvc/qnbuQSDU/UQ1/SCDuokEAlaktXxOj6QTMoL 3FCPj54F8apJfm/MCcCOooxl1jhvihHb0EWpuCSYG134Ft17X+TSLz6JjTa5K8Jha/Io n1EQ== X-Gm-Message-State: AOAM531AuwK23KW6WgR6IGIAAf9cknOtxENaVFn2yowNb3XIJeJ77Esa Z31AF0YDr2DzbXBdFXx1MJSEwr9zScRXg98o X-Google-Smtp-Source: ABdhPJx1M9BYUgn7lk2Ou4jQiNklyKmr2UJ1IPXJV8YHTfJQRdjponMIjxPYHjbXC9oxxepQbm4ylw== X-Received: by 2002:ac8:13c4:: with SMTP id i4mr2670098qtj.350.1632366134021; Wed, 22 Sep 2021 20:02:14 -0700 (PDT) Received: from [192.168.2.100] (pool-72-79-19-93.nwrknj.east.verizon.net. [72.79.19.93]) by smtp.gmail.com with ESMTPSA id o4sm2844158qti.24.2021.09.22.20.02.13 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 22 Sep 2021 20:02:13 -0700 (PDT) Message-ID: <135cb451-c8d0-28ed-f563-0bd3bf2f2438@gmail.com> Date: Wed, 22 Sep 2021 23:02:12 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.0 Subject: Re: Faster distinct query? Content-Language: en-US To: pgsql-general@lists.postgresql.org References: <0BB059BF-54BD-46FA-8B26-28FEF9A04198@alaska.edu> From: Mladen Gogala In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 9/22/21 16:20, David G. Johnston wrote: > I'd probably turn that index into a foreign key that just ensures that > every (station,channel) that appears in the data table also appears on > the lookup table.  Grouping and array-ifying the lookup table would be > trivial.  Either modify the application code or add a trigger to > populate the lookup table as needed. I fully agree with this. Adding a trigger to populate a lookup table is a standard design in situations like this. Using "DISTINCT" almost always spells trouble for the performance. -- Mladen Gogala Database Consultant Tel: (347) 321-1217 https://dbwhisperer.wordpress.com