我找到了PostgreSQL 9.6进行的有关并行查询和并行顺序扫描的文档,但是我找不到关于PostgreSQL 9.6是否可以在单个连接上同时运行多个查询的任何信息(我知道我可以打开多个连接并同时运行查询。)
I found the documentation about parallel queries and parallel sequential scans that PostgreSQL 9.6 does, but I couldn't find anything about if PostgreSQL 9.6 can, on a single connection run multiple queries concurrently(I know I can open multiple connections and run the queries simultaneously).
说我有两个要执行的查询(在单个连接上): SELECT * FROM table1; SELECT * FROM table2;
Say I have 2 queries I want to execute(on a single connection): SELECT * FROM table1; SELECT * FROM table2;
这些查询可以在PostgreSQL服务器端同时运行吗?
Is there any way on PostgreSQL server-side for these queries to run concurrently?
请多多指教。
推荐答案使用 pg_send_query 和 pg_get_result 您可以像这样在 PHP 中异步执行多个查询:
Using pg_send_query and pg_get_result you can execute multiple queries asynchronously in PHP like so:
<?php $dbconn = pg_connect("dbname=publisher") or die("Could not connect"); if (!pg_connection_busy($dbconn)) { pg_send_query($dbconn, "select * from authors; select count(*) from authors;"); } $res1 = pg_get_result($dbconn); echo "First call to pg_get_result(): $res1\n"; $rows1 = pg_num_rows($res1); echo "$res1 has $rows1 records\n\n"; $res2 = pg_get_result($dbconn); echo "Second call to pg_get_result(): $res2\n"; $rows2 = pg_num_rows($res2); echo "$res2 has $rows2 records\n"; ?>有关更多信息,您可以参考官方页面
For more info, you can refer to official page
希望对您有所帮助
更多推荐
在PostgreSQL 9.6中并行查询单个连接
发布评论