Skip to content

Commit 2bb8fbd

Browse files
committed
ext/pgsql: add pg_jit server info.
since PostgreSQL 11, LLVM JIT feature had been brought thus reporting the settings to the client connection. Close GH-14566
1 parent 4107cb2 commit 2bb8fbd

File tree

7 files changed

+60
-1
lines changed

7 files changed

+60
-1
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ PHP NEWS
213213
. Added pg_put_copy_data/pg_put_copy_end to send COPY commands and signal
214214
the end of the COPY. (David Carlier)
215215
. Added pg_socket_poll to poll on the connection. (David Carlier)
216+
. Added pg_jit to get infos on server JIT support. (David Carlier)
216217

217218
- Phar:
218219
. Fixed bug GH-12532 (PharData created from zip has incorrect timestamp).

UPGRADING

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ PHP 8.4 UPGRADE NOTES
561561
end-of-data to the server.
562562
. Added pg_socket_poll to check if there is any read and/or write events
563563
with an optional timeout.
564+
. Added pg_jit to get informations on the server JIT support.
564565

565566
- Sodium:
566567
. Added the sodium_crypto_aead_aegis128l_*() and sodium_crypto_aead_aegis256l_*()

Zend/Optimizer/zend_func_infos.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ static const func_info_t func_infos[] = {
333333
F1("pg_tty", MAY_BE_STRING),
334334
F1("pg_host", MAY_BE_STRING),
335335
F1("pg_version", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_LONG|MAY_BE_ARRAY_OF_STRING|MAY_BE_ARRAY_OF_NULL),
336+
F1("pg_jit", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_STRING|MAY_BE_ARRAY_OF_NULL),
336337
F1("pg_parameter_status", MAY_BE_STRING|MAY_BE_FALSE),
337338
F1("pg_query", MAY_BE_OBJECT|MAY_BE_FALSE),
338339
F1("pg_query_params", MAY_BE_OBJECT|MAY_BE_FALSE),

ext/pgsql/pgsql.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,7 @@ PHP_FUNCTION(pg_close)
864864
#define PHP_PG_TTY 5
865865
#define PHP_PG_HOST 6
866866
#define PHP_PG_VERSION 7
867+
#define PHP_PG_JIT 8
867868

868869
/* php_pgsql_get_link_info */
869870
static void php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type)
@@ -929,6 +930,25 @@ static void php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type
929930
PHP_PQ_COPY_PARAM("application_name");
930931
return;
931932
}
933+
case PHP_PG_JIT: {
934+
PGresult *res;
935+
array_init(return_value);
936+
res = PQexec(pgsql, "SHOW jit_provider");
937+
if (PQresultStatus(res) != PGRES_TUPLES_OK) {
938+
add_assoc_null(return_value, "jit_provider");
939+
} else {
940+
add_assoc_string(return_value, "jit_provider", PQgetvalue(res, 0, 0));
941+
}
942+
PQclear(res);
943+
res = PQexec(pgsql, "SHOW jit");
944+
if (PQresultStatus(res) != PGRES_TUPLES_OK) {
945+
add_assoc_null(return_value, "jit");
946+
} else {
947+
add_assoc_string(return_value, "jit", PQgetvalue(res, 0, 0));
948+
}
949+
PQclear(res);
950+
return;
951+
}
932952
EMPTY_SWITCH_DEFAULT_CASE()
933953
}
934954
if (result) {
@@ -980,6 +1000,11 @@ PHP_FUNCTION(pg_version)
9801000
php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAM_PASSTHRU,PHP_PG_VERSION);
9811001
}
9821002

1003+
PHP_FUNCTION(pg_jit)
1004+
{
1005+
php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAM_PASSTHRU,PHP_PG_JIT);
1006+
}
1007+
9831008
/* Returns the value of a server parameter */
9841009
PHP_FUNCTION(pg_parameter_status)
9851010
{

ext/pgsql/pgsql.stub.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,12 @@ function pg_host(?PgSql\Connection $connection = null): string {}
497497
*/
498498
function pg_version(?PgSql\Connection $connection = null): array {}
499499

500+
/**
501+
* @return array<string, string|null>
502+
* @refcount 1
503+
*/
504+
function pg_jit(?PgSql\Connection $connection = null): array {}
505+
500506
/**
501507
* @param PgSql\Connection|string $connection
502508
* @refcount 1

ext/pgsql/pgsql_arginfo.h

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/pgsql/tests/pg_jit.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
PostgreSQL JIT support
3+
--EXTENSIONS--
4+
pgsql
5+
--SKIPIF--
6+
<?php include("inc/skipif.inc"); ?>
7+
--FILE--
8+
<?php
9+
include('inc/config.inc');
10+
11+
$db = pg_connect($conn_str);
12+
var_dump(pg_jit($db));
13+
pg_close($db);
14+
?>
15+
--EXPECTF--
16+
array(2) {
17+
["jit_provider"]=>
18+
%s
19+
["jit"]=>
20+
%s
21+
}

0 commit comments

Comments
 (0)