Re: [HACKERS] FW: was [PERFORM] partitioned table and ORDER BY indexed_field DESC LIMIT 1

2008-03-24 Thread Bruce Momjian

Patch rejected because of Tom Lane's comments:

> This is useless since it does not represent a complete patch; the
> provided code calls a lot of Greenplum-private routines that weren't
> provided. It's not even reviewable let alone a candidate to apply.


---

Luke Lonergan wrote:
> Below is a patch against Greenplum Database that fixes the problem.
> 
> - Luke
> 
> -- Forwarded Message
> From: Luke Lonergan <[EMAIL PROTECTED]>
> Date: Fri, 24 Aug 2007 09:25:53 -0700
> To: Heikki Linnakangas <[EMAIL PROTECTED]>, Anton <[EMAIL PROTECTED]>
> Cc: <[EMAIL PROTECTED]>
> Conversation: [PERFORM] partitioned table and ORDER BY indexed_field DESC
> LIMIT 1
> Subject: Re: [PERFORM] partitioned table and ORDER BY indexed_field DESC
> LIMIT 1
> 
> Below is a patch against 8.2.4 (more or less), Heikki can you take a look at
> it?
> 
> This enables the use of index scan of a child table by recognizing sort
> order of the append node.  Kurt Harriman did the work.
> 
> - Luke
> 
> Index: cdb-pg/src/backend/optimizer/path/indxpath.c
> ===
> RCS file: 
> /data/FISHEYE_REPOSITORIES/greenplum/cvsroot/cdb2/cdb-pg/src/backend/optimiz
> er/path/indxpath.c,v
> diff -u -N -r1.22 -r1.22.2.1
> --- cdb-pg/src/backend/optimizer/path/indxpath.c25 Apr 2007 22:07:21
> -1.22
> +++ cdb-pg/src/backend/optimizer/path/indxpath.c10 Aug 2007 03:41:15
> -1.22.2.1
> @@ -379,8 +379,51 @@
>  index_pathkeys = build_index_pathkeys(root, index,
>ForwardScanDirection,
>true);
> -useful_pathkeys = truncate_useless_pathkeys(root, rel,
> -index_pathkeys);
> +/*
> + * CDB: For appendrel child, pathkeys contain Var nodes in
> terms 
> + * of the child's baserel.  Transform the pathkey list to refer
> to 
> + * columns of the appendrel.
> + */
> +if (rel->reloptkind == RELOPT_OTHER_MEMBER_REL)
> +{
> +AppendRelInfo  *appinfo = NULL;
> +RelOptInfo *appendrel = NULL;
> +ListCell   *appcell;
> +CdbPathLocusnotalocus;
> +
> +/* Find the appendrel of which this baserel is a child. */
> +foreach(appcell, root->append_rel_list)
> +{
> +appinfo = (AppendRelInfo *)lfirst(appcell);
> +if (appinfo->child_relid == rel->relid)
> +break;
> +}
> +Assert(appinfo);
> +appendrel = find_base_rel(root, appinfo->parent_relid);
> +
> +/*
> + * The pathkey list happens to have the same format as the
> + * partitioning key of a Hashed locus, so by disguising it
> + * we can use cdbpathlocus_pull_above_projection() to do
> the 
> + * transformation.
> + */
> +CdbPathLocus_MakeHashed(¬alocus, index_pathkeys);
> +notalocus =
> +cdbpathlocus_pull_above_projection(root,
> +   notalocus,
> +   rel->relids,
> +   rel->reltargetlist,
> +  
> appendrel->reltargetlist,
> +   appendrel->relid);
> +if (CdbPathLocus_IsHashed(notalocus))
> +index_pathkeys = truncate_useless_pathkeys(root,
> appendrel,
> +  
> notalocus.partkey);
> +else
> +index_pathkeys = NULL;
> +}
> +
> +useful_pathkeys = truncate_useless_pathkeys(root, rel,
> +index_pathkeys);
>  }
>  else
>  useful_pathkeys = NIL;
> Index: cdb-pg/src/backend/optimizer/path/pathkeys.c
> ===
> RCS file: 
> /data/FISHEYE_REPOSITORIES/greenplum/cvsroot/cdb2/cdb-pg/src/backend/optimiz
> er/path/pathkeys.c,v
> diff -u -N -r1.18 -r1.18.2.1
> --- cdb-pg/src/backend/optimizer/path/pathkeys.c30 Apr 2007 05:44:07
> -1.18
> +++ cdb-pg/src/backend/optimizer/path/pathkeys.c10 Aug 2007 03:41:15
> -1.18.2.1
> @@ -1403,55 +1403,53 @@
>  {
>  PathKeyItem*item;
>  Expr   *newexpr;
> +AttrNumber  targetindex;
>  
>  Assert(pathkey);
>  
> -/* Use constant expr if available.  Will be at head of list. */
> -if (CdbPathkeyEqualsConstant(pathkey))
> +/* Find an expr that we can rewrite to use the projected columns. */
> +  

Re: [HACKERS] FW: was [PERFORM] partitioned table and ORDER BY indexed_field DESC LIMIT 1

2007-08-28 Thread Bruce Momjian

This has been saved for the 8.4 release:

http://momjian.postgresql.org/cgi-bin/pgpatches_hold

---

Luke Lonergan wrote:
> Below is a patch against Greenplum Database that fixes the problem.
> 
> - Luke
> 
> -- Forwarded Message
> From: Luke Lonergan <[EMAIL PROTECTED]>
> Date: Fri, 24 Aug 2007 09:25:53 -0700
> To: Heikki Linnakangas <[EMAIL PROTECTED]>, Anton <[EMAIL PROTECTED]>
> Cc: <[EMAIL PROTECTED]>
> Conversation: [PERFORM] partitioned table and ORDER BY indexed_field DESC
> LIMIT 1
> Subject: Re: [PERFORM] partitioned table and ORDER BY indexed_field DESC
> LIMIT 1
> 
> Below is a patch against 8.2.4 (more or less), Heikki can you take a look at
> it?
> 
> This enables the use of index scan of a child table by recognizing sort
> order of the append node.  Kurt Harriman did the work.
> 
> - Luke
> 
> Index: cdb-pg/src/backend/optimizer/path/indxpath.c
> ===
> RCS file: 
> /data/FISHEYE_REPOSITORIES/greenplum/cvsroot/cdb2/cdb-pg/src/backend/optimiz
> er/path/indxpath.c,v
> diff -u -N -r1.22 -r1.22.2.1
> --- cdb-pg/src/backend/optimizer/path/indxpath.c25 Apr 2007 22:07:21
> -1.22
> +++ cdb-pg/src/backend/optimizer/path/indxpath.c10 Aug 2007 03:41:15
> -1.22.2.1
> @@ -379,8 +379,51 @@
>  index_pathkeys = build_index_pathkeys(root, index,
>ForwardScanDirection,
>true);
> -useful_pathkeys = truncate_useless_pathkeys(root, rel,
> -index_pathkeys);
> +/*
> + * CDB: For appendrel child, pathkeys contain Var nodes in
> terms 
> + * of the child's baserel.  Transform the pathkey list to refer
> to 
> + * columns of the appendrel.
> + */
> +if (rel->reloptkind == RELOPT_OTHER_MEMBER_REL)
> +{
> +AppendRelInfo  *appinfo = NULL;
> +RelOptInfo *appendrel = NULL;
> +ListCell   *appcell;
> +CdbPathLocusnotalocus;
> +
> +/* Find the appendrel of which this baserel is a child. */
> +foreach(appcell, root->append_rel_list)
> +{
> +appinfo = (AppendRelInfo *)lfirst(appcell);
> +if (appinfo->child_relid == rel->relid)
> +break;
> +}
> +Assert(appinfo);
> +appendrel = find_base_rel(root, appinfo->parent_relid);
> +
> +/*
> + * The pathkey list happens to have the same format as the
> + * partitioning key of a Hashed locus, so by disguising it
> + * we can use cdbpathlocus_pull_above_projection() to do
> the 
> + * transformation.
> + */
> +CdbPathLocus_MakeHashed(¬alocus, index_pathkeys);
> +notalocus =
> +cdbpathlocus_pull_above_projection(root,
> +   notalocus,
> +   rel->relids,
> +   rel->reltargetlist,
> +  
> appendrel->reltargetlist,
> +   appendrel->relid);
> +if (CdbPathLocus_IsHashed(notalocus))
> +index_pathkeys = truncate_useless_pathkeys(root,
> appendrel,
> +  
> notalocus.partkey);
> +else
> +index_pathkeys = NULL;
> +}
> +
> +useful_pathkeys = truncate_useless_pathkeys(root, rel,
> +index_pathkeys);
>  }
>  else
>  useful_pathkeys = NIL;
> Index: cdb-pg/src/backend/optimizer/path/pathkeys.c
> ===
> RCS file: 
> /data/FISHEYE_REPOSITORIES/greenplum/cvsroot/cdb2/cdb-pg/src/backend/optimiz
> er/path/pathkeys.c,v
> diff -u -N -r1.18 -r1.18.2.1
> --- cdb-pg/src/backend/optimizer/path/pathkeys.c30 Apr 2007 05:44:07
> -1.18
> +++ cdb-pg/src/backend/optimizer/path/pathkeys.c10 Aug 2007 03:41:15
> -1.18.2.1
> @@ -1403,55 +1403,53 @@
>  {
>  PathKeyItem*item;
>  Expr   *newexpr;
> +AttrNumber  targetindex;
>  
>  Assert(pathkey);
>  
> -/* Use constant expr if available.  Will be at head of list. */
> -if (CdbPathkeyEqualsConstant(pathkey))
> +/* Find an expr that we can rewrite to use the projected columns. */
> +item = cdbpullup_findPathKeyItemInTargetList(pathkey,
> + relids,
> +