Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tUlhD-002YdS-2v for pgsql-general@arkaria.postgresql.org; Mon, 06 Jan 2025 11:54:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tUlhA-008D9G-NK for pgsql-general@arkaria.postgresql.org; Mon, 06 Jan 2025 11:54:56 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tUlhA-008D98-71 for pgsql-general@lists.postgresql.org; Mon, 06 Jan 2025 11:54:55 +0000 Received: from mail-oa1-x30.google.com ([2001:4860:4864:20::30]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tUlh7-000921-2k for pgsql-general@lists.postgresql.org; Mon, 06 Jan 2025 11:54:54 +0000 Received: by mail-oa1-x30.google.com with SMTP id 586e51a60fabf-2a01707db44so4953761fac.2 for ; Mon, 06 Jan 2025 03:54:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736164493; x=1736769293; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=JUSywk76g+I2l5jE1dbWGXKRqePbDzcJOthjm7R47Fg=; b=FSfBNmKiBnlFjGqEHvnQI3/4xKY1vk25E0Pyw9NmdpTzQSfWy6fsJJlM9HkLAIhGAA Z8N6fKPkdr9/WSe583nxiUyTXIu97JNsC/s190l9BL7/aiDFNeH3pvqWcPCVnDO5SJ5U 6LeRVAMcZbHiE9M3ALTAk2bY6TBLfF37SV03aRSQzHTR0Q6UhgdFfYRoZ7c5G45Qy/+g zo9/LCeMp5MOaNAJ7Tq0q0GQSlVug82XtIaNVZoVR4pJX3SMWysc+H8ShUhCLt7i9uMv Yf4pD0NKZeZzOQdtQ6PAczIJpCkIrzRoZDJI/bajmMPIhmrHw4Ellu7JMQWxBNeh2rW2 4L0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736164493; x=1736769293; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JUSywk76g+I2l5jE1dbWGXKRqePbDzcJOthjm7R47Fg=; b=OtMmt5hMmJutB57HOirHN5G3oAT8Q+nydoerk8A+T5TwR9X9GPV25655kKSRI03YIY Cbf22zjB7h1IyYIGIgg97H4H9pKHYUCu17i3sdZEgcgmau+s03rEXDrFIp+E4U6di9gs +UlbFxY6XRlv+nvV0cg2LtdcuCOWHhxHYhF9YVxJsrp2VKUxWjJzqnlUJPMt0wO8MP8f WVkT4kxGY0fNth4V/U037OABV14Ogk74dICFZ9XyYH1jPQQPzacZMO/JB2ZP5WHShI02 26ihGeEkt5AZm6l9bTp5w7gOhP2FC1T6Ev9BEKBUYRXX+2lBDJ2ZYGs2Mhhklo1qCr75 D+Jw== X-Gm-Message-State: AOJu0YzNbtDx2eyc6UzHvYigb2dqTXDZqRHJzU11314E/GpddCCrAkqi K2NZEO9ZX6t/iUu9KwdgKdRLmgmOnFKd5jhRP9KrbqI3tjtVKyqqXbvQa2iy+g8oPbfM31lkXrU Dy9iyzHHEZo2Ymqyey8RrFk2f3ys= X-Gm-Gg: ASbGnctZt+hG2S5LP4x9+UtKUQLgQaSrmRrQu6il3GOeMqBqT6bIBH9auQ8AglxqcLD UZjMjuvhkefHZGi0SfsXSsNaugDOkqK31v9VHtD4W X-Google-Smtp-Source: AGHT+IG1cpWCW5lO2d2abyRC9USO4Xt7HwoW7QI6VtRFSiLfrLEuYVuGgxxwZiEKtBqGeZClf4ssqPi5y/PSzpHgSf4= X-Received: by 2002:a05:6870:1647:b0:29e:3bea:7e67 with SMTP id 586e51a60fabf-2a7fb4c21a1mr29507972fac.38.1736164493214; Mon, 06 Jan 2025 03:54:53 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Dominique Devienne Date: Mon, 6 Jan 2025 12:54:41 +0100 Message-ID: Subject: Re: Will PQsetSingleRowMode get me results faster? To: Stijn Sanders Cc: pgsql-general@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Jan 6, 2025 at 12:21=E2=80=AFPM Stijn Sanders wrote: > I've been using LibPQ to get data from PostgreSQL instances with great su= ccess. > I'm using PQsendQuery and PQgetResult, but noticed there's also PQsetSing= leRowMode. > The documentation is clearly stating it only benefits a limited set of sc= enario's, but I'm saddened that it can't help to get the first resulte of a= (longer running) query faster. I haven't used single-row-mode myself, but I can tell you that using a cursor instead of a statement allows you to reduce your time-to-first-row. But at the expense of overall performance, i.e. in my (limited) testing, getting the whole result-set in one go is faster than getting the same rows via a cursor, even in varying chunk sizes. Another alternative is to use COPY, which gets your the rows as they come, but then you're on your own to "decode" the row and its select-clause. FWIW. --DD