* transformIndexStmt - parse analysis for CREATE INDEX and ALTER TABLE * * Note: this is a no-op for an index not using either index expressions or * a predicate expression. There are several code paths that create indexes * without bothering to call this, because they know they don't have any * such expressions to deal with. * * To avoid race conditions, it's important that this function
| 3942 | * relation. |
| 3943 | */ |
| 3944 | IndexStmt * |
| 3945 | transformIndexStmt(Oid relid, IndexStmt *stmt, const char *queryString) |
| 3946 | { |
| 3947 | ParseState *pstate; |
| 3948 | ParseNamespaceItem *nsitem; |
| 3949 | ListCell *l; |
| 3950 | Relation rel; |
| 3951 | |
| 3952 | /* Nothing to do if statement already transformed. */ |
| 3953 | if (stmt->transformed) |
| 3954 | return stmt; |
| 3955 | |
| 3956 | /* Set up pstate */ |
| 3957 | pstate = make_parsestate(NULL); |
| 3958 | pstate->p_sourcetext = queryString; |
| 3959 | |
| 3960 | /* |
| 3961 | * Put the parent table into the rtable so that the expressions can refer |
| 3962 | * to its fields without qualification. Caller is responsible for locking |
| 3963 | * relation, but we still need to open it. |
| 3964 | */ |
| 3965 | rel = relation_open(relid, NoLock); |
| 3966 | nsitem = addRangeTableEntryForRelation(pstate, rel, |
| 3967 | AccessShareLock, |
| 3968 | NULL, false, true); |
| 3969 | |
| 3970 | /* no to join list, yes to namespaces */ |
| 3971 | addNSItemToQuery(pstate, nsitem, false, true, true); |
| 3972 | |
| 3973 | /* take care of the where clause */ |
| 3974 | if (stmt->whereClause) |
| 3975 | { |
| 3976 | stmt->whereClause = transformWhereClause(pstate, |
| 3977 | stmt->whereClause, |
| 3978 | EXPR_KIND_INDEX_PREDICATE, |
| 3979 | "WHERE"); |
| 3980 | /* we have to fix its collations too */ |
| 3981 | assign_expr_collations(pstate, stmt->whereClause); |
| 3982 | } |
| 3983 | |
| 3984 | /* take care of any index expressions */ |
| 3985 | foreach(l, stmt->indexParams) |
| 3986 | { |
| 3987 | IndexElem *ielem = (IndexElem *) lfirst(l); |
| 3988 | |
| 3989 | if (ielem->expr) |
| 3990 | { |
| 3991 | /* Extract preliminary index col name before transforming expr */ |
| 3992 | if (ielem->indexcolname == NULL) |
| 3993 | ielem->indexcolname = FigureIndexColname(ielem->expr); |
| 3994 | |
| 3995 | /* Now do parse transformation of the expression */ |
| 3996 | ielem->expr = transformExpr(pstate, ielem->expr, |
| 3997 | EXPR_KIND_INDEX_EXPRESSION); |
| 3998 | |
| 3999 | /* We have to fix its collations too */ |
| 4000 | assign_expr_collations(pstate, ielem->expr); |
| 4001 |
no test coverage detected