Re: [HACKERS] Custom Data Type Question

2006-11-16 Thread Greg Mitchell



A simpler way to do this might be to only cache the list per query
context. In your IO functions, you could whack a pointer to your cache
onto fcinfo-flinfo-fn_extra, and the same flinfo gets passed in for
e.g. all output function calls for that column for that query, IIRC.
This was what I had in mind originally when I did the enum patch, but I
ended up just using syscaches, which I think would be unavailable to you
writing a UDT.


If my understanding is correct, if fn_extra is null, I would palloc() my
data cache and store the pointer in fn_extra? What about freeing this
pointer? Or is cleanup automatic?

Also, are there any ADTs like a hash-map or tree-map in the server
libraries (my background is C++ and am use to having std::map) or do I
need to role my  own?

I am using enumkit for some true enums I have in the DB and like it very
much. Though I tend to customize the C-code to optimize it for my use.

Thanks,
Greg

---(end of broadcast)---
TIP 7: You can help support the PostgreSQL project by donating at

   http://www.postgresql.org/about/donate


Re: [HACKERS] Custom Data Type Question

2006-11-16 Thread Greg Mitchell
As far as memory management goes, do I just use hash_create() and assign 
that pointer to fn_extra and at the end of the query it will be freed? 
Or will it not be freed until this end of the transaction? I'm really 
having trouble understanding the memory management issues with Postgres.


Greg

Andrew Dunstan wrote:

Greg Mitchell wrote:




Also, are there any ADTs like a hash-map or tree-map in the server
libraries (my background is C++ and am use to having std::map) or do I
need to role my  own?




Look at the dynahash code. I just used it for the first time in a plperl 
patch, and it's reasonably straightforward.


cheers

andrew



---(end of broadcast)---
TIP 2: Don't 'kill -9' the postmaster


[HACKERS] Custom Data Type Question

2006-11-15 Thread Greg Mitchell
I'm trying to create a custom data type similar to an enumeration type. 
However, I'd like the mapping of the int-string to be dynamic instead 
of hard coded. I'd like to have a table that contains this mapping that 
can be appended to. Creating this type is not very difficult. However, 
for performance reasons, I'd like to cache the mapping so that the table 
is only queried once every connection unless it changes. I'm thinking a 
combination of a flag that can be triggered on insert and a transaction 
id could be used to decide if the table needs to be reloaded. 
Unfortunately, I'm not exactly sure how to get started on this, any ideas?


Thanks,
Greg

---(end of broadcast)---
TIP 9: In versions below 8.0, the planner will ignore your desire to
  choose an index scan if your joining column's datatypes do not
  match