在PostgreSQL 9.6中并行查询单个连接

编程入门 行业动态 更新时间:2024-10-27 02:29:53
本文介绍了在PostgreSQL 9.6中并行查询单个连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我找到了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中并行查询单个连接

本文发布于:2023-10-20 03:21:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1509692.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:PostgreSQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!