pdf viewer for asp.net web application : Add png to pdf acrobat control software platform web page windows azure web browser postgresql-9.4-A4199-part2833

Chapter 53. Writing A Foreign Data Wrapper
Alloperationsonaforeigntablearehandledthroughitsforeigndatawrapper,whichconsistsofaset
offunctionsthatthecoreservercalls.Theforeigndatawrapperisresponsibleforfetchingdatafrom
theremotedatasourceandreturningittothePostgreSQLexecutor.Ifupdatingforeigntablesistobe
supported,thewrappermusthandlethat,too.Thischapteroutlineshowtowriteanewforeigndata
wrapper.
Theforeigndatawrappersincludedinthestandarddistributionaregoodreferenceswhentryingto
writeyourown.Lookintothe
contrib
subdirectoryofthesourcetree.TheCREATEFOREIGN
DATAWRAPPERreferencepagealsohassomeusefuldetails.
Note:TheSQLstandardspecifiesaninterfaceforwritingforeigndatawrappers.However,Post-
greSQL doesnotimplementthatAPI,because theeffort to accommodate it into PostgreSQL
wouldbelarge,andthestandardAPIhasn’tgainedwideadoptionanyway.
53.1. Foreign Data Wrapper Functions
TheFDWauthorneedstoimplementahandlerfunction,andoptionallyavalidatorfunction.Both
functionsmustbewritteninacompiledlanguagesuchasC,usingtheversion-1interface.Fordetails
onClanguagecallingconventionsanddynamicloading,seeSection35.9.
Thehandlerfunctionsimplyreturnsastructoffunctionpointerstocallbackfunctionsthatwillbe
calledbytheplanner,executor,andvariousmaintenancecommands.Mostoftheeffortinwritingan
FDWisinimplementingthesecallbackfunctions.ThehandlerfunctionmustberegisteredwithPost-
greSQLastakingnoargumentsandreturningthespecialpseudo-type
fdw_handler
.Thecallback
functionsareplainCfunctionsandarenotvisibleorcallableattheSQLlevel.Thecallbackfunctions
aredescribedinSection53.2.
Thevalidatorfunctionisresponsibleforvalidatingoptionsgivenin
CREATE
and
ALTER
commands
foritsforeigndatawrapper,aswellasforeignservers,usermappings,andforeigntablesusingthe
wrapper.Thevalidatorfunctionmustberegisteredastakingtwoarguments,atextarraycontain-
ingtheoptionstobevalidated, andanOIDrepresentingthetypeofobjecttheoptionsareasso-
ciated with(inthe form m ofthe OIDofthesystemcatalogtheobjectwould be storedin, , either
ForeignDataWrapperRelationId
,
ForeignServerRelationId
,
UserMappingRelationId
,
or
ForeignTableRelationId
).Ifnovalidatorfunctionissupplied,optionsarenotcheckedatob-
jectcreationtimeorobjectalterationtime.
53.2. Foreign Data Wrapper Callback Routines
TheFDWhandlerfunctionreturnsapalloc’d
FdwRoutine
structcontainingpointerstothecallback
functionsdescribedbelow.Thescan-relatedfunctionsarerequired,therestareoptional.
The
FdwRoutine
structtypeisdeclaredin
src/include/foreign/fdwapi.h
,whichseeforad-
ditionaldetails.
1918
Add png to pdf acrobat - insert images into PDF in C#.net, ASP.NET, MVC, Ajax, WinForms, WPF
Sample C# code to add image, picture, logo or digital photo into PDF document page using PDF page editor control
how to add image to pdf; adding image to pdf
Add png to pdf acrobat - VB.NET PDF insert image library: insert images into PDF in vb.net, ASP.NET, MVC, Ajax, WinForms, WPF
Guide VB.NET Programmers How to Add Images in PDF Document
adding image to pdf form; adding an image to a pdf form
Chapter53.WritingAForeignDataWrapper
53.2.1.FDWRoutinesForScanningForeignTables
void
GetForeignRelSize (PlannerInfo
*
root,
RelOptInfo
*
baserel,
Oid foreigntableid);
Obtainrelationsizeestimatesforaforeigntable.Thisiscalledatthebeginningofplanningfora
querythatscansaforeigntable.
root
istheplanner’sglobalinformationaboutthequery;
baserel
istheplanner’sinformationaboutthistable;and
foreigntableid
isthe
pg_class
OIDofthe
foreigntable.(
foreigntableid
couldbeobtainedfromtheplannerdatastructures,butit’spassed
explicitlytosaveeffort.)
This function should update
baserel->rows
to be the expected numberof rows returned by
thetablescan,afteraccountingforthefilteringdonebytherestrictionquals.Theinitialvalueof
baserel->rows
isjustaconstantdefaultestimate,whichshouldbereplacedifatallpossible.The
functionmayalsochoosetoupdate
baserel->width
ifitcancomputeabetterestimateofthe
averageresultrowwidth.
SeeSection53.4foradditionalinformation.
void
GetForeignPaths (PlannerInfo
*
root,
RelOptInfo
*
baserel,
Oid foreigntableid);
Createpossibleaccesspathsforascanonaforeigntable.Thisiscalledduringqueryplanning.The
parametersarethesameasfor
GetForeignRelSize
,whichhasalreadybeencalled.
Thisfunctionmustgenerateatleastoneaccesspath(
ForeignPath
node)forascanontheforeign
tableandmustcall
add_path
toaddeachsuchpathto
baserel->pathlist
.It’srecommended
touse
create_foreignscan_path
tobuildthe
ForeignPath
nodes.Thefunctioncangenerate
multipleaccesspaths,e.g.,apathwhichhasvalid
pathkeys
torepresentapre-sortedresult.Each
accesspathmustcontaincostestimates,andcancontainanyFDW-privateinformationthatisneeded
toidentifythespecificscanmethodintended.
SeeSection53.4foradditionalinformation.
ForeignScan
*
GetForeignPlan (PlannerInfo
*
root,
RelOptInfo
*
baserel,
Oid foreigntableid,
ForeignPath
*
best_path,
List
*
tlist,
List
*
scan_clauses);
Createa
ForeignScan
plannodefromtheselectedforeignaccesspath.Thisiscalledattheendof
queryplanning.Theparametersareasfor
GetForeignRelSize
,plustheselected
ForeignPath
(previouslyproducedby
GetForeignPaths
),thetargetlisttobeemittedbytheplannode,andthe
restrictionclausestobeenforcedbytheplannode.
This function must create and return a
ForeignScan
plan node; it’s recommended to use
make_foreignscan
tobuildthe
ForeignScan
node.
SeeSection53.4foradditionalinformation.
void
1919
C# PDF Converter Library SDK to convert PDF to other file formats
formats, including GIF, BMP, JPEG, PNG and so on. can manipulate & convert standard PDF documents in other external third-party dependencies like Adobe Acrobat.
add picture to pdf preview; how to add a photo to a pdf document
VB.NET PDF: How to Create Watermark on PDF Document within
your VB.NET imaging project; Able to add text or used as PDF watermarks, including, jpeg, bmp, png, gif; Full PDF watermark processing applications in VB.NET are
how to add a jpeg to a pdf; adding an image to a pdf file
Chapter53.WritingAForeignDataWrapper
BeginForeignScan (ForeignScanState
*
node,
int eflags);
Beginexecutingaforeignscan.Thisiscalledduringexecutorstartup.Itshouldperformanyinitial-
izationneededbeforethescancanstart,butnotstartexecutingtheactualscan(thatshouldbedone
uponthefirstcallto
IterateForeignScan
).The
ForeignScanState
nodehasalreadybeencre-
ated,butits
fdw_state
fieldisstillNULL.Informationaboutthetabletoscanisaccessiblethrough
the
ForeignScanState
node(inparticular,fromtheunderlying
ForeignScan
plannode,which
containsanyFDW-privateinformationprovidedby
GetForeignPlan
).
eflags
containsflagbits
describingtheexecutor’soperatingmodeforthisplannode.
Notethatwhen
(eflags & EXEC_FLAG_EXPLAIN_ONLY)
istrue,thisfunctionshouldnotperform
anyexternally-visibleactions;itshouldonlydotheminimumrequiredtomakethenodestatevalid
for
ExplainForeignScan
and
EndForeignScan
.
TupleTableSlot
*
IterateForeignScan (ForeignScanState
*
node);
Fetchonerowfromtheforeignsource,returningitinatupletableslot(thenode’s
ScanTupleSlot
shouldbeusedforthispurpose).ReturnNULLifnomorerowsareavailable.Thetupletableslot
infrastructureallowseitheraphysicalorvirtualtupletobereturned;inmostcasesthelatterchoice
ispreferablefromaperformancestandpoint.Notethatthisiscalledinashort-livedmemorycontext
thatwillberesetbetweeninvocations.Createamemorycontextin
BeginForeignScan
ifyouneed
longer-livedstorage,orusethe
es_query_cxt
ofthenode’s
EState
.
Therowsreturnedmustmatchthecolumnsignatureoftheforeigntablebeingscanned.Ifyouchoose
tooptimizeawayfetchingcolumnsthatarenotneeded,youshouldinsertnullsinthosecolumn
positions.
NotethatPostgreSQL’sexecutordoesn’tcarewhethertherowsreturnedviolateany
NOT NULL
con-
straintsthatweredefinedontheforeigntablecolumns—buttheplannerdoescare,andmayoptimize
queriesincorrectlyif
NULL
valuesarepresentinacolumndeclarednottocontainthem.Ifa
NULL
valueisencounteredwhentheuserhasdeclaredthatnoneshouldbepresent,itmaybeappropriateto
raiseanerror(justasyouwouldneedtodointhecaseofadatatypemismatch).
void
ReScanForeignScan (ForeignScanState
*
node);
Restartthescanfromthebeginning.Notethatanyparametersthescandependsonmayhavechanged
value,sothenewscandoesnotnecessarilyreturnexactlythesamerows.
void
EndForeignScan (ForeignScanState
*
node);
Endthescanandreleaseresources.Itisnormallynotimportanttoreleasepalloc’dmemory,butfor
exampleopenfilesandconnectionstoremoteserversshouldbecleanedup.
53.2.2.FDWRoutinesForUpdatingForeignTables
IfanFDWsupportswritableforeigntables,itshouldprovidesomeorallofthefollowingcallback
functionsdependingontheneedsandcapabilitiesoftheFDW:
void
AddForeignUpdateTargets (Query
*
parsetree,
1920
C# powerpoint - PowerPoint Conversion & Rendering in C#.NET
without using other external third-party dependencies like Adobe Acrobat. and above versions, raster images (Jpeg, Png, Bmp, and PowerPoint to PDF Conversion.
pdf insert image; add image pdf
C# Word - Word Conversion in C#.NET
without using other external third-party dependencies like Adobe Acrobat. be converted from Word document, including Jpeg, Png, Bmp, Gif PDF to Word Conversion.
acrobat insert image into pdf; acrobat add image to pdf
Chapter53.WritingAForeignDataWrapper
RangeTblEntry
*
target_rte,
Relation target_relation);
UPDATE
and
DELETE
operationsareperformedagainstrowspreviouslyfetchedbythetable-scanning
functions.TheFDWmayneedextrainformation,suchas arowIDorthevaluesofprimary-key
columns,toensurethatitcanidentifytheexactrowtoupdateordelete.Tosupportthat,thisfunction
canaddextrahidden,or“junk”,targetcolumnstothelistofcolumnsthataretoberetrievedfromthe
foreigntableduringan
UPDATE
or
DELETE
.
Todothat,add
TargetEntry
itemsto
parsetree->targetList
,containingexpressionsforthe
extravaluestobefetched.Eachsuchentrymustbemarked
resjunk
=
true
,andmusthaveadistinct
resname
thatwillidentifyitatexecutiontime.Avoidusingnamesmatching
ctid
N
,
wholerow
,or
wholerow
N
,asthecoresystemcangeneratejunkcolumnsofthesenames.
Thisfunctioniscalledintherewriter,nottheplanner,sotheinformationavailableisabitdifferent
fromthatavailabletotheplanningroutines.
parsetree
istheparsetreeforthe
UPDATE
or
DELETE
command,while
target_rte
and
target_relation
describethetargetforeigntable.
Ifthe
AddForeignUpdateTargets
pointerissetto
NULL
,noextratargetexpressionsareadded.
(Thiswillmakeitimpossibletoimplement
DELETE
operations,though
UPDATE
maystillbefeasible
iftheFDWreliesonanunchangingprimarykeytoidentifyrows.)
List
*
PlanForeignModify (PlannerInfo
*
root,
ModifyTable
*
plan,
Index resultRelation,
int subplan_index);
Performanyadditionalplanningactionsneededforaninsert,update,ordeleteonaforeigntable.This
functiongeneratestheFDW-privateinformationthatwillbeattachedtothe
ModifyTable
plannode
thatperformstheupdateaction.Thisprivateinformationmusthavetheformofa
List
,andwillbe
deliveredto
BeginForeignModify
duringtheexecutionstage.
root
istheplanner’sglobalinformationaboutthequery.
plan
isthe
ModifyTable
plannode,which
iscompleteexceptforthe
fdwPrivLists
field.
resultRelation
identifiesthetargetforeigntable
byitsrangetableindex.
subplan_index
identifieswhichtargetofthe
ModifyTable
plannodethis
is,countingfromzero;usethisifyouwanttoindexinto
plan->plans
orothersubstructureofthe
plan
node.
SeeSection53.4foradditionalinformation.
Ifthe
PlanForeignModify
pointerissetto
NULL
,noadditionalplan-timeactionsaretaken,andthe
fdw_private
listdeliveredto
BeginForeignModify
willbeNIL.
void
BeginForeignModify (ModifyTableState
*
mtstate,
ResultRelInfo
*
rinfo,
List
*
fdw_private,
int subplan_index,
int eflags);
Beginexecutingaforeigntablemodificationoperation.Thisroutineiscalledduringexecutorstartup.
Itshouldperform anyinitializationneededpriorto theactual tablemodifications. . Subsequently,
ExecForeignInsert
,
ExecForeignUpdate
or
ExecForeignDelete
willbecalledforeachtuple
tobeinserted,updated,ordeleted.
1921
C# Excel - Excel Conversion & Rendering in C#.NET
without using other external third-party dependencies like Adobe Acrobat. 2007 and above versions, raster images (Jpeg, Png, Bmp, and Excel to PDF Conversion.
add a jpg to a pdf; add image to pdf form
JPEG to PDF Converter | Convert JPEG to PDF, Convert PDF to JPEG
software that converts JPEG, TIFF, JPG, TIF, PNG, PCX, GIF is able to convert image files to PDF directly without the software Adobe Acrobat Reader for
add image to pdf acrobat; add multiple jpg to pdf
Chapter53.WritingAForeignDataWrapper
mtstate
istheoverallstateofthe
ModifyTable
plannodebeingexecuted;globaldataabouttheplan
andexecutionstateisavailableviathisstructure.
rinfo
isthe
ResultRelInfo
structdescribingthe
targetforeigntable.(The
ri_FdwState
fieldof
ResultRelInfo
isavailablefortheFDWtostore
anyprivatestateitneedsforthisoperation.)
fdw_private
containstheprivatedatageneratedby
PlanForeignModify
,ifany.
subplan_index
identifieswhichtargetofthe
ModifyTable
plan
nodethisis.
eflags
containsflagbitsdescribingtheexecutor’soperatingmodeforthisplannode.
Notethatwhen
(eflags & EXEC_FLAG_EXPLAIN_ONLY)
istrue,thisfunctionshouldnotperform
anyexternally-visibleactions;itshouldonlydotheminimumrequiredtomakethenodestatevalid
for
ExplainForeignModify
and
EndForeignModify
.
Ifthe
BeginForeignModify
pointerissetto
NULL
,noactionistakenduringexecutorstartup.
TupleTableSlot
*
ExecForeignInsert (EState
*
estate,
ResultRelInfo
*
rinfo,
TupleTableSlot
*
slot,
TupleTableSlot
*
planSlot);
Insertonetupleintotheforeigntable.
estate
isglobalexecutionstateforthequery.
rinfo
isthe
ResultRelInfo
structdescribingthetargetforeigntable.
slot
containsthetupletobeinserted;it
willmatchtherow-typedefinitionoftheforeigntable.
planSlot
containsthetuplethatwasgener-
atedbythe
ModifyTable
plannode’ssubplan;itdiffersfrom
slot
inpossiblycontainingadditional
“junk”columns.(The
planSlot
istypicallyoflittleinterestfor
INSERT
cases,butisprovidedfor
completeness.)
Thereturnvalueiseitheraslotcontainingthedatathatwasactuallyinserted(thismightdifferfrom
thedatasupplied,forexampleasaresultoftriggeractions),orNULLifnorowwasactuallyinserted
(again,typicallyasaresultoftriggers).Thepassed-in
slot
canbere-usedforthispurpose.
Thedatainthereturnedslotisusedonlyifthe
INSERT
queryhasa
RETURNING
clauseortheforeign
tablehasan
AFTER ROW
trigger.Triggersrequireallcolumns,buttheFDWcouldchoosetooptimize
awayreturningsomeorallcolumnsdependingonthecontentsofthe
RETURNING
clause.Regardless,
someslotmustbereturnedtoindicatesuccess,orthequery’sreportedrowcountwillbewrong.
Ifthe
ExecForeignInsert
pointerissetto
NULL
,attemptstoinsertintotheforeigntablewillfail
withanerrormessage.
TupleTableSlot
*
ExecForeignUpdate (EState
*
estate,
ResultRelInfo
*
rinfo,
TupleTableSlot
*
slot,
TupleTableSlot
*
planSlot);
Updateonetupleintheforeigntable.
estate
is globalexecutionstateforthe query.
rinfo
is
the
ResultRelInfo
struct describing the targetforeign table.
slot
contains the newdata for
thetuple;itwillmatchtherow-typedefinitionoftheforeigntable.
planSlot
containsthetuple
thatwas generatedbythe
ModifyTable
plan node’s subplan; itdiffers from
slot
in possibly
containing additional “junk” columns. In particular, any junk columns that were requested by
AddForeignUpdateTargets
willbeavailablefromthisslot.
Thereturnvalueiseitheraslotcontainingtherowasitwasactuallyupdated(thismightdifferfrom
thedatasupplied,forexampleasaresultoftriggeractions),orNULLifnorowwasactuallyupdated
(again,typicallyasaresultoftriggers).Thepassed-in
slot
canbere-usedforthispurpose.
Thedatainthereturnedslotisusedonlyifthe
UPDATE
queryhasa
RETURNING
clauseortheforeign
tablehasan
AFTER ROW
trigger.Triggersrequireallcolumns,buttheFDWcouldchoosetooptimize
1922
C# Windows Viewer - Image and Document Conversion & Rendering in
independently, without using other external third-party dependencies like Adobe Acrobat. common image files, such as Bitmap, Jpeg, Png, Gif): Convert to PDF.
how to add image to pdf file; how to add image to pdf document
VB.NET PowerPoint: VB Code to Draw and Create Annotation on PPT
limitations (other documents are compatible, including PDF, TIFF, MS project, what would you do to add and draw no more plug-ins needed like Acrobat or Adobe
add picture to pdf; add photo to pdf reader
Chapter53.WritingAForeignDataWrapper
awayreturningsomeorallcolumnsdependingonthecontentsofthe
RETURNING
clause.Regardless,
someslotmustbereturnedtoindicatesuccess,orthequery’sreportedrowcountwillbewrong.
Ifthe
ExecForeignUpdate
pointerissetto
NULL
,attemptstoupdatetheforeigntablewillfailwith
anerrormessage.
TupleTableSlot
*
ExecForeignDelete (EState
*
estate,
ResultRelInfo
*
rinfo,
TupleTableSlot
*
slot,
TupleTableSlot
*
planSlot);
Deleteonetuplefromtheforeigntable.
estate
isglobalexecutionstateforthequery.
rinfo
is
the
ResultRelInfo
structdescribingthetargetforeigntable.
slot
containsnothingusefulupon
call,butcanbeusedtoholdthereturnedtuple.
planSlot
containsthetuplethatwasgenerated
bythe
ModifyTable
plannode’ssubplan;inparticular,itwillcarryanyjunkcolumnsthatwere
requestedby
AddForeignUpdateTargets
.Thejunkcolumn(s)mustbeusedtoidentifythetuple
tobedeleted.
Thereturnvalueiseitheraslotcontainingtherowthatwasdeleted,orNULLifnorowwasdeleted
(typicallyasaresultoftriggers).Thepassed-in
slot
canbeusedtoholdthetupletobereturned.
Thedatainthereturnedslotisusedonlyifthe
DELETE
queryhasa
RETURNING
clauseortheforeign
tablehasan
AFTER ROW
trigger.Triggersrequireallcolumns,buttheFDWcouldchoosetooptimize
awayreturningsomeorallcolumnsdependingonthecontentsofthe
RETURNING
clause.Regardless,
someslotmustbereturnedtoindicatesuccess,orthequery’sreportedrowcountwillbewrong.
Ifthe
ExecForeignDelete
pointerissetto
NULL
,attemptstodeletefromtheforeigntablewillfail
withanerrormessage.
void
EndForeignModify (EState
*
estate,
ResultRelInfo
*
rinfo);
Endthetableupdateandreleaseresources.Itisnormallynotimportanttoreleasepalloc’dmemory,
butforexampleopenfilesandconnectionstoremoteserversshouldbecleanedup.
Ifthe
EndForeignModify
pointerissetto
NULL
,noactionistakenduringexecutorshutdown.
int
IsForeignRelUpdatable (Relation rel);
Reportwhichupdateoperationsthespecifiedforeigntablesupports.Thereturnvalueshouldbeabit
maskofruleeventnumbersindicatingwhichoperationsaresupportedbytheforeigntable,usingthe
CmdType
enumeration;thatis,
(1 << CMD_UPDATE) = 4
for
UPDATE
,
(1 << CMD_INSERT) = 8
for
INSERT
,and
(1 << CMD_DELETE) = 16
for
DELETE
.
Ifthe
IsForeignRelUpdatable
pointerissetto
NULL
,foreigntablesareassumedtobeinsertable,
updatable, or deletable if the FDW provides
ExecForeignInsert
,
ExecForeignUpdate
, or
ExecForeignDelete
respectively.ThisfunctionisonlyneedediftheFDWsupportssometables
thatare updatable and some that are not. (Even then, it’s permissible tothrow an errorin the
executionroutineinsteadofcheckinginthisfunction.However,thisfunctionisusedtodetermine
updatabilityfordisplayinthe
information_schema
views.)
1923
BMP to PDF Converter | Convert Bitmap to PDF, Convert PDF to BMP
Also designed to be used add-on for .NET Image SDK, RasterEdge Bitmap Powerful image converter for Bitmap and PDF files; No need for Adobe Acrobat Reader &
how to add image to pdf form; how to add image to pdf reader
GIF to PDF Converter | Convert GIF to PDF, Convert PDF to GIF
and convert PDF files to GIF images with high quality. It can be functioned as an integrated component without the use of external applications & Adobe Acrobat
adding images to pdf forms; add image to pdf java
Chapter53.WritingAForeignDataWrapper
53.2.3.FDWRoutinesfor
EXPLAIN
void
ExplainForeignScan (ForeignScanState
*
node,
ExplainState
*
es);
Print additional
EXPLAIN
output for a foreign table scan. This function can call
ExplainPropertyText
andrelatedfunctionstoaddfieldstothe
EXPLAIN
output.Theflagfields
in
es
canbeusedtodeterminewhattoprint,andthestateofthe
ForeignScanState
nodecanbe
inspectedtoproviderun-timestatisticsinthe
EXPLAIN ANALYZE
case.
Ifthe
ExplainForeignScan
pointerissetto
NULL
, noadditionalinformationis printedduring
EXPLAIN
.
void
ExplainForeignModify (ModifyTableState
*
mtstate,
ResultRelInfo
*
rinfo,
List
*
fdw_private,
int subplan_index,
struct ExplainState
*
es);
Print additional
EXPLAIN
output for a foreign table update. This function can call
ExplainPropertyText
andrelatedfunctionstoaddfieldstothe
EXPLAIN
output.Theflagfields
in
es
canbeusedtodeterminewhattoprint,andthestateofthe
ModifyTableState
nodecanbe
inspectedtoproviderun-timestatisticsinthe
EXPLAIN ANALYZE
case.Thefirstfourargumentsare
thesameasfor
BeginForeignModify
.
Ifthe
ExplainForeignModify
pointerissetto
NULL
,noadditionalinformationisprintedduring
EXPLAIN
.
53.2.4.FDWRoutinesfor
ANALYZE
bool
AnalyzeForeignTable (Relation relation,
AcquireSampleRowsFunc
*
func,
BlockNumber
*
totalpages);
ThisfunctioniscalledwhenANALYZEisexecutedonaforeigntable.IftheFDWcancollectstatis-
ticsforthisforeigntable,itshouldreturn
true
,andprovideapointertoafunctionthatwillcollect
samplerowsfromthetablein
func
,plustheestimatedsizeofthetableinpagesin
totalpages
.
Otherwise,return
false
.
IftheFDWdoesnotsupportcollectingstatisticsforanytables,the
AnalyzeForeignTable
pointer
canbesetto
NULL
.
Ifprovided,thesamplecollectionfunctionmusthavethesignature
int
AcquireSampleRowsFunc (Relation relation, int elevel,
HeapTuple
*
rows, int targrows,
double
*
totalrows,
double
*
totaldeadrows);
Arandomsampleofupto
targrows
rowsshouldbecollectedfromthetableandstoredintothe
caller-provided
rows
array.Theactualnumberofrowscollectedmustbereturned.Inaddition,store
1924
Chapter53.WritingAForeignDataWrapper
estimatesofthetotalnumbersofliveanddeadrowsinthetableintotheoutputparameters
totalrows
and
totaldeadrows
.(Set
totaldeadrows
tozeroiftheFDWdoesnothaveanyconceptofdead
rows.)
53.3. Foreign Data Wrapper Helper Functions
Severalhelperfunctionsareexportedfromthecoreserversothatauthorsofforeigndatawrappers
cangeteasyaccesstoattributesofFDW-relatedobjects,suchasFDWoptions.Touseanyofthese
functions,youneedtoincludetheheaderfile
foreign/foreign.h
inyoursourcefile.Thatheader
alsodefinesthestructtypesthatarereturnedbythesefunctions.
ForeignDataWrapper
*
GetForeignDataWrapper(Oid fdwid);
Thisfunctionreturnsa
ForeignDataWrapper
objectfortheforeign-datawrapperwiththegiven
OID.A
ForeignDataWrapper
objectcontainspropertiesoftheFDW(see
foreign/foreign.h
fordetails).
ForeignServer
*
GetForeignServer(Oid serverid);
This function returns a
ForeignServer
object for the foreign server with the given OID. A
ForeignServer
objectcontainspropertiesoftheserver(see
foreign/foreign.h
fordetails).
UserMapping
*
GetUserMapping(Oid userid, Oid serverid);
Thisfunctionreturnsa
UserMapping
objectfortheusermappingofthegivenroleonthegiven
server.(Ifthereisnomappingforthespecificuser,itwillreturnthemappingfor
PUBLIC
,orthrow
error if there is none.) A
UserMapping
object contains properties of the user mapping (see
foreign/foreign.h
fordetails).
ForeignTable
*
GetForeignTable(Oid relid);
This function returns a
ForeignTable
object for the foreign table with the given OID. A
ForeignTable
object contains properties of the foreign table (see
foreign/foreign.h
for
details).
List
*
GetForeignColumnOptions(Oid relid, AttrNumber attnum);
Thisfunctionreturnstheper-columnFDWoptionsforthecolumnwiththegivenforeigntableOID
andattributenumber,intheformofalistof
DefElem
.NILisreturnedifthecolumnhasnooptions.
Someobjecttypeshavename-basedlookupfunctionsinadditiontotheOID-basedones:
ForeignDataWrapper
*
GetForeignDataWrapperByName(const char
*
name, bool missing_ok);
Thisfunctionreturnsa
ForeignDataWrapper
objectfortheforeign-datawrapperwiththegiven
name.Ifthewrapperisnotfound,returnNULLifmissing_okistrue,otherwiseraiseanerror.
1925
Chapter53.WritingAForeignDataWrapper
ForeignServer
*
GetForeignServerByName(const char
*
name, bool missing_ok);
Thisfunctionreturnsa
ForeignServer
objectfortheforeignserverwiththegivenname.Ifthe
serverisnotfound,returnNULLifmissing_okistrue,otherwiseraiseanerror.
53.4. Foreign Data Wrapper Query Planning
TheFDWcallbackfunctions
GetForeignRelSize
,
GetForeignPaths
,
GetForeignPlan
,and
PlanForeignModify
mustfitintotheworkingsofthePostgreSQLplanner.Herearesomenotes
aboutwhattheymustdo.
Theinformationin
root
and
baserel
canbeusedtoreducetheamountofinformationthathasto
befetchedfromtheforeigntable(andthereforereducethecost).
baserel->baserestrictinfo
isparticularlyinteresting,asitcontainsrestrictionquals(
WHERE
clauses)thatshouldbeusedtofilter
therowstobefetched.(TheFDWitselfisnotrequiredtoenforcethesequals,asthecoreexecutorcan
checktheminstead.)
baserel->reltargetlist
canbeusedtodeterminewhichcolumnsneedto
befetched;butnotethatitonlylistscolumnsthathavetobeemittedbythe
ForeignScan
plannode,
notcolumnsthatareusedinqualevaluationbutnotoutputbythequery.
VariousprivatefieldsareavailablefortheFDWplanningfunctionstokeepinformationin.Generally,
whateveryoustoreinFDWprivatefieldsshouldbepalloc’d,sothatitwillbereclaimedattheendof
planning.
baserel->fdw_private
isa
void
pointerthatisavailableforFDWplanningfunctionstostore
informationrelevanttotheparticularforeigntable.Thecoreplannerdoesnottouchitexceptto
initialize it to NULL when the
baserel
node is created. It is useful for passing information
forward from
GetForeignRelSize
to
GetForeignPaths
and/or
GetForeignPaths
to
GetForeignPlan
,therebyavoidingrecalculation.
GetForeignPaths
canidentifythemeaningofdifferentaccesspathsbystoringprivateinformation
inthe
fdw_private
fieldof
ForeignPath
nodes.
fdw_private
isdeclaredasa
List
pointer,but
couldactuallycontainanythingsincethecoreplannerdoesnottouchit.However,bestpracticeisto
usearepresentationthat’sdumpableby
nodeToString
,forusewithdebuggingsupportavailablein
thebackend.
GetForeignPlan
canexaminethe
fdw_private
fieldoftheselected
ForeignPath
node,andcan
generate
fdw_exprs
and
fdw_private
liststobeplacedinthe
ForeignScan
plannode,wherethey
willbeavailableatexecutiontime.Bothoftheselistsmustberepresentedinaformthat
copyObject
knowshowtocopy.The
fdw_private
listhasnootherrestrictionsandisnotinterpretedbythecore
backendinanyway.The
fdw_exprs
list,ifnotNIL,isexpectedtocontainexpressiontreesthatare
intendedtobeexecutedatruntime.Thesetreeswillundergopost-processingbytheplannertomake
themfullyexecutable.
In
GetForeignPlan
,generallythepassed-intargetlistcanbecopiedintotheplannodeas-is.The
passed
scan_clauses
listcontainsthesameclausesas
baserel->baserestrictinfo
,butmay
bere-orderedforbetterexecutionefficiency.InsimplecasestheFDWcanjuststrip
RestrictInfo
nodesfromthe
scan_clauses
list(using
extract_actual_clauses
)andputalltheclausesinto
theplannode’squallist,whichmeansthatalltheclauseswillbecheckedbytheexecutoratruntime.
MorecomplexFDWsmaybeabletochecksomeoftheclausesinternally,inwhichcasethoseclauses
canberemovedfromtheplannode’squallistsothattheexecutordoesn’twastetimerecheckingthem.
Asanexample,theFDWmightidentifysomerestrictionclausesoftheform
foreign_variable
= sub_expression
, which it determines can be executed on the remote server given the
locally-evaluatedvalueofthe
sub_expression
.Theactualidentificationofsuchaclauseshould
1926
Chapter53.WritingAForeignDataWrapper
happenduring
GetForeignPaths
,sinceitwouldaffectthecostestimateforthepath.Thepath’s
fdw_private
field would probably include a pointerto the identified clause’s
RestrictInfo
node. Then
GetForeignPlan
would remove that clause from
scan_clauses
, but add the
sub_expression
to
fdw_exprs
toensurethatitgetsmassagedintoexecutableform. Itwould
probablyalsoputcontrolinformationintotheplannode’s
fdw_private
fieldtotelltheexecution
functions what to do at run time. The query transmitted to the remote server would involve
somethinglike
WHERE
foreign_variable
= $1
, withtheparametervalueobtained atruntime
fromevaluationofthe
fdw_exprs
expressiontree.
The FDWshouldalways constructatleastone paththatdepends onlyonthe table’s restriction
clauses. In join queries, it might also choose to construct path(s) that depend onjoinclauses,
for example
foreign_variable = local_variable
. Such clauses will not be found in
baserel->baserestrictinfo
butmustbesoughtintherelation’sjoinlists.Apathusingsucha
clauseiscalleda“parameterizedpath”.Itmustidentifytheotherrelationsusedintheselectedjoin
clause(s)withasuitablevalueof
param_info
;use
get_baserel_parampathinfo
tocompute
thatvalue.In
GetForeignPlan
,the
local_variable
portionofthejoinclausewouldbeaddedto
fdw_exprs
,andthenatruntimethecaseworksthesameasforanordinaryrestrictionclause.
Whenplanningan
UPDATE
or
DELETE
,
PlanForeignModify
canlookupthe
RelOptInfo
structfor
theforeigntableandmakeuseofthe
baserel->fdw_private
datapreviouslycreatedbythescan-
planningfunctions.However,in
INSERT
thetargettableisnotscannedsothereisno
RelOptInfo
forit.The
List
returnedby
PlanForeignModify
hasthesamerestrictionsasthe
fdw_private
listofa
ForeignScan
plannode,thatisitmustcontainonlystructuresthat
copyObject
knowshow
tocopy.
Foran
UPDATE
or
DELETE
againstanexternaldatasourcethatsupportsconcurrentupdates,itisrec-
ommendedthatthe
ForeignScan
operationlocktherowsthatitfetches,perhapsviatheequivalent
of
SELECT FOR UPDATE
.TheFDWmayalsochoosetolockrowsatfetchtimewhentheforeignta-
bleisreferencedina
SELECT FOR UPDATE/SHARE
;ifitdoesnot,the
FOR UPDATE
or
FOR SHARE
optionisessentiallyano-opsofarastheforeigntableisconcerned.Thisbehaviormayyieldse-
manticsslightlydifferentfromoperationsonlocaltables,whererowlockingiscustomarilydelayed
aslongaspossible:remoterowsmaygetlockedeventhoughtheysubsequentlyfaillocally-applied
restrictionorjoinconditions.However,matchingthelocalsemanticsexactlywouldrequireanad-
ditionalremoteaccessforeveryrow,andmightbeimpossibleanywaydependingonwhatlocking
semanticstheexternaldatasourceprovides.
1927
Documents you may be interested
Documents you may be interested