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

Function postgresGetForeignRelSize

contrib/postgres_fdw/postgres_fdw.c:622–786  ·  view source on GitHub ↗

* postgresGetForeignRelSize * Estimate # of rows and width of the result of the scan * * We should consider the effect of all baserestrictinfo clauses here, but * not any join clauses. */

Source from the content-addressed store, hash-verified

620 * not any join clauses.
621 */
622static void
623postgresGetForeignRelSize(PlannerInfo *root,
624 RelOptInfo *baserel,
625 Oid foreigntableid)
626{
627 PgFdwRelationInfo *fpinfo;
628 ListCell *lc;
629 RangeTblEntry *rte = planner_rt_fetch(baserel->relid, root);
630
631 /*
632 * We use PgFdwRelationInfo to pass various information to subsequent
633 * functions.
634 */
635 fpinfo = (PgFdwRelationInfo *) palloc0(sizeof(PgFdwRelationInfo));
636 baserel->fdw_private = (void *) fpinfo;
637
638 /* Base foreign tables need to be pushed down always. */
639 fpinfo->pushdown_safe = true;
640
641 /* Look up foreign-table catalog info. */
642 fpinfo->table = GetForeignTable(foreigntableid);
643 fpinfo->server = GetForeignServer(fpinfo->table->serverid);
644
645 /*
646 * Extract user-settable option values. Note that per-table settings of
647 * use_remote_estimate, fetch_size and async_capable override per-server
648 * settings of them, respectively.
649 */
650 fpinfo->use_remote_estimate = false;
651 fpinfo->fdw_startup_cost = DEFAULT_FDW_STARTUP_COST;
652 fpinfo->fdw_tuple_cost = DEFAULT_FDW_TUPLE_COST;
653 fpinfo->shippable_extensions = NIL;
654 fpinfo->fetch_size = 100;
655 fpinfo->async_capable = false;
656
657 apply_server_options(fpinfo);
658 apply_table_options(fpinfo);
659
660 /*
661 * If the table or the server is configured to use remote estimates,
662 * identify which user to do remote access as during planning. This
663 * should match what ExecCheckRTEPerms() does. If we fail due to lack of
664 * permissions, the query would have failed at runtime anyway.
665 */
666 if (fpinfo->use_remote_estimate)
667 {
668 Oid userid = rte->checkAsUser ? rte->checkAsUser : GetUserId();
669
670 fpinfo->user = GetUserMapping(userid, fpinfo->server->serverid);
671 }
672 else
673 fpinfo->user = NULL;
674
675 /*
676 * Identify which baserestrictinfo clauses can be sent to the remote
677 * server and which can't.
678 */
679 classifyConditions(root, baserel, baserel->baserestrictinfo,

Callers

nothing calls this directly

Calls 15

GetForeignTableFunction · 0.85
GetForeignServerFunction · 0.85
apply_server_optionsFunction · 0.85
apply_table_optionsFunction · 0.85
GetUserIdFunction · 0.85
GetUserMappingFunction · 0.85
pull_varattnosFunction · 0.85
clauselist_selectivityFunction · 0.85
cost_qual_evalFunction · 0.85
estimate_path_cost_sizeFunction · 0.85
psprintfFunction · 0.85

Tested by

no test coverage detected