ext/pgsql: add meta_cache per-link metadata caching#21885
ext/pgsql: add meta_cache per-link metadata caching#21885arshidkv12 wants to merge 5 commits intophp:masterfrom
Conversation
|
I may have a look later but one large thing I notice is the conflict of interest between persistent connections and request scoped caching. There is probably more to it .. |
|
I need to check as follows. Is that correct? if (!link->persistent && link->meta_cache) {
// check cache
}
if (!link->persistent && !link->meta_cache) {
// allocate cache
} |
| int i, num_rows, err; | ||
| zval elem; | ||
| pgsql_link_handle *link; | ||
| link = FETCH_DEFAULT_LINK_NO_WARNING(); |
There was a problem hiding this comment.
FETCH_DEFAULT_LINK_NO_WARNING() in php_pgsql_meta_data is wrong. The function gets PGconn *pg_link but the cache is looked up against the default link. Those don't match with multiple connections, and OO callers (no default link set) get no caching at all. The pgsql_link_handle * needs to be plumbed through.
There was a problem hiding this comment.
Thank you. How can I obtain a pgsql_link_handle *link from a PGconn *pgsql? I believe we cannot replace pgsql_link_handle with PGconn, as it would break the API. How can this be resolved?
There was a problem hiding this comment.
You can't ; plumb the handle through instead. The usual way is to keep the existing PHP_PGSQL_API symbol for ABI and introduce an internal variant taking the link directly. In-tree callers all have it on hand.
| RETURN_FALSE; | ||
| } | ||
|
|
||
| if (link->meta_cache) { |
There was a problem hiding this comment.
Invalidation is incomplete. Wiping on pg_query() only — pg_query_params, pg_execute, pg_prepare, and the pg_send_* family all leave stale entries
| FREE_HASHTABLE(link->notices); | ||
| link->notices = NULL; | ||
| } | ||
| if (link->meta_cache) { |
There was a problem hiding this comment.
This is pretty repetitive. Could be a helper.
|
You really do need to focus on solving design flaws I mentioned earlier. Even then, there might be other issues when I do a 2nd pass. |
We could store a direct PGconn > pgsql_link mapping using a HashTable for O(1) lookup: zend_hash_index_update_ptr(&PGG(conn_to_link), (zend_ulong) pg_conn, link);
link = zend_hash_index_find_ptr(&PGG(conn_to_link), (zend_ulong) pg_conn);This avoids repeated lookups or iteration. What do you think? |
|
Rather not, that adds another structure with its own lifetime concerns (insert/remove on connect/close, persistent vs request) just to work around the first one. The handle is already reachable without a side map. Worth a look at how other helpers in the file get it passed in. Should be enough for your agent to get started. |
|
I do not think it s going to cut it, I'd suggest to put it in draft mode and going through the eviction part, the cache design and so on ... Cheers. |
|
Thank you |
|
I do not think you re extremely far behind neither but once you re done, there is need for tests too. Good luck |
php_pgsql_meta_data()to avoid repeated catalog queriesPQexec()for faster metadata accessmeta_cacheon connection free and query mutationspg_query/pg_deleteto avoid stale schema dataNULL-safechecks forlink->meta_cacheusageImproves performance by reducing repeated queries.