Re: Sort a column that does not exist

From: Werner Echezuria <wercool(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Sort a column that does not exist
Date: 2009-04-02 16:21:34
Message-ID: 2485a25e0904020921y187ad0c9u85a31da34a0da749@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi, the problem goes on. I think the problem is in the planner.c on
grouping_planner function, because when I do a regular sort it gets to it:

/*
* If we were not able to make the plan come out in the right order, add
* an explicit sort step.
*/
if (parse->sortClause)
{
if (!pathkeys_contained_in(sort_pathkeys, current_pathkeys))
{
result_plan = (Plan *) make_sort_from_pathkeys(root,
result_plan,
sort_pathkeys,
limit_tuples);
current_pathkeys = sort_pathkeys;
}
}

and do the make_sort_from_pathkeys, but when I do the sort by grmemb it does
not. So I change it in order to pass through make_sort_from_pathkey, but it
drops an error like this "invalid attnum", so when I go to heaptuple and
force to get to ObjectIdGetDatum in heap_getsysattr, the server hang out.
What can I do? How can I assign a valid attrnum?

2009/4/1 Hitoshi Harada <umi(dot)tanuki(at)gmail(dot)com>

> 2009/4/1 Werner Echezuria <wercool(at)gmail(dot)com>:
> > As you can see if someone do this: SELECT * FROM table WHERE
> > field=some_value ORDER BY grmemb, postgresql creates a new target entry
> and
> > then assigned to the targetlist as a sort node. I know that it creates
> the
> > node on the parser, but it does not work, it seems the executor don't see
> > it.
>
> See include/nodes/primnodes.h around line 1075:
> bool resjunk; /* set to true to eliminate
> the attribute from
> * final
> target list */
>
> If the TargetEntry is set resjunk = false, the final result is
> filtered as junk. So more accurately the executor sees but drops it.
>
> >
> > How could I sort a column like this?, I know i'm missing something, but i
> > just don't see it. What is the process to sort a column?
> >
>
> Use makeTargetEntry in makefuncs.c
> TargetEntry *
> makeTargetEntry(Expr *expr,
> AttrNumber resno,
> char *resname,
> bool resjunk)
>
> by the 4th argument you can set resjunk = false if you don't want it
> to be in the result.
>
> Regards,
>
>
> --
> Hitoshi Harada
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Steve Crawford 2009-04-02 16:29:04 Re: [HACKERS] string_to_array with empty input
Previous Message David E. Wheeler 2009-04-02 16:17:21 Re: [HACKERS] string_to_array with empty input