I'm working on an index access method. I have a function which can appear in a projection list which should be evaluated by the access method itself. Example:
SELECT title, my_special_function(body) FROM books WHERE book_id <===> 42; "<===>" is the operator that invokes the access method. The value returned by my_special_function() gets calculated during the index scan, and depends on information that exists only in the index. How do I get the system to pull the value from the index instead of trying to calculate it? So far, I have created a CustomScan and set it using set_rel_pathlist_hook. The hook function gives us a PlannerInfo, RelOptInfo, Index, and RangeTblEntry. So far as I can tell, only RelOptInfo.reltarget.exprs gives us any info on the SELECT expressions, but unfortunately, the exprs are Var nodes that contain the (title, body) columns from above, and do not say anything about my_special_function(). Where do I find the actual final projection exprs? Am I using the right hook? Is there any example code out there on how to do this? I know this is possible, because the docs for PathTarget say this: PathTarget * * This struct contains what we need to know during planning about the * targetlist (output columns) that a Path will compute. Each RelOptInfo * includes a default PathTarget, which its individual Paths may simply * reference. However, in some cases a Path may compute outputs different * from other Paths, and in that case we make a custom PathTarget for it. * *For example, an indexscan might return index expressions that would * otherwise need to be explicitly calculated.* -- Chris Cleveland 312-339-2677 mobile