@@ -827,4 +827,137 @@ export function getArraySpecialMembers(): ArraySpecialMember[] {
827827 _ ( 'TestSpec' , 'sessions' , 'nsesssions' ) ,
828828 _ ( 'TestSpec' , 'permutations' , 'npermutations' ) ,
829829 ] ;
830- }
830+ }
831+
832+ /*
833+ *
834+ * Computed like this:
835+ *
836+ * type->field:
837+ * - ind1 = (path->path->path)[ind1 - (indexDelta ?? 0)]
838+ * - ind2 = (path->path->path)[ind2 - (indexDelta ?? 0)]
839+ * - ind3 = (path->path->path)[ind3 - (indexDelta ?? 0)]
840+ */
841+ export interface BitmapsetReference {
842+ /*
843+ * Type in which this Bitmapset stored.
844+ */
845+ type : string ;
846+ /*
847+ * Field name of this Bitmapset member
848+ */
849+ field : string ;
850+ /*
851+ * Paths to fields to which this bitmapset refers.
852+ * Examined starting from PlannerInfo.
853+ */
854+ paths : {
855+ /*
856+ * One of possible paths to referer
857+ */
858+ path : string [ ] ,
859+ /*
860+ * Delta to apply to result number for element in set.
861+ * Useful i.e. for rtable index in RelOptInfo->relids.
862+ * By default - 0
863+ */
864+ indexDelta ?: number ;
865+ } [ ] ;
866+
867+ /*
868+ * From which element search should be started (accessing via `paths').
869+ * 'PlannerInfo' - search in parents until reach 'PlannerInfo'
870+ * (PlannerInfo->...->elem->bms - search PlannerInfo's fields)
871+ * 'Parent' - from direct parent of containing element
872+ * (parent-elem->bms - search parent's fields)
873+ * 'Self' - search directly in containing element
874+ * (elem->bms - search in elem's fields)
875+ */
876+ start ?: 'PlannerInfo' | 'Parent' | 'Self' ;
877+ }
878+
879+ export function getWellKnownBitmapsetReferences ( ) : [ string , BitmapsetReference ] [ ] {
880+ const pathToRangeTable = [ 'parse' , 'rtable' ] ;
881+ const pathToRelOptInfos = [ 'simple_rel_array' ] ;
882+ const pathToRteAndRelOptInfos = [ { path : pathToRangeTable , indexDelta : - 1 } ,
883+ { path : pathToRelOptInfos } ] ;
884+ const ref = ( type : string , field : string ,
885+ paths : { path : string [ ] , indexDelta ?: number } [ ] ,
886+ start ?: 'PlannerInfo' | 'Parent' | 'Self' ) : [ string , BitmapsetReference ] =>
887+ [ field , { type, field, paths, start } ] ;
888+
889+ return [
890+ ref ( 'RelOptInfo' , 'relids' , pathToRteAndRelOptInfos ) ,
891+ ref ( 'RelOptInfo' , 'eclass_indexes' , [ { path : [ 'eclasses' ] } ] ) ,
892+ ref ( 'RelOptInfo' , 'nulling_relids' , pathToRteAndRelOptInfos ) ,
893+ ref ( 'RelOptInfo' , 'direct_lateral_relids' , pathToRteAndRelOptInfos ) ,
894+ ref ( 'RelOptInfo' , 'lateral_relids' , pathToRteAndRelOptInfos ) ,
895+ ref ( 'RelOptInfo' , 'lateral_referencers' , pathToRteAndRelOptInfos ) ,
896+ ref ( 'RelOptInfo' , 'top_parent_relids' , pathToRteAndRelOptInfos ) ,
897+ ref ( 'RelOptInfo' , 'live_parts' , [ { path : [ 'part_rels' ] } ] , 'Self' ) ,
898+ ref ( 'RelOptInfo' , 'all_partrels' , pathToRteAndRelOptInfos ) ,
899+
900+ ref ( 'JoinDomain' , 'jd_relids' , pathToRteAndRelOptInfos ) ,
901+
902+ ref ( 'EquivalenceClass' , 'ec_relids' , pathToRteAndRelOptInfos ) ,
903+
904+ ref ( 'EquivalenceMember' , 'em_relids' , pathToRteAndRelOptInfos ) ,
905+
906+ ref ( 'PlannerInfo' , 'all_baserels' , pathToRteAndRelOptInfos , 'Self' ) ,
907+ ref ( 'PlannerInfo' , 'outer_join_rels' , pathToRteAndRelOptInfos , 'Self' ) ,
908+ ref ( 'PlannerInfo' , 'all_query_rels' , pathToRteAndRelOptInfos , 'Self' ) ,
909+ ref ( 'PlannerInfo' , 'all_result_relids' , pathToRteAndRelOptInfos , 'Self' ) ,
910+ ref ( 'PlannerInfo' , 'leaf_result_relids' , pathToRteAndRelOptInfos , 'Self' ) ,
911+ ref ( 'PlannerInfo' , 'curOuterRels' , pathToRteAndRelOptInfos , 'Self' ) ,
912+
913+ ref ( 'ParamPathInfo' , 'ppi_req_outer' , pathToRteAndRelOptInfos ) ,
914+
915+ ref ( 'RestrictInfo' , 'required_relids' , pathToRteAndRelOptInfos ) ,
916+ ref ( 'RestrictInfo' , 'clause_relids' , pathToRteAndRelOptInfos ) ,
917+ ref ( 'RestrictInfo' , 'incompatible_relids' , pathToRteAndRelOptInfos ) ,
918+ ref ( 'RestrictInfo' , 'outer_relids' , pathToRteAndRelOptInfos ) ,
919+ ref ( 'RestrictInfo' , 'left_relids' , pathToRteAndRelOptInfos ) ,
920+ ref ( 'RestrictInfo' , 'right_relids' , pathToRteAndRelOptInfos ) ,
921+
922+ ref ( 'PlaceHolderVar' , 'phrelds' , pathToRteAndRelOptInfos ) ,
923+ ref ( 'PlaceHolderVar' , 'phnullingrels' , pathToRteAndRelOptInfos ) ,
924+
925+ ref ( 'SpecialJoinInfo' , 'min_lefthand' , pathToRteAndRelOptInfos ) ,
926+ ref ( 'SpecialJoinInfo' , 'min_righthand' , pathToRteAndRelOptInfos ) ,
927+ ref ( 'SpecialJoinInfo' , 'syn_lefthand' , pathToRteAndRelOptInfos ) ,
928+ ref ( 'SpecialJoinInfo' , 'syn_righthand' , pathToRteAndRelOptInfos ) ,
929+ ref ( 'SpecialJoinInfo' , 'compute_above_l' , pathToRteAndRelOptInfos ) ,
930+ ref ( 'SpecialJoinInfo' , 'compute_above_r' , pathToRteAndRelOptInfos ) ,
931+ ref ( 'SpecialJoinInfo' , 'compute_below_l' , pathToRteAndRelOptInfos ) ,
932+ ref ( 'SpecialJoinInfo' , 'compute_below_r' , pathToRteAndRelOptInfos ) ,
933+
934+ ref ( 'RowIdentifyVarInfo' , 'rowidrels' , pathToRteAndRelOptInfos ) ,
935+
936+ ref ( 'PlaceHolderInfo' , 'ph_evalat' , pathToRteAndRelOptInfos ) ,
937+ ref ( 'PlaceHolderInfo' , 'ph_lateral' , pathToRteAndRelOptInfos ) ,
938+ ref ( 'PlaceHolderInfo' , 'ph_needed' , pathToRteAndRelOptInfos ) ,
939+
940+ ref ( 'JoinPathExtraData' , 'param_source_rels' , pathToRteAndRelOptInfos ) ,
941+
942+ ref ( 'PlannedStmt' , 'rewindPlanIDs' , [ { path : [ 'subplans' ] } ] , 'Self' ) ,
943+
944+ ref ( 'ModifyTable' , 'fdwDirectModifyPlans' , [ { path : [ 'resultRelations' ] } ] , 'Self' ) ,
945+
946+ ref ( 'Append' , 'apprelids' , pathToRteAndRelOptInfos ) ,
947+ ref ( 'MergeAppend' , 'apprelids' , pathToRteAndRelOptInfos ) ,
948+
949+ ref ( 'ForeignScan' , 'fs_relids' , pathToRteAndRelOptInfos ) ,
950+ ref ( 'ForeignScan' , 'fs_base_relids' , pathToRteAndRelOptInfos ) ,
951+
952+ ref ( 'CustomScan' , 'custom_relids' , pathToRteAndRelOptInfos ) ,
953+
954+ ref ( 'Var' , 'varnullingrels' , pathToRteAndRelOptInfos ) ,
955+
956+ ref ( 'AppendState' , 'as_asyncplans' , [ { path : [ 'as_asyncrequests' ] } ] , 'Self' ) ,
957+ ref ( 'AppendState' , 'as_needrequest' , [ { path : [ 'as_asyncrequests' ] } ] , 'Self' ) ,
958+ ref ( 'AppendState' , 'as_valid_subplans' , [ { path : [ 'as_asyncrequests' ] } ] , 'Self' ) ,
959+ ref ( 'AppendState' , 'as_valid_asyncplans' , [ { path : [ 'as_asyncrequests' ] } ] , 'Self' ) ,
960+
961+ ref ( 'MergeAppendState' , 'ms_valid_subplans' , [ { path : [ 'mergeplans' ] } ] , 'Self' ) ,
962+ ]
963+ }
0 commit comments