Re: Sort a column that does not exist
От | Werner Echezuria |
---|---|
Тема | Re: Sort a column that does not exist |
Дата | |
Msg-id | 2485a25e0904071252g1fb16a65i9e7085e72d42c5a3@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Sort a column that does not exist (Werner Echezuria <wercool@gmail.com>) |
Список | pgsql-hackers |
Hi, I think I solved the problem in the parser and the planner, but I'm stuck in the executor, I think is in the ExecSort function on nodeSort around this code:
/*
* Scan the subplan and feed all the tuples to tuplesort.
*/
for (;;)
{
slot = ExecProcNode(outerNode);
if (TupIsNull(slot))
break;
tuplesort_puttupleslot(tuplesortstate, slot);
}
Now, when the server get in that loop it hangs out, Would I have to add something that identifies the extra column? or will I have to include somewhere in the tuplesort the column?
/*
* Scan the subplan and feed all the tuples to tuplesort.
*/
for (;;)
{
slot = ExecProcNode(outerNode);
if (TupIsNull(slot))
break;
tuplesort_puttupleslot(tuplesortstate, slot);
}
Now, when the server get in that loop it hangs out, Would I have to add something that identifies the extra column? or will I have to include somewhere in the tuplesort the column?
2009/4/2 Werner Echezuria <wercool@gmail.com>
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.tanuki@gmail.com>2009/4/1 Werner Echezuria <wercool@gmail.com>:> As you can see if someone do this: SELECT * FROM table WHERESee include/nodes/primnodes.h around line 1075:
> 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.
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.Use makeTargetEntry in makefuncs.c
>
> 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?
>
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
В списке pgsql-hackers по дате отправления: