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 1mTSDE-0004xO-RM for pgsql-general@arkaria.postgresql.org; Thu, 23 Sep 2021 17:08:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mTSDD-0002Hi-QJ for pgsql-general@arkaria.postgresql.org; Thu, 23 Sep 2021 17:08:43 +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 1mTSDD-0002Ha-Hg for pgsql-general@lists.postgresql.org; Thu, 23 Sep 2021 17:08:43 +0000 Received: from mail-il1-x12c.google.com ([2607:f8b0:4864:20::12c]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mTSDB-0007FR-7n for pgsql-general@lists.postgresql.org; Thu, 23 Sep 2021 17:08:43 +0000 Received: by mail-il1-x12c.google.com with SMTP id m4so7362656ilj.9 for ; Thu, 23 Sep 2021 10:08:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=FDTY3yHvglC5avUI5l3c2L7jan9Me1YN0YNq2DziLzU=; b=Hpm2KZUd5lI02OO5DsE9b+HhrbEvYfOqb+Zmg7DymyEoFXDQQYiPaWAif6ecWAU/dW EbrqvV99zlc2z15jSZrENrollUZ6hGuOb5ytOEyLFxoHDXOVu/rCoMYvLjoOYI0cfdSX 9J6wJyqJhwFP/LjtinwOFPFMk4c3ZG7+hXQ0/IpuDOcVuFHZLC743pSQSd8bMBN85rKu 1nTEGqp2qwcoI1Dc6e89dKN/w+upXku6myCzqCo4O0EH86i1wzpddr4SK4pHMVF7NM+1 O0OC0j10kNXadGfylYqLXM2aEzvqMeC1nUN2UmxSbRPITBJ6Td6xThi8A/z+gP6t6S+e UMZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=FDTY3yHvglC5avUI5l3c2L7jan9Me1YN0YNq2DziLzU=; b=YnrWJQHuRIZyv+EBhE8Jjxb8vtBUrrSWNph4axH+1EWdobjh5ei0YPSeufIe/RhKt/ yDKay+svLlI3EP0XTloh7BDIgzQ3KcdOI34lAyJbIhUElEqQkkiYpbm1ScxE4zdDmvsE mKMiWr94grLPdTz6RJSgEADdhV8uRGofPxtjphmPA5LylbOtHVYyJx0SjUizuHJ7apJ7 4T3DL3k7KmXxxLw0vOfIm43c69dbegx08BvSLWGQAqUW6vmgoW9IQ049Xbk8v6q/Tn4z hnxziAFcyth0pRD74qsfoNj94ANwnMhTitR2xXuWZUwI7KxSCaUbojg2PN86kuIfeiC9 CCjQ== X-Gm-Message-State: AOAM532WCspG4FHUAJKnwDHyRVzRiLO8ACpNQ1ro0qfOu55SQ4i+qa1k uwzaS3foAZbQ/3461OSYZfkWeAqoyTE= X-Google-Smtp-Source: ABdhPJw3chAcGAU9GvzWx/0ZbilwaVfQX/5RjRFAeGp+B1wPPC7U1v2DF8QPfiYRCsL/EYzCVMWvVQ== X-Received: by 2002:a05:6e02:1d06:: with SMTP id i6mr4222971ila.299.1632416919763; Thu, 23 Sep 2021 10:08:39 -0700 (PDT) Received: from ?IPv6:2601:681:5500:dde0:fc4a:45a4:3592:943d? ([2601:681:5500:dde0:fc4a:45a4:3592:943d]) by smtp.gmail.com with ESMTPSA id d14sm2815191iod.18.2021.09.23.10.08.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Sep 2021 10:08:39 -0700 (PDT) Subject: Re: Faster distinct query? To: Israel Brewster Cc: pgsql-general@lists.postgresql.org References: <0BB059BF-54BD-46FA-8B26-28FEF9A04198@alaska.edu> <20210923070435.GB8425@depesz.com> <0BAB9A86-3C6B-4591-B557-27501919843E@alaska.edu> <670727da-f703-bbd3-f239-9e208130b1f0@gmail.com> From: Rob Sargent Message-ID: <13e62549-ffa1-712e-39f4-cfc42aaf25e3@gmail.com> Date: Thu, 23 Sep 2021 11:08:38 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-CA List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk I would look into pre-loading the lookup table (and pre-emptive maintenance).  Add the foreign key, but not the trigger. > > That makes sense. Thanks! > Yeah, then I got to wondering: Do you care?  Are these stations likely to be spoofed?  You have the station id and type in you data table and essentially the same in your lookup table.  If you're not replacing the id+type in your data table with a lookup id you really don't need to even have a foreign key.  Maybe sync them regularly but I'm not seeing the value in the runtime overhead.  Now presumably the station table is entirely pinned in memory and foreign key check might not be much overhead but it won't be zero.