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 1mvp8i-0006mz-88 for pgsql-admin@arkaria.postgresql.org; Fri, 10 Dec 2021 23:17: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 1mvp8h-0006va-0f for pgsql-admin@arkaria.postgresql.org; Fri, 10 Dec 2021 23:17:19 +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 1mvp8g-0006vR-KD for pgsql-admin@lists.postgresql.org; Fri, 10 Dec 2021 23:17:18 +0000 Received: from mail-ot1-x32e.google.com ([2607:f8b0:4864:20::32e]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mvp8d-0000ZW-SI for pgsql-admin@lists.postgresql.org; Fri, 10 Dec 2021 23:17:17 +0000 Received: by mail-ot1-x32e.google.com with SMTP id h19-20020a9d3e53000000b0056547b797b2so11159935otg.4 for ; Fri, 10 Dec 2021 15:17:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=juPgLyIndTHnGBC9KTJdroIWPgoxA4b6MoMY8CO9oaE=; b=Uk5mK90Qj8SACYEBPYKQr1UmE1Z18ALfc6/YvQRo5RAOI622mGlX/aYlrQBLgO1vBu rGIcr9nOuLyuwrYME3K9pLfV6rQxVc7dGl9T2iEHwcLfZgT/IMgOGsAI0rM4wtaujbJB WqJpLemOu+fIdnghbjexXVOne5qn2QyskZNM6bqGegj2Y7Nbg8qbT0nnyjB9QaIRbvFG WuKztcX5s7BZ+LMZCwp2vOBYxHb0FP2qK6kp0EC89BgR0Pok885izACQmNaee9xhP29C SKw4HTdI6OXXeINm0BJ6Gl9RwXwAnqWKgkrFGe/kcjBhFRIbAcATskavG73T2Bt6cxVJ fEuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=juPgLyIndTHnGBC9KTJdroIWPgoxA4b6MoMY8CO9oaE=; b=WNY9cxguVmp/9UchCzX5NUq4fI+a3N9pYWm62nuIf6DNnbPil+KRPkZjtIpzOFVpM/ FslNehK+h4vXI10O5BkxefOOdfVp1X+MvFe9Buc2926rLj9PiOt/eiOIkyHwzFqNnoyN iJ+D7heUnMLtnJBfBTQc1qSvFNhzwK1h06tkrEMdQ0gZjqqzeEJtA947nl/yx7KPvTKi M1VTjRLimZiX9oJQpGvMJk0AjjCGM9vEOM0hzxyXFqolkLXl/s9JuShBoFpE00cggf/v +/5GXi5IwHLRzhYACJINzDmC98HJtbGnv3ccoZ7YjyqNnf1G/3jcoZ+RCPlEQjTFA/eF gGog== X-Gm-Message-State: AOAM531SWXpdRtfSkjYXc4L0b4PdGH63xzhsSKnskWuJxW0Oibcyt6iY O7rVS+mHrLmOS8AiI/FuBy+fR0GZDC0= X-Google-Smtp-Source: ABdhPJyiCBl2e6RFeNlYabbAgCH/z1l4HpVz76b2brEWX2NZqm1kMmYtbs3+6z26AzopvzybgGtZwA== X-Received: by 2002:a05:6830:1617:: with SMTP id g23mr13055811otr.117.1639178234512; Fri, 10 Dec 2021 15:17:14 -0800 (PST) Received: from [192.168.88.10] (ip68-11-68-85.no.no.cox.net. [68.11.68.85]) by smtp.googlemail.com with ESMTPSA id bi20sm1140766oib.29.2021.12.10.15.17.13 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 10 Dec 2021 15:17:13 -0800 (PST) Subject: Re: Very slow 101-feeling design/query.. To: pgsql-admin@lists.postgresql.org References: From: Ron Message-ID: <144f1205-22cc-b6ef-b0f9-21c7d271397a@gmail.com> Date: Fri, 10 Dec 2021 17:16:42 -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-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 12/10/21 4:53 PM, Wells Oliver wrote: > This feels very 101 but I feel like it should be much faster: > > A table "joints" with a PK of play_uuid, target_id, joint_seq, > joint_timestamp. > > "joints" is partitioned using RANGE on joint_timestamp for monthly > partitions 1/1 - 2/1, 2-1 - 3/1, etc. > > "joints" has an FK where play_uuid refers to table "plays" and > column "play_uuid" where "play_uuid" is the PK. > > "plays" additionally has an indexed column game_id. > > "joints" has 1133,932,391 rows across 12 monthly partitions for 2021, and > "plays has 585,627 rows. We made a view called "vw_joints" which just does: > > SELECT * FROM joints JOIN plays USING (play_id); > > Then doing: > > SELECT DISTINCT game_id FROM vw_joints > > Takes 35-45 minutes. Which seems nuts. We do this kind of design in a few > different plays to normalize things, but it comes at the cost of these > agonizingly slow (and seemingly dead simple) qeuries. > > Is there any optimization to do here beyond flattening table and > de-normalizing data? Is the partitioning causing a slowness here? I feel > like partitioning is creating some difficulty... What Postgresql version? What does the query plan look like? -- Angular momentum makes the world go 'round.