Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t6kNh-00FFJx-Vg for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Nov 2024 05:39:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1t6kNf-009d8k-Uj for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Nov 2024 05:39:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t6kNf-009d8b-II for pgsql-hackers@lists.postgresql.org; Fri, 01 Nov 2024 05:39:31 +0000 Received: from mail-vk1-xa34.google.com ([2607:f8b0:4864:20::a34]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1t6kNZ-00485Y-A0 for pgsql-hackers@lists.postgresql.org; Fri, 01 Nov 2024 05:39:31 +0000 Received: by mail-vk1-xa34.google.com with SMTP id 71dfb90a1353d-50d57c109d5so519652e0c.2 for ; Thu, 31 Oct 2024 22:39:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730439563; x=1731044363; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=FByR6pnN6abfZIUqiob8J6kDSRpYFrIO31HMfvfvhB4=; b=a0Nrhd5HSoNLL3ehiWiSLFz2YVecG5mmVAj4a+MI6H+g7u4j2a+LJDjmppjgDFhTDp p+9gPzKKjB/483AK4tg5a5UUOqRr20UWwOV92GNPqDaDAkIx8mqCJjdXecAx/MSpHOsL c/GUm6LrWnJhhILkG/9TwcN0Q7yGq/uHzEYPAq6yWV5h7aNfoPj25faksz2kGBNlXMU/ ewb8msXcjrSb3lJDNUKkV1NLrB0MgzVtugS8sW2erX5wmYS0l5gbZNC9kJi2PUFX+kyB HEn5JRf+d9V3526gKpP/H1FjdYkuWztZdHBjrpmnwdhsS1//mOh9+6sJyrwp3LO0xyUB jb5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730439563; x=1731044363; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FByR6pnN6abfZIUqiob8J6kDSRpYFrIO31HMfvfvhB4=; b=pxdHcGguZTcYsWFd8FE6OfUW/rpsJF0UP1mg46DLoEcpN5TF/ekzCYB+p5kpwX0rfW ZWpW4MHqhKqXhLerFMZ/vopMZGG24Y5kW+csHl/0GlIA9/ejTeGzWVvgJ3XaEvgsNfHv g56T0altg7O/9msU211rd2e9eakDZtKVnY3wxdkETaPnFDHZ+CRdSfr60nsAct351Rp+ bThSHDUdJoAqiLAsjtOM8Hrlz1RjZhgCg3sYkKKVfiQClcdEE89TBjVmm64MwR+ZJyV+ hdjCtXozAyP3nPTsscHjCVxSFOyg1bAJIMXMfcKFccRUwO17tmyxLCRnzFvlVzC9JcI9 /J+w== X-Forwarded-Encrypted: i=1; AJvYcCWZQiKaCPsQK5df4g9KPZvZcC5sDd5XuXX+sKeQKsu//iUaBit9wmB3AvC69bLbeoorg3ynaLT32GXXPfhH@lists.postgresql.org X-Gm-Message-State: AOJu0YzrpNjJ800LCTRWAnLnmv6PMXZ5E17AhEKJNon4jfWwhKZw4hCK ua1it3uowA/XzadsgDz9ciRXIf1JRtBYGNkJBoeKoF+oDtQRFQO+PHfiQLYQfVmpY9cVHOFtSHO 7WLJzpQPDpUo2F6x4xYHsv4XgDYM= X-Google-Smtp-Source: AGHT+IFKt/IYeGWbdNvBro/8ExR4eAdafsvmej2veMAtXMITJ0hQYZEGhdRtqPFOsQHtExXKsLVJPxzXSKvk1ckrrzk= X-Received: by 2002:a05:6122:2502:b0:50a:b604:2bb2 with SMTP id 71dfb90a1353d-512275639ddmr2321435e0c.11.1730439563116; Thu, 31 Oct 2024 22:39:23 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: jian he Date: Fri, 1 Nov 2024 13:39:11 +0800 Message-ID: Subject: Re: Wrong result when enable_partitionwise_join is on if collation of PartitionKey and Column is different. To: Amit Langote Cc: Junwang Zhao , Tender Wang , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Oct 31, 2024 at 9:09=E2=80=AFPM Amit Langote wrote: > > > I think we should insist that the join key collation and the partition > collation are exactly the same and refuse to match them if they are > not. > > + { > + Oid colloid =3D exprCollation((Node *) expr); > + > + if ((partcoll !=3D colloid) && > + OidIsValid(colloid) && > + !get_collation_isdeterministic(colloid)) > + *coll_incompatiable =3D true; > > I am not quite sure what is the point of checking whether or not the > expression collation is deterministic after confirming that it's not > the same as partcoll. > > Attached 0002 is what I came up with. One thing that's different from > what Jian proposed is that match_expr_to_partition_keys() returns -1 > (expr not matched to any key) when the collation is also not matched > instead of using a separate output parameter for that. > i was thinking that CREATE TABLE part_tab (c text collate "POSIX") PARTITION BY LIST(c collate = "C"); maybe can do partitionwise join. join key collation and the partition key collation same sure would make things easy. about 0002. Similar to PartCollMatchesExprColl in match_clause_to_partition_key I think we can simply do the following: no need to hack match_expr_to_partition_keys. @@ -2181,6 +2181,9 @@ have_partkey_equi_join(PlannerInfo *root, RelOptInfo *joinrel, if (ipk1 !=3D ipk2) continue; + if (rel1->part_scheme->partcollation[ipk1] !=3D opexpr->inputcollid) + return false;