Re: Sort a column that does not exist - Mailing list pgsql-hackers

From Werner Echezuria
Subject Re: Sort a column that does not exist
Date
Msg-id 2485a25e0904020921y187ad0c9u85a31da34a0da749@mail.gmail.com
Whole thread Raw
In response to Re: Sort a column that does not exist  (Hitoshi Harada <umi.tanuki@gmail.com>)
Responses Re: Sort a column that does not exist  (Werner Echezuria <wercool@gmail.com>)
List pgsql-hackers
<br />Hi, the problem goes on. I think the problem is in the planner.c on grouping_planner function, because when I do
aregular sort it gets to it:<br /><br />    /*<br />     * If we were not able to make the plan come out in the right
order,add<br />      * an explicit sort step.<br />     */<br />    if (parse->sortClause)<br />    {<br />       
if(!pathkeys_contained_in(sort_pathkeys, current_pathkeys))<br />        {<br />            result_plan = (Plan *)
make_sort_from_pathkeys(root,<br/>                                                            result_plan,<br />       
                                                  sort_pathkeys,<br />                                               
          limit_tuples);<br />             current_pathkeys = sort_pathkeys;<br />        }<br />    }<br /><br />and
dothe 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
ObjectIdGetDatumin heap_getsysattr, the server hang out. What can I do? How can I assign a valid attrnum?<br /><br
/><br/><div class="gmail_quote">2009/4/1 Hitoshi Harada <span dir="ltr"><<a
href="mailto:umi.tanuki@gmail.com">umi.tanuki@gmail.com</a>></span><br/><blockquote class="gmail_quote"
style="border-left:1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> 2009/4/1 Werner
Echezuria<<a href="mailto:wercool@gmail.com">wercool@gmail.com</a>>:<br /><div class="im">> As you can see if
someonedo this: SELECT * FROM table WHERE<br /> > field=some_value ORDER BY grmemb, postgresql creates a new target
entryand<br /> > then assigned to the targetlist as a sort node. I know that it creates the<br /> > node on the
parser,but it does not work, it seems the executor don't see<br /> > it.<br /><br /></div>See
include/nodes/primnodes.haround line 1075:<br />        bool            resjunk;                /* set to true to
eliminatethe attribute from<br />                                                                 * final target list
*/<br/><br /> If the TargetEntry is set resjunk = false, the final result is<br /> filtered as junk. So more accurately
theexecutor sees but drops it.<br /><div class="im"><br /> ><br /> > How could I sort a column like this?, I know
i'mmissing something, but i<br /> > just don't see it. What is the process to sort a column?<br /> ><br /><br
/></div>UsemakeTargetEntry in makefuncs.c<br /> TargetEntry *<br /> makeTargetEntry(Expr *expr,<br />                  
            AttrNumber resno,<br />                                char *resname,<br />                              
 boolresjunk)<br /><br /> by the 4th argument you can set resjunk = false if you don't want it<br /> to be in the
result.<br/><br /> Regards,<br /><br /><br /> --<br /><font color="#888888">Hitoshi Harada<br
/></font></blockquote></div><br/> 

pgsql-hackers by date:

Previous
From: "David E. Wheeler"
Date:
Subject: Re: [GENERAL] string_to_array with empty input
Next
From: Tom Lane
Date:
Subject: Re: questions about not-null constraints and inheritance