Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
4dd1299
#105 Introducing db2GetForeignUpperPaths
temuenz Jan 12, 2026
ade1cf4
add deep copy of fdwstate for upper path
temuenz Jan 17, 2026
d6d59f2
added deparseAggref to handle aggregate functions count, sum, min, ma…
temuenz Jan 17, 2026
c367016
the code is able now to correctly parse the aggregate functions, but …
temuenz Jan 17, 2026
08b462e
enhanced traces
temuenz Jan 17, 2026
b46e854
still not working properly. refer to pg_fdw for clarification.
temuenz Jan 18, 2026
7ae4113
reworks all the depare functions to match the pg_fdw implementation m…
temuenz Jan 20, 2026
b522b4a
removed all code no longer required by PG >= v13
temuenz Jan 20, 2026
f2f3c86
added some later PG_VERSION_NUM sections for compatibility of the cod…
temuenz Jan 20, 2026
52eba74
moved deparse functions from db2_fdw_utils to db2_deparse
temuenz Jan 21, 2026
0a6efdf
adding more parsing functions
temuenz Jan 21, 2026
0eedf45
add fetchsize to the fdw
temuenz Jan 22, 2026
ffd991a
fix warn on cast SQLULEN to SQLPOINTER
temuenz Jan 26, 2026
e96a453
adding fetchsize to fdwState (de)serializing
temuenz Jan 26, 2026
36a797a
addinf fetch_size to fdwState (de)serializing
temuenz Jan 26, 2026
b7a2479
more preparations for push down of aggregates
temuenz Jan 26, 2026
2377212
just define FIXED_FETCH_SIZE
temuenz Jan 26, 2026
71b2f6e
added debug tracing
temuenz Jan 26, 2026
cc0c0ae
save the old file just in case we need to revert quickly
temuenz Jan 27, 2026
e3803ab
added retrieved_attr list
temuenz Jan 27, 2026
fe5ac4f
factor out de/serializatin of plan to a new file
temuenz Jan 27, 2026
433f278
factor our de / serialization of plan data
temuenz Jan 27, 2026
fe324b8
rework of building the foreign plan
temuenz Jan 27, 2026
a858678
more deparsing rework
temuenz Jan 27, 2026
633492f
adding JWT Token to de / serialization of fdw_state
temuenz Jan 28, 2026
ef9add1
follow up #107 change in this branch
temuenz Jan 28, 2026
fe3c77e
more preparations for push down of aggregate functions
temuenz Feb 6, 2026
c705ff6
the repo has moved to pg-fdw
temuenz Feb 6, 2026
02f9a34
Update documentation to reflect correct GitHub URL and author email
temuenz Feb 6, 2026
16ddb47
first working version of aggregate push down
temuenz Feb 7, 2026
958c187
refactor convertTuple to simply iterate over the expected results and…
temuenz Feb 8, 2026
3a95713
remove columnindex from DB2FdwState since it is no longer used
temuenz Feb 8, 2026
3616fc8
if ever, this new will be version 18.2.0
temuenz Feb 8, 2026
a6a428d
enhanced debug output
temuenz Feb 10, 2026
8ea2d54
solved the problem of multiple columns in an aggregate function as we…
temuenz Feb 10, 2026
f714d2e
enhanced debugging output
temuenz Feb 10, 2026
10599e5
fixed the test for an expression is a column of any of the relations …
temuenz Feb 10, 2026
eb9e25d
handle NULLs correctly
temuenz Feb 10, 2026
e821a20
remove the reverting of the resulnumber. The aim now is to ensure the…
temuenz Feb 10, 2026
39d9120
removed pgtype and directly used res->pgtype
temuenz Feb 10, 2026
31dd92e
started to set resnum correctly, but on foreignjoinpaths the way the …
temuenz Feb 10, 2026
d1cf6c7
enhanced Debug Traces
temuenz Feb 11, 2026
a95d209
ensure the result columns are correctly sorted as mentioned in the qu…
temuenz Feb 11, 2026
2751024
use the correct db2PrepareQuery Prototype
temuenz Feb 11, 2026
9e35a04
cleanup the code formatting
temuenz Feb 12, 2026
1069821
cleanup code
temuenz Feb 12, 2026
7aacff1
adding relevant binding parameters to ParamDesc so it can be bound wi…
temuenz Feb 12, 2026
f104353
more dead code cleanup
temuenz Feb 12, 2026
378b203
add pathnodes.h to ensure elements if DB2FdWState are resovable where…
temuenz Feb 13, 2026
ee10ad2
rearrange the sequence of options sources to reflect the order of pre…
temuenz Feb 13, 2026
b2f5724
define PQ_QUERY_PARAM_MAX_LIMIT if not defined yet
temuenz Feb 13, 2026
fc65ff3
aligned the code more with how postgres_fdw does it
temuenz Feb 13, 2026
14ec5b8
removed foreign.h and pathnodes.h since they are included in DB2FdwSt…
temuenz Feb 13, 2026
af0a84c
enhance debug tracing
temuenz Feb 13, 2026
d2f069d
enhance debug tracing
temuenz Feb 13, 2026
a7b40a0
when one column signals inclusion of all colums the logic was not cop…
temuenz Feb 13, 2026
0e87370
enhanced debug tracing
temuenz Feb 13, 2026
493221d
renaming Db2Column.varno to pgrelid which is the index of the relatio…
temuenz Feb 14, 2026
27be15f
proper formatting of pointers
temuenz Feb 14, 2026
7ae9dcf
actually for analyze we seem not to be needing any results. The code …
temuenz Feb 14, 2026
1c3b3cb
fixed a typo in debug output
temuenz Feb 14, 2026
4644f2b
add all the db2 column attributes to the fdw column option. with that…
temuenz Feb 15, 2026
9ffaa23
remove OLD_FDW_API precompile exclusions from the code
temuenz Feb 15, 2026
0c9e27d
adding db2bytes and db2chars as fdw column options
temuenz Feb 16, 2026
83f0afe
reworked ImportForeignSchema that adds all necessary db2 column info …
temuenz Feb 16, 2026
cea7b38
code cleanup
temuenz Feb 16, 2026
cd5c230
added a compiler error when using PG < 13
temuenz Feb 17, 2026
254ab30
rncols no longer required
temuenz Feb 17, 2026
02fd943
cleanup code
temuenz Feb 17, 2026
6014f8e
first try the new way of describing the fdw table if that fails use t…
temuenz Feb 17, 2026
9d86f6c
the function has been added to db2GetFdwState, as it is only used there
temuenz Feb 17, 2026
484f8cd
db2Getoptions.c has become obsolete
temuenz Feb 17, 2026
e9f4f24
code and debug beautifying
temuenz Feb 17, 2026
14c9103
oops forgot to move optionIsTrue - now in db2_fdw_utils.c
temuenz Feb 17, 2026
056e6b0
prepare DirectModify Function for UPDATE and DELETE
temuenz Feb 22, 2026
39e072e
ensure the value of serialized and deserialized FDWState is printed a…
temuenz Feb 22, 2026
356a205
still trying to get the Update to work but the junkres does not bear …
temuenz Feb 22, 2026
9026f72
complete rework of the debug tracing functions
temuenz Feb 24, 2026
83ce160
migration of debug tracing to macros defined in db2_fdw.h
temuenz Feb 24, 2026
a60ed92
direct update and direct delete now work, but the code is likely not …
temuenz Feb 27, 2026
bfb8005
instead of allocating indentation, just move the output in the output…
temuenz Mar 1, 2026
cf1f3ee
adding comments to functions
temuenz Mar 1, 2026
fcbb1df
estate and rtinfo are currently not used in db2IterateDirectModify, b…
temuenz Mar 1, 2026
1310c8b
using db2alloc instead of palloc
temuenz Mar 1, 2026
155786c
adding a debug trace before freeing resCol
temuenz Mar 1, 2026
cd552c1
on insert we lost the input value of the key, so adding to look for i…
temuenz Mar 1, 2026
a817975
fix a debug message
temuenz Mar 1, 2026
02c8267
simply use the Key Column name for the junkresname as well, it seems …
temuenz Mar 1, 2026
72db297
ensure junk attrs are only obtained on UPDATE and DELETE. Obtain the …
temuenz Mar 1, 2026
b502bc6
obtaining junk attr values is now easy by simple using pkey value.
temuenz Mar 1, 2026
3689351
refactored convertTuple to call it from functions using both DB2FdwSt…
temuenz Mar 2, 2026
6cc7c05
added proper return of affected rows
temuenz Mar 2, 2026
0bc7c21
fail on error when deployed to an too old pg version (<13)
temuenz Mar 5, 2026
f1d2f65
introduced PG_SUPPORTED_MIN_VERSION
temuenz Mar 5, 2026
180fa63
ensure the code compiles for PG 13 thru 18
temuenz Mar 5, 2026
a488d44
moving the includes for pure sqlcli functions to db2_fdw.h
temuenz Mar 7, 2026
08c9727
adding db2Log, db2LogInfo, db2LogNotice, db2LogWarning and db2LogErro…
temuenz Mar 7, 2026
365c5c4
completed prototype for the debugging functions.
temuenz Mar 7, 2026
2bb9d38
removed more pre PG V13 defines
temuenz Mar 7, 2026
ecedc8d
changed memory management functions in code to use macros for better …
temuenz Mar 7, 2026
ac4736b
fixing query like "select empno, firstnme,lastname, salary + bonus + …
temuenz Apr 19, 2026
e4c5672
porting fixes for #110, #111, #112 and #113 into this branch
temuenz May 3, 2026
acb8f8b
modularize the testing
temuenz May 6, 2026
17d58fa
TC001: Dropping and re-creating a foreign table "manually"
temuenz May 6, 2026
2835f04
TC002: Importing a single foreign table from a remote schema
temuenz May 6, 2026
5c082e8
TC003: Run a simple join
temuenz May 6, 2026
5ff62cb
TC004: clone a foreign table into a local table including content
temuenz May 6, 2026
eca8eb1
TC005: run a pushdown query for aggregate functions
temuenz May 6, 2026
83feee0
test results
temuenz May 6, 2026
2158e01
update license and remove LivingMainframe from it
temuenz May 6, 2026
d819f27
fixing TC007
temuenz May 9, 2026
f832ae5
new testcases added
temuenz May 9, 2026
e8c44f6
fixing push down LIMIT n OFFEST m;
temuenz May 9, 2026
d02c0f5
extending TC011
temuenz May 9, 2026
0940ff9
enhanced testcases
temuenz May 10, 2026
bc14218
enhanced push down order by limit offset
temuenz May 10, 2026
1ae53ca
more tests
temuenz May 17, 2026
250c96e
reword fdw options and follow up on documentation
temuenz May 17, 2026
924dcee
update doc
temuenz May 17, 2026
6783115
current testresult
temuenz May 17, 2026
8323331
Merge branch 'master' into Enable-Push-Down-Functions
temuenz May 17, 2026
2602e37
Merge remote-tracking branch 'refs/remotes/origin/Enable-Push-Down-Fu…
temuenz May 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
The PostgreSQL License

