* preprocess_expression * Do subquery_planner's preprocessing work for an expression, * which can be a targetlist, a WHERE clause (including JOIN/ON * conditions), a HAVING clause, or a few other things. */
| 1402 | * conditions), a HAVING clause, or a few other things. |
| 1403 | */ |
| 1404 | static Node * |
| 1405 | preprocess_expression(PlannerInfo *root, Node *expr, int kind) |
| 1406 | { |
| 1407 | /* |
| 1408 | * Fall out quickly if expression is empty. This occurs often enough to |
| 1409 | * be worth checking. Note that null->null is the correct conversion for |
| 1410 | * implicit-AND result format, too. |
| 1411 | */ |
| 1412 | if (expr == NULL) |
| 1413 | return NULL; |
| 1414 | |
| 1415 | /* |
| 1416 | * If the query has any join RTEs, replace join alias variables with |
| 1417 | * base-relation variables. We must do this first, since any expressions |
| 1418 | * we may extract from the joinaliasvars lists have not been preprocessed. |
| 1419 | * For example, if we did this after sublink processing, sublinks expanded |
| 1420 | * out from join aliases would not get processed. But we can skip this in |
| 1421 | * non-lateral RTE functions, VALUES lists, and TABLESAMPLE clauses, since |
| 1422 | * they can't contain any Vars of the current query level. |
| 1423 | */ |
| 1424 | if (root->hasJoinRTEs && |
| 1425 | !(kind == EXPRKIND_RTFUNC || |
| 1426 | kind == EXPRKIND_VALUES || |
| 1427 | kind == EXPRKIND_TABLESAMPLE || |
| 1428 | kind == EXPRKIND_TABLEFUNC)) |
| 1429 | expr = flatten_join_alias_vars(root->parse, expr); |
| 1430 | |
| 1431 | if (root->parse->hasFuncsWithExecRestrictions) |
| 1432 | { |
| 1433 | if (kind == EXPRKIND_RTFUNC) |
| 1434 | { |
| 1435 | /* allowed */ |
| 1436 | } |
| 1437 | else if (kind == EXPRKIND_TARGET) |
| 1438 | { |
| 1439 | /* |
| 1440 | * Allowed in simple cases with no real RTEs. For example, |
| 1441 | * "SELECT func()" is allowed, but "SELECT func() FROM foo" is not. |
| 1442 | */ |
| 1443 | if ((list_length(root->parse->rtable) != 1 || |
| 1444 | linitial_node(RangeTblEntry, root->parse->rtable)->rtekind != RTE_RESULT) && |
| 1445 | check_execute_on_functions((Node *) root->parse->targetList) != PROEXECLOCATION_ANY) |
| 1446 | { |
| 1447 | ereport(ERROR, |
| 1448 | (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
| 1449 | errmsg("function with EXECUTE ON restrictions cannot be used in the SELECT list of a query with FROM"))); |
| 1450 | } |
| 1451 | } |
| 1452 | else |
| 1453 | { |
| 1454 | if (check_execute_on_functions((Node *) root->parse->targetList) != PROEXECLOCATION_ANY) |
| 1455 | ereport(ERROR, |
| 1456 | (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
| 1457 | errmsg("function with EXECUTE ON restrictions cannot be used here"))); |
| 1458 | } |
| 1459 | } |
| 1460 | |
| 1461 | /* |
no test coverage detected