-
Notifications
You must be signed in to change notification settings - Fork 7.9k
ext/pgsql: adding pg_result_memory_size. #14214
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
Conversation
@@ -66,6 +66,7 @@ if test "$PHP_PGSQL" != "no"; then | |||
AC_CHECK_LIB(pq, pg_encoding_to_char,AC_DEFINE(HAVE_PGSQL_WITH_MULTIBYTE_SUPPORT,1,[Whether libpq is compiled with --enable-multibyte])) | |||
AC_CHECK_LIB(pq, lo_truncate64, AC_DEFINE(HAVE_PG_LO64,1,[PostgreSQL 9.3 or later])) | |||
AC_CHECK_LIB(pq, PQsetErrorContextVisibility, AC_DEFINE(HAVE_PG_CONTEXT_VISIBILITY,1,[PostgreSQL 9.6 or later])) | |||
AC_CHECK_LIB(pq, PQresultMemorySize, AC_DEFINE(HAVE_PG_RESULT_MEMORY_SIZE,1,[PostgreSQL 12 or later])) |
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.
NOTE:
PostgreSQL: Documentation: 12: E.20. Release 12
https://www.postgresql.org/docs/12/release-12.html#id-1.11.6.24.5.9
E.20.3.7. Client Interfaces
- Add libpq function
PQresultMemorySize()
to report the memory used by a query result (Lars Kanis, Tom Lane)
No, it s not necessary in this case neither. |
Looks pretty straightforward and correct, will look again later today. |
|
||
$db = pg_connect($conn_str); | ||
|
||
$result = pg_query($db, 'select 1'); |
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.
question: is the memory usage deterministic right ? If that s the case if I redo this query it should be the same amount correct ?
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.
The memory usage returned by PQresultMemorySize()
for the same query is generally consistent, but this cannot be guaranteed in all cases due to several factors:
- Version of libpq: Although significant differences are unlikely, the lack of documented specifications of
libpq
means we cannot ensure identical behavior across all versions. - CPU architecture: Differences in architecture could potentially influence memory usage.
- Query purity: Non-deterministic elements, such as the output of
VOLATILE
functions or results fromINSERT INTO .. RETURNING ...
/UPDATE ... RETURNING
, can affect the memory used.
Based on some tests with simple queries, the memory usage has been consistent when none of these variables are at play. However, I must note that I am not deeply familiar with the internal implementation of libpq
, so while my response is based on research and tests, it might not cover all possible scenarios.
(For the above reasons, I did not write the output size directly in the test, but instead tested by comparing the two results)
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.
Thanks for the detail but what I meant if within your test if I do
$result = pg_query($db, 'select 1');
$size_3 = pg_result_memory_size($result);
var_dump($size_1 == $size_3);
it should be true then ?
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.
Yes, true
in that case.
(Although not guaranteed, I don't think this behavior will change.)
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.
Looking good.
Retrieve the memory usage of the query result resource.
Returns the value of
PQresultMemorySize()
provided by the client librarylibpq
as is. The memory here is allocated internally bylibpq
, so until now there was no way for the user to directly check it.Is an RFC necessary to introduce this feature? Although
pg_set_error_context_visibility()
added in #11395 did not require an RFC, please confirm if one is needed for this case.