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

Function check_selective_binary_conversion

contrib/file_fdw/file_fdw.c:866–981  ·  view source on GitHub ↗

* check_selective_binary_conversion * * Check to see if it's useful to convert only a subset of the file's columns * to binary. If so, construct a list of the column names to be converted, * return that at *columns, and return true. (Note that it's possible to * determine that no columns need be converted, for instance with a COUNT(*) * query. So we can't use returning a NIL list to indic

Source from the content-addressed store, hash-verified

864 * query. So we can't use returning a NIL list to indicate failure.)
865 */
866static bool
867check_selective_binary_conversion(RelOptInfo *baserel,
868 Oid foreigntableid,
869 List **columns)
870{
871 ForeignTable *table;
872 ListCell *lc;
873 Relation rel;
874 TupleDesc tupleDesc;
875 AttrNumber attnum;
876 Bitmapset *attrs_used = NULL;
877 bool has_wholerow = false;
878 int numattrs;
879 int i;
880
881 *columns = NIL; /* default result */
882
883 /*
884 * Check format of the file. If binary format, this is irrelevant.
885 */
886 table = GetForeignTable(foreigntableid);
887 foreach(lc, table->options)
888 {
889 DefElem *def = (DefElem *) lfirst(lc);
890
891 if (strcmp(def->defname, "format") == 0)
892 {
893 char *format = defGetString(def);
894
895 if (strcmp(format, "binary") == 0)
896 return false;
897 break;
898 }
899 }
900
901 /* Collect all the attributes needed for joins or final output. */
902 pull_varattnos((Node *) baserel->reltarget->exprs, baserel->relid,
903 &attrs_used);
904
905 /* Add all the attributes used by restriction clauses. */
906 foreach(lc, baserel->baserestrictinfo)
907 {
908 RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
909
910 pull_varattnos((Node *) rinfo->clause, baserel->relid,
911 &attrs_used);
912 }
913
914 /* Convert attribute numbers to column names. */
915 rel = table_open(foreigntableid, AccessShareLock);
916 tupleDesc = RelationGetDescr(rel);
917
918 while ((attnum = bms_first_member(attrs_used)) >= 0)
919 {
920 /* Adjust for system attributes. */
921 attnum += FirstLowInvalidHeapAttributeNumber;
922
923 if (attnum == 0)

Callers 1

fileGetForeignPathsFunction · 0.85

Calls 11

GetForeignTableFunction · 0.85
defGetStringFunction · 0.85
pull_varattnosFunction · 0.85
table_openFunction · 0.85
bms_first_memberFunction · 0.85
lappendFunction · 0.85
makeStringFunction · 0.85
table_closeFunction · 0.85
list_lengthFunction · 0.85
foreachFunction · 0.50
pstrdupFunction · 0.50

Tested by

no test coverage detected