* Pulls up the expr sublink subquery into the top-level range table. */
| 837 | * Pulls up the expr sublink subquery into the top-level range table. |
| 838 | */ |
| 839 | static int |
| 840 | add_expr_subquery_rte(Query *parse, Query *subselect) |
| 841 | { |
| 842 | int subq_indx; |
| 843 | ParseNamespaceItem *pni; |
| 844 | ParseState *pstate; |
| 845 | |
| 846 | /** |
| 847 | * Generate column names. |
| 848 | * TODO: improve this to keep old names around |
| 849 | */ |
| 850 | ListCell *lc = NULL; |
| 851 | int teNum = 0; |
| 852 | |
| 853 | foreach(lc, subselect->targetList) |
| 854 | { |
| 855 | TargetEntry *te = (TargetEntry *) lfirst(lc); |
| 856 | |
| 857 | te->resname = psprintf("csq_c%d", teNum); |
| 858 | teNum++; |
| 859 | } |
| 860 | |
| 861 | /* Create a dummy ParseState for addRangeTableEntryForSubquery */ |
| 862 | pstate = make_parsestate(NULL); |
| 863 | |
| 864 | /* |
| 865 | * Create a RTE entry in the parent query for the subquery. |
| 866 | * It is marked as lateral, because any correlation quals will |
| 867 | * refer to other RTEs in the parent query. |
| 868 | */ |
| 869 | pni = addRangeTableEntryForSubquery(pstate, |
| 870 | subselect, |
| 871 | makeAlias("Expr_SUBQUERY", NIL), |
| 872 | true, /* lateral */ |
| 873 | false /* inFromClause */ ); |
| 874 | parse->rtable = lappend(parse->rtable, pni->p_rte); |
| 875 | |
| 876 | /* assume new rte is at end */ |
| 877 | subq_indx = list_length(parse->rtable); |
| 878 | Assert(pni->p_rte == rt_fetch(subq_indx, parse->rtable)); |
| 879 | |
| 880 | return subq_indx; |
| 881 | } |
| 882 | |
| 883 | |
| 884 | /* Create a join expression linking the supplied larg node |
no test coverage detected