1 /*
2  * This file and its contents are licensed under the Timescale License.
3  * Please see the included NOTICE for copyright information and
4  * LICENSE-TIMESCALE for a copy of the license.
5  */
6 #ifndef TIMESCALEDB_TSL_FDW_SCAN_PLAN_H
7 #define TIMESCALEDB_TSL_FDW_SCAN_PLAN_H
8 
9 #include <postgres.h>
10 #include <commands/explain.h>
11 #include <fmgr.h>
12 #include <foreign/foreign.h>
13 #include <funcapi.h>
14 #include <lib/stringinfo.h>
15 #include <nodes/pathnodes.h>
16 #include <utils/relcache.h>
17 
18 #include "data_node_chunk_assignment.h"
19 
20 typedef struct TsFdwRelInfo TsFdwRelInfo;
21 
22 typedef struct ScanInfo
23 {
24 	Oid data_node_serverid;
25 	Index scan_relid;
26 	List *local_exprs;
27 	List *fdw_private;
28 	List *fdw_scan_tlist;
29 	List *fdw_recheck_quals;
30 	List *params_list;
31 	bool systemcol;
32 } ScanInfo;
33 
34 typedef Path *(*CreatePathFunc)(PlannerInfo *root, RelOptInfo *rel, PathTarget *target, double rows,
35 								Cost startup_cost, Cost total_cost, List *pathkeys,
36 								Relids required_outer, Path *fdw_outerpath, List *fdw_private);
37 
38 typedef Path *(*CreateUpperPathFunc)(PlannerInfo *root, RelOptInfo *rel, PathTarget *target,
39 									 double rows, Cost startup_cost, Cost total_cost,
40 									 List *pathkeys, Path *fdw_outerpath, List *fdw_private);
41 
42 extern void fdw_scan_info_init(ScanInfo *scaninfo, PlannerInfo *root, RelOptInfo *rel,
43 							   Path *best_path, List *scan_clauses);
44 
45 extern void fdw_add_paths_with_pathkeys_for_rel(PlannerInfo *root, RelOptInfo *rel, Path *epq_path,
46 												CreatePathFunc create_scan_path);
47 extern void fdw_add_upper_paths_with_pathkeys_for_rel(PlannerInfo *root, RelOptInfo *rel,
48 													  Path *epq_path,
49 													  CreateUpperPathFunc create_upper_path);
50 
51 extern void fdw_create_upper_paths(TsFdwRelInfo *input_fpinfo, PlannerInfo *root,
52 								   UpperRelationKind stage, RelOptInfo *input_rel,
53 								   RelOptInfo *output_rel, void *extra,
54 								   CreateUpperPathFunc create_paths);
55 
56 #endif /* TIMESCALEDB_TSL_FDW_SCAN_PLAN_H */
57