-
Notifications
You must be signed in to change notification settings - Fork 7.9k
ext/pgsql: adding cache for the tables meta data. #11193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
6e2ee9a
to
bda8f5e
Compare
cc @Girgias any guidance about how to fix those ?
They are coming from the hash insertions, asan does not report anything but I can reproduce it locally. Cheers |
ext/pgsql/pgsql.c
Outdated
|
||
tmp = (zval *)safe_emalloc(1, sizeof(zval), 0); | ||
ZVAL_COPY(tmp, meta); | ||
zend_hash_add(zmeta, (zend_string *)table_name, tmp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zend_hash_add(zmeta, (zend_string *)table_name, tmp); | |
zend_hash_add(zmeta, table_name, tmp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in fact locally I opted for the zend_hash_str* api to avoid this.
ext/pgsql/pgsql.c
Outdated
@@ -4147,7 +4151,6 @@ PHP_FUNCTION(pg_flush) | |||
|
|||
/* {{{ php_pgsql_meta_data | |||
* table_name must not be empty | |||
* TODO: Add meta_data cache for better performance | |||
*/ | |||
PHP_PGSQL_API zend_result php_pgsql_meta_data(PGconn *pg_link, const zend_string *table_name, zval *meta, bool extended) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First let's drop the const qualifier, as the hash insertion is trying to increase the refcount of the zend_string (and also compute the hash on it).
PHP_PGSQL_API zend_result php_pgsql_meta_data(PGconn *pg_link, const zend_string *table_name, zval *meta, bool extended) | |
PHP_PGSQL_API zend_result php_pgsql_meta_data(PGconn *pg_link, zend_string *table_name, zval *meta, bool extended) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah right, will look at it later.
bda8f5e
to
ed9a106
Compare
ext/pgsql/pgsql.c
Outdated
|
||
tmp = (zval *)safe_emalloc(1, sizeof(zval), 0); | ||
ZVAL_COPY(tmp, meta); | ||
zend_hash_add(zmeta, table_name, tmp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This leaks because meta
here is still emalloc
ed. You'd need to copy the entire array to "process-space" recursively. May I suggest making the cache request-bound? This problem goes away, along with potential cache-invalidation issues. Even with request-bound cache I'm wondering, if the table changes during the request (could be a CLI process) we'd need a way to clear the cache.
No description provided.