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 1izzZ1-0000SY-9x for pgsql-hackers@arkaria.postgresql.org; Fri, 07 Feb 2020 09:04:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1izzZ0-0000qm-21 for pgsql-hackers@arkaria.postgresql.org; Fri, 07 Feb 2020 09:04:38 +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 1izzYz-0000mE-Lq for pgsql-hackers@lists.postgresql.org; Fri, 07 Feb 2020 09:04:37 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1izzYt-0006ro-89 for pgsql-hackers@postgresql.org; Fri, 07 Feb 2020 09:04:36 +0000 Received: by mail-wr1-x441.google.com with SMTP id y17so1703728wrh.5 for ; Fri, 07 Feb 2020 01:04:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:in-reply-to:references:comments:mime-version :content-id:content-transfer-encoding:date:message-id; bh=Cz9eIpmUQuwB6X6xCZYfCvyFJONH/UaOz07MXRfbyA0=; b=Z1CocUr1ecIrtmQcbx9cgTaYqpynWR+L20m7RtcxWsnd+LBSUPuvXKbVaEkmJZS7vn GUL3dRgtO384ULcdSchJGird4xV57uTjcb5ZPb2U/BVbTzxYRFlkzaXMHDjqmzhMa8eP 2aXPmG0A3EoF5FmJPFiA0ld6KAWNwRlUMnkkYd08UJ+EmIgwned5vmzbeXUEeoMXYDIu /5U6ZVNl36Q6S8z5/xR67Nu1Gij+EJtxLPF0BtRoftUREnXF2otrasVSGT5l+A5D24wY wm4XEtj4s14F0gcoTWkve8sM1zrG4wZkTd8MeBhdMosLoP0zBAqdMP2iySpX/F8evgf9 erRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references :comments:mime-version:content-id:content-transfer-encoding:date :message-id; bh=Cz9eIpmUQuwB6X6xCZYfCvyFJONH/UaOz07MXRfbyA0=; b=K0y6eRcDga702/81SAUUBMYLD52LuTglfpa0B8TKu3D9DjRUcBb5EPeKAz0h4XQpY5 UDaqII33qzKoio+ohm/YqX8oxCAG9YrSbxQVkuHac0RNc4kzTIP+Muyx0e5/ZxWlNAwE Uaj2IUMkF0Llzt9MEHlkFLrDKJ8iLVrJ90lbI5+TrM/k5lmfSrv20elk4SEsMutCLMx/ UxYgA2lpIQFNjfDrrzmw6A1BoHc/+aefTk3eayVIRHgsm896GFZ73WQieL32tjINIMfe cERP2iE3ZnbD7LNhGvxV2RYDkzp0+/0fTazdzj+dm7UDtfrrnv8JSPkYvLzupmpE5k+X RgNA== X-Gm-Message-State: APjAAAVZ0RyfrriETzjwaGm5wqv+awr3+C3sM603ePZQb8yGuPHUxYod 4MmvNWdctpMLW+cTRWyCus7iJA== X-Google-Smtp-Source: APXvYqzuOkeR5V8nXPnWQfZw7YnbT1B+Yn0RM4Xuybw183F1fu51XS2uWjdJ5I12oMu/9MwMmyeSfw== X-Received: by 2002:adf:df8f:: with SMTP id z15mr3415089wrl.282.1581066269528; Fri, 07 Feb 2020 01:04:29 -0800 (PST) Received: from antos ([77.87.240.5]) by smtp.gmail.com with ESMTPSA id x17sm2500317wrt.74.2020.02.07.01.04.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Feb 2020 01:04:28 -0800 (PST) From: Antonin Houska To: Richard Guo cc: Tomas Vondra , Alvaro Herrera , Richard Guo , Tom Lane , Michael Paquier , PostgreSQL-development Subject: Re: [HACKERS] WIP: Aggregation push-down In-reply-to: References: <20190904202339.GA13644@alvherre.pgsql> <7087.1567663858@localhost> <20200111011124.efacqhdsptc36pm2@development> <72558.1579188350@antos> Comments: In-reply-to Richard Guo message dated "Thu, 06 Feb 2020 16:30:32 +0800." X-Mailer: MH-E 8.6+git; nmh 1.7; GNU Emacs 26.3.50 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <53725.1581066334.1@antos> Content-Transfer-Encoding: quoted-printable Date: Fri, 07 Feb 2020 10:05:34 +0100 Message-ID: <53726.1581066334@antos> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Richard Guo wrote: > Hi, > = > I've been looking at the 'make_join_rel()' part of the patch, and I'm > aware that, if we are joining A and B, a 'grouped join rel (AB)' would > be created besides the 'plain join rel (AB)', and paths are added by 1) > applying partial aggregate to the paths of the 'plain join rel (AB)', or > 2) joining grouped A to plain B or joining plain A to grouped B. > = > This is a smart idea. One issue I can see is that some logic would have > to be repeated several times. For example, the validity check for the > same proposed join would be performed at most three times by > join_is_legal(). > = > I'm thinking of another idea that, instead of using a separate > RelOptInfo for the grouped rel, we add in RelOptInfo a > 'grouped_pathlist' for the grouped paths, just like how we implement > parallel query via adding 'partial_pathlist'. > = > For base rel, if we decide it can produce grouped paths, we create the > grouped paths by applying partial aggregation to the paths in 'pathlist' > and add them into 'grouped_pathlist'. > = > For join rel (AB), we can create the grouped paths for it by: > 1) joining a grouped path from 'A->grouped_pathlist' to a plain path > from 'B->pathlist', or vice versa; > 2) applying partial aggregation to the paths in '(AB)->pathlist'. > = > This is basically the same idea, just moves the grouped paths from the > grouped rel to a 'grouped_pathlist'. With it we should not need to make > any code changes to 'make_join_rel()'. Most code changes would happen in > 'add_paths_to_joinrel()'. > = > Will this idea work? Is it better or worse? I tried such approach in an earlier version of the patch [1], and I think = the reason also was to avoid repeated calls of functions like join_is_legal(). However there were objections against such approach, e.g. [2], and I admit that it was more invasive than what the current patc= h version does. Perhaps we can cache the result of join_is_legal() that we get for the pla= in relation, and use it for the group relation. I'll consider that. Thanks. [1] https://www.postgresql.org/message-id/18007.1513957437%40localhost [2] https://www.postgresql.org/message-id/CA%2BTgmob8og%2B9HzMg1vM%2B3LwDm= 2f_bHUi9%2Bg1bqLDTjqpw5s%2BnQ%40mail.gmail.com -- = Antonin Houska Web: https://www.cybertec-postgresql.com