Copyright (c) 2023, Ing Wolfgang Brandl.
Copyright (c) 2025, Thomas Muenz, Living-Mainframe GmbH.
Copyright (c) 2025, Thomas Muenz, PG_FDW Project.

Wolfgang Brandl, Thomas Muenz and Living-Mainframe Gmbh, furthermore called "the developers".
Wolfgang Brandl, Thomas Muenz, furthermore called "the developers".

Permission to use, copy, modify, and distribute this software and its documentation for any purpose, without fee, and without a written agreement is hereby granted, provided that the above copyright notice and this paragraph and the following two paragraphs appear in all copies.

Expand Down
4 changes: 2 additions & 2 deletions META.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "db2_fdw",
"abstract": "PostgreSQL Data Wrappper to DB2 databases",
"description": "With the Data Wrapper you can acces DB2 Tabels. Not supported for all Data Types (BLOB over 2 GByte)",
"version": "18.1.2",
"version": "18.2.0",
"maintainer": [
"Thomas Muenz <thomas.muenz@pg-fdw.de>"
],
Expand All @@ -12,7 +12,7 @@
"abstract": "PostgreSQL Data Wrappper to DB2 databases",
"file": "sql/db2_fdw.sql",
"docfile": "doc/db2_fdw.md",
"version": "18.1.2"
"version": "18.2.0"
}
},
"resources": {
Expand Down
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ EXTENSION = db2_fdw
EXTVERSION = $(shell grep default_version $(EXTENSION).control | sed -e "s/default_version[[:space:]]*=[[:space:]]*'\([^']*\)'/\1/")
MODULE_big = db2_fdw
OBJS = source/db2_fdw.o\
source/db2_deparse.o\
source/db2_de_serialize.o\
source/db2GetForeignPlan.o\
source/db2GetForeignPaths.o\
source/db2GetForeignUpperPaths.o\
source/db2GetForeignJoinPaths.o\
source/db2AnalyzeForeignTable.o\
source/db2ExplainForeignScan.o\
Expand All @@ -26,12 +29,12 @@ OBJS = source/db2_fdw.o\
source/db2ExplainForeignModify.o\
source/db2IsForeignRelUpdatable.o\
source/db2ImportForeignSchema.o\
source/db2ImportForeignSchemaData.o\
source/db2GetFdwState.o\
source/db2GetForeignRelSize.o\
source/db2ReAllocFree.o\
source/db2SetHandlers.o\
source/db2Callbacks.o\
source/db2GetOptions.o\
source/db2Debug.o\
source/db2ServerVersion.o\
source/db2ClientVersion.o\
Expand All @@ -44,7 +47,6 @@ OBJS = source/db2_fdw.o\
source/db2FreeStmtHdl.o\
source/db2GetSession.o\
source/db2Describe.o\
source/db2GetImportColumn.o\
source/db2PrepareQuery.o\
source/db2BindParameter.o\
source/db2ExecuteQuery.o\
Expand All @@ -64,6 +66,10 @@ OBJS = source/db2_fdw.o\
source/db2Shutdown.o\
source/db2CopyText.o\
source/db2IsStatementOpen.o\
source/db2PlanDirectModify.o\
source/db2BeginDirectModify.o\
source/db2IterateDirectModify.o\
source/db2EndDirectModify.o\
source/db2_utils.o
RELEASE = $(shell grep default_version $(EXTENSION).control | sed -e "s/default_version[[:space:]]*=[[:space:]]*'\([^']*\)'/\1/")
DATA = $(wildcard sql/*--*.sql)
Expand All @@ -76,7 +82,7 @@ REGRESS_OPTS = --inputdir=test
# to your extention.
#
#MODULES = $(patsubst %.c,%,$(wildcard src/*.c))
PG_CPPFLAGS = -g -fPIC -I$(DB2_HOME)/include -I./include
PG_CPPFLAGS = -fPIC -I$(DB2_HOME)/include -I./include
SHLIB_LINK = -fPIC -L$(DB2_HOME)/lib64 -L$(DB2_HOME)/bin -ldb2
PG_CONFIG ?= pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
Expand Down
96 changes: 87 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,33 @@ Foreign server options
This can be in any of the forms that DB2 supports as long as your
DB2 client is configured accordingly.

- **batch_size** (optional, default 100)

In future enhancements batch_size will be used to operate cunks of rows of that size in batch mode.
Usage in LOAD and INSERT BATCH scenarios is envisaged.

- **no_encoding_error** (optional, "ON", "OFF", "YES", "NO", "TRUE", "FALSE")

If this option is set to ON, YES, TRUE errors are generated on encoding problems.
By default these errors are suppressed.

User mapping options
--------------------

- **user** (required)
- **user** (optional - mutual exclusive to jwt_password, one use is required)

The DB2 user name for the session.
Set this to an empty string for *external authentication* if you don't
want to store DB2 credentials in the PostgreSQL database (one simple way
is to use an *external password store*).

- **password** (required)
- **password** (optional - mutual exclusive to jwt_password, one use is required)

The password for the DB2 user.

- **jwt_token** (optional - mutual exclusive to user&password, one use is required)

The password for the DB2 user.
Foreign table options
---------------------

Expand All @@ -209,15 +222,12 @@ Foreign table options
occurs in DB2's system catalog, so normally consist of uppercase letters
only.

- **max_long** (optional, defaults to "32767")
- **max_long** (optional, now deprecated - no longer used)

The maximal length of any LONG or LONG RAW columns in the DB2 table.
Possible values are integers between 1 and 1073741823 (the maximal size of a
`bytea` in PostgreSQL). This amount of memory will be allocated at least
twice, so large values will consume a lot of memory.
If **max_long** is less than the length of the longest value retrieved,
you will receive the error message `ORA-01406: fetched column value was
truncated`.

- **readonly** (optional, defaults to "false")

Expand All @@ -228,7 +238,7 @@ Foreign table options
on tables that you do not wish to be changed, to be prepared for an upgrade
to PostgreSQL 9.3 or later.

- **sample_percent** (optional, defaults to "100")
- **sample_percent** (optional, defaults to "100.0")

This option only influences ANALYZE processing and can be useful to
ANALYZE very large tables in a reasonable time.
Expand All @@ -241,16 +251,35 @@ Foreign table options
ANALYZE will fail with ORA-00933 for tables defined with DB2 queries and
may fail with ORA-01446 for tables defined with complex DB2 views.

- **prefetch** (optional, defaults to "200")
- **prefetch** (aka SQL_ATTR_PREFETCH_NROWS optional, defaults to "100")

Sets the number of rows that will be fetched with a single round-trip between
PostgreSQL and DB2 during a foreign table scan. This is implemented using
DB2 row prefetching. The value must be between 0 and 10240, where a value
DB2 row prefetching. The value must be between 0 and 1024, where a value
of zero disables prefetching.

Higher values can speed up performance, but will use more memory on the
PostgreSQL server.

- **fetch_size** (optional, fix 1)

In future enhancements fetch_size will be used to enable fetching of that number of rows at once.
Currently any number is ignored and 1 is used as a fix value, until the logic to cope with a larger result that one is implemnted.

- **batch_size** (optional, default 100)

In future enhancements batch_size will be used to operate cunks of rows of that size in batch mode.
Usage in LOAD and INSERT BATCH scenarios is envisaged.
A value defined on a table will override the value provided on the server, just for that table.

- **no_encoding_error** (optional, "ON", "OFF", "YES", "NO", "TRUE", "FALSE")

If this option is set to ON, YES, TRUE errors are generated on encoding problems.
By default these errors are suppressed.
Providing this on a table level sets all columns to this value, diffenent from the system wide setting given
explicitly or implicitly on the server.


Column options (from PostgreSQL 9.2 on)
---------------------------------------

Expand All @@ -261,6 +290,48 @@ Column options (from PostgreSQL 9.2 on)
For UPDATE and DELETE to work, you must set this option on all columns
that belong to the table's primary key.

- **db2type** (required)

On import the SQL value of the datatype is stored, identifying the DB2 datatype to db2_fdw.
It is required to re-construct the table description internally for db2_fdw.

- **db2size** (required)

On import the length of the column as defined in the DB2 catalog is stored.
It is required to re-construct the table description internally for db2_fdw.

- **db2bytes** (required)

On import the number of bytes derived from the datatype, encoding as provided by DB2 is stored.
It is required to re-construct the table description internally for db2_fdw.

- **db2chars** (required)

On import the number of characters derived from the datatype, encoding as provided by DB2 is stored.
It is required to re-construct the table description internally for db2_fdw.

- **db2scale** (required)

On import the scale of a decimal value as provided by DB2 is stored.
It is required to re-construct the table description internally for db2_fdw.

- **db2null** (required)

The nullable characteristic (0 = NULLABLE, 1 = NOT NULL) as provided by DB2 is stored.
It is required to re-construct the table description internally for db2_fdw.

- **db2ccsid** (required)

On import the ccsid of the encoding as provided by DB2 is stored.
It is required to re-construct the table description internally for db2_fdw.

- **no_encoding_error** (optional, "ON", "OFF", "YES", "NO", "TRUE", "FALSE")

If this option is set to ON, YES, TRUE errors are generated on encoding problems.
By default these errors are suppressed.
Providing this on a column level sets this columns to this value, diffenent from the system wide setting given
explicitly or implicitly on the server, or the table wide settings given on the table level.

4 Usage
=======

Expand Down Expand Up @@ -301,6 +372,13 @@ If you want to UPDATE or DELETE, make sure that the `key` option is set on all
columns that belong to the table's primary key. Failure to do so will result
in errors.

If the remote table does not have a key defined you may alter the foreign table
manually for defining a column key:

ALTER FOREIGN TABLE <schema>.<tablename>
ALTER COLUMN <columnname> OPTIONS (ADD key 'true');


Data types
----------

Expand Down
2 changes: 1 addition & 1 deletion db2_fdw.control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# db2_fdw extension
comment = 'foreign data wrapper for DB2 access'
default_version = '18.1.2'
default_version = '18.2.0'
module_pathname = '$libdir/db2_fdw'
relocatable = true
39 changes: 18 additions & 21 deletions include/DB2Column.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,24 @@
* @since 1.0
*/
typedef struct db2Column {
char* colName; // column name in DB2
short colType; // column data type in DB2
size_t colSize; // column size
short colScale; // column scale of size describing digits right of decimal point
short colNulls; // column is nullable
size_t colChars; // numer of characters fit in column size, it is less if UTF8, 16 or DBCS
size_t colBytes; // number of bytes representing colSize
int colPrimKeyPart;// 1 if column is part of the primary key - only relevant for UPDATE or DELETE
int colCodepage; // codepage set for this column (only set on char columns), if 0 the content is binary
char* pgname; // PG column name
int pgattnum; // PG attribute number
Oid pgtype; // PG data type
int pgtypmod; // PG type modifier
int used; // is the column used in the query?
int pkey; // nonzero for primary keys, later set to the resjunk attribute number
char* val; // buffer for DB2 to return results in (LOB locator for LOBs)
size_t val_size; // allocated size in val
size_t val_len; // actual length of val
int val_null; // indicator for NULL value
int varno; // range table index of this column's relation
db2NoEncErrType noencerr; // no encoding error produced
char* colName; // column name in DB2
short colType; // column data type in DB2
size_t colSize; // column size
short colScale; // column scale of size describing digits right of decimal point
short colNulls; // column is nullable
size_t colChars; // numer of characters fit in column size, it is less if UTF8, 16 or DBCS
size_t colBytes; // number of bytes representing colSize
int colPrimKeyPart; // 1 if column is part of the primary key - only relevant for UPDATE or DELETE
int colCodepage; // codepage set for this column (only set on char columns), if 0 the content is binary
int pgrelid; // range table index of this column's relation
char* pgname; // PG column name
int pgattnum; // PG attribute number
Oid pgtype; // PG data type
int pgtypmod; // PG type modifier
int used; // is the column used in the query?
int pkey; // nonzero for primary keys, later set to the resjunk attribute number
size_t val_size; // allocated size in val
db2NoEncErrType noencerr; // no encoding error produced
} DB2Column;

#endif
68 changes: 68 additions & 0 deletions include/DB2FdwDirectModifyState.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#ifndef DB2FDWDIRECTMODIFYSTATE_H
#define DB2FDWDIRECTMODIFYSTATE_H

#include <foreign/foreign.h>
#include <foreign/fdwapi.h>
#include <funcapi.h>
#include "ParamDesc.h"
#include "DB2ResultColumn.h"

// Execution state of a foreign scan that modifies a foreign table directly.
typedef struct db2FdwDirectModifyState {
// DB2 Section
char* dbserver; // DB2 connect string
char* user; // DB2 username
char* password; // DB2 password
char* jwt_token; // JWT token for authentication (alternative to user/password)
char* nls_lang; // DB2 locale information
DB2Session* session; // encapsulates the active DB2 session
ParamDesc* paramList; // description of parameters needed for the query
DB2ResultColumn* resultList; // list of result columns for the query
DB2Table* db2Table; // description of the remote DB2 table
unsigned long prefetch; // number of rows to prefetch (SQL_ATTR_PREFETCH_NROWS 0-1024)
int fetch_size; // fetch size for this remote table (SQL_ATTR_ROW_ARRAY_SIZE 1 - 32767)
Relation rel; // relcache entry for the foreign table
AttInMetadata* attinmeta; // attribute datatype conversion metadata
// extracted fdw_private data
char* query; // text of UPDATE/DELETE command
bool has_returning; // is there a RETURNING clause?
List* retrieved_attrs; // attr numbers retrieved by RETURNING
bool set_processed; // do we set the command es_processed?
// for remote query execution
int numParams; // number of parameters passed to query
FmgrInfo* param_flinfo; // output conversion functions for them
List* param_exprs; // executable expressions for param values
const char** param_values; // textual values of query parameters
// for storing result tuples
// PGresult* result; // result for query
int num_tuples; // # of result tuples
int next_tuple; // index of next one to return
Relation resultRel; // relcache entry for the target relation
AttrNumber* attnoMap; // array of attnums of input user columns
AttrNumber ctidAttno; // attnum of input ctid column
AttrNumber oidAttno; // attnum of input oid column
bool hasSystemCols; // are there system columns of resultRel?
// working memory context
MemoryContext temp_cxt; // context for per-tuple temporary data
} DB2FdwDirectModifyState;

/* Similarly, this enum describes what's kept in the fdw_private list for
* a ForeignScan node that modifies a foreign table directly. We store:
*
* 1) UPDATE/DELETE statement text to be sent to the remote server
* 2) Boolean flag showing if the remote query has a RETURNING clause
* 3) Integer list of attribute numbers retrieved by RETURNING, if any
* 4) Boolean flag showing if we set the command es_processed
*/
enum FdwDirectModifyPrivateIndex {
// SQL statement to execute remotely (as a String node)
FdwDirectModifyPrivateUpdateSql,
// has-returning flag (as a Boolean node)
FdwDirectModifyPrivateHasReturning,
// Integer list of attribute numbers retrieved by RETURNING
FdwDirectModifyPrivateRetrievedAttrs,
// set-processed flag (as a Boolean node)
FdwDirectModifyPrivateSetProcessed,
};

#endif
21 changes: 21 additions & 0 deletions include/DB2FdwPathExtraData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef DB2FDWPATHEXTRADATA_H
#define DB2FDWPATHEXTRADATA_H

#include <nodes/pathnodes.h>

/** Struct for extra information passed to estimate_path_cost_size()
*
* @author Thomas Muenz
* @since 18.1.1
*/

typedef struct DB2FdwPathExtraData {
PathTarget* target;
bool has_final_sort;
bool has_limit;
double limit_tuples;
int64 count_est;
int64 offset_est;
} DB2FdwPathExtraData;

#endif
Loading
Loading