MCPcopy Create free account
hub / github.com/apache/cloudberry / transformIndexStmt

Function transformIndexStmt

src/backend/parser/parse_utilcmd.c:3944–4030  ·  view source on GitHub ↗

* 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

Source from the content-addressed store, hash-verified

3942 * relation.
3943 */
3944IndexStmt *
3945transformIndexStmt(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

Callers 3

ProcessUtilitySlowFunction · 0.85
ATPostAlterTypeParseFunction · 0.85
transformAlterTableStmtFunction · 0.85

Calls 14

make_parsestateFunction · 0.85
relation_openFunction · 0.85
addNSItemToQueryFunction · 0.85
transformWhereClauseFunction · 0.85
assign_expr_collationsFunction · 0.85
FigureIndexColnameFunction · 0.85
transformExprFunction · 0.85
list_lengthFunction · 0.85
free_parsestateFunction · 0.85
table_closeFunction · 0.85
foreachFunction · 0.50

Tested by

no test coverage detected