Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oPXAz-0007B9-JO for pgsql-general@arkaria.postgresql.org; Sat, 20 Aug 2022 22:42:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oPXAx-0001TF-H9 for pgsql-general@arkaria.postgresql.org; Sat, 20 Aug 2022 22:42:43 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oPXAw-0001So-Vj for pgsql-general@lists.postgresql.org; Sat, 20 Aug 2022 22:42:43 +0000 Received: from anteater.ash.relay.mailchannels.net ([23.83.222.3]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oPXAp-0001WW-G3 for pgsql-general@lists.postgresql.org; Sat, 20 Aug 2022 22:42:41 +0000 X-Sender-Id: a2hosting|x-authuser|pedz+easesoftware.com@mi3-ss4.a2hosting.com Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 6F4572A184E for ; Sat, 20 Aug 2022 22:42:30 +0000 (UTC) Received: from mi3-ss4.a2hosting.com (unknown [127.0.0.6]) (Authenticated sender: a2hosting) by relay.mailchannels.net (Postfix) with ESMTPA id D3E832A17A6 for ; Sat, 20 Aug 2022 22:42:29 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1661035350; a=rsa-sha256; cv=none; b=WsRFszqG/GVPCnuV0egu9tRg59Y29fi/h9w+EdWiksCvxcmTJ+rX6vmwjk8AI5QWeh+PEC D9TRedQUMD39hG5BhrznqqM4pOr+eotOIaTAD6s4gBkIvR4J3Z7WrX5AFWZEx4FInhUtLW eUukrtQTk6ylJybc1HROkXCm6agVmkz9xrFPUM5/674vko+7w6tp3roBpkphv11Z9zM2Y5 eTk9MZ1dsJmIwpUBYQi28A2gZumo2kSSxsi90t2A3ICO66VMuVLhTX0uU9DtUwvVjblH62 PsNEbVo/P53jW+sXbFxxcFCongsZuTUbJ0TayIa2sZW+0gPuPHnJlmU3r1s/CA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1661035350; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: dkim-signature; bh=CxIAxx2a2en6fyYsB3A7W7Fcu/Z/jeob95j1J5r9oM8=; b=gV8acdBWfwZ0+Xm4r833K3lYw6fp4u3Ik4xPLuUnjj+UYBFVyPpc2XWo/xlSCikGQ8aOWb jnQokReOL9IeJ+WwIdeSidQZAcn8/QiAI2IhMX/2+2+j+q9fJqSCcCPPGN/+rJNxYZasMw Xdx3yVk8SXcjCdWD2ArHGfg/V6Zcc8r8bM4akKd7HgZxGvF+0keYbxIf0c4GzIoyIt+KL3 xrznum55iDRwVlK7T5DkCAiJ6ddPMMHtQSya3MoiIZni57DfRu7Gz0kp+RSaeqsR6Y3lJ0 v8uGzg22OegBbX8iFprcCZnriy7JCs7fVO82n/TnOS+j+qv8eu1Ikwyar9j7CA== ARC-Authentication-Results: i=1; rspamd-79945fd77c-qls8j; auth=pass smtp.auth=a2hosting smtp.mailfrom=pedz@easesoftware.com X-Sender-Id: a2hosting|x-authuser|pedz+easesoftware.com@mi3-ss4.a2hosting.com X-MC-Relay: Neutral X-MailChannels-SenderId: a2hosting|x-authuser|pedz+easesoftware.com@mi3-ss4.a2hosting.com X-MailChannels-Auth-Id: a2hosting X-Dime-Shrill: 408f33367f1040d0_1661035350199_974733769 X-MC-Loop-Signature: 1661035350199:4059251266 X-MC-Ingress-Time: 1661035350199 Received: from mi3-ss4.a2hosting.com (mi3-ss4.a2hosting.com [68.66.200.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.112.55.195 (trex/6.7.1); Sat, 20 Aug 2022 22:42:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=easesoftware.com; s=default; h=To:Date:Message-Id:Subject:Mime-Version: Content-Type:From:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=CxIAxx2a2en6fyYsB3A7W7Fcu/Z/jeob95j1J5r9oM8=; b=X9HLmsaZNBixEBS4QDRXW0wzQA Ak/e4S0NNlNOJN2AOFztAAshqhN4bg9N55ip09z3K0LhjBIwHeklsxcKQUuI/ISphYfL8Wxn8Lhfx XFZmcdKznmgYZ6peJXq/rVB+gLiPDON9Uafx649+oAtDe+X69EEVmq0ftkE2VPCYK5EJ69Ku+U7u8 +Gjjilo3TBnO48RSzLNNl4+hMTT4i1a6VxuWyJDXslFZnoHwSdv8oeZy1vfEGQVe0p0uNsmQ4z800 8sp3r1+JE3VGAqSndckdws+/mM0tRUketRqA7wnqePYWQUef5X4Znaf+Dzrq4NVSBJfqV8a6VV0wk im4aQ8JA==; Received: from cpe-70-94-128-193.satx.res.rr.com ([70.94.128.193]:56464 helo=smtpclient.apple) by mi3-ss4.a2hosting.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1oPXAi-0005h1-KG for pgsql-general@lists.postgresql.org; Sat, 20 Aug 2022 18:42:28 -0400 From: Perry Smith Content-Type: multipart/signed; boundary="Apple-Mail=_90727624-EE3B-411B-8BBB-AF0DAC2AC89D"; protocol="application/pgp-signature"; micalg=pgp-sha256 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Subject: With Recursive / Recursive View question Message-Id: <9F77CCA4-8039-435E-8166-7C7CBC90F39F@easesoftware.com> Date: Sat, 20 Aug 2022 17:42:27 -0500 To: pgsql-general list X-Mailer: Apple Mail (2.3696.120.41.1.1) X-AuthUser: pedz+easesoftware.com@mi3-ss4.a2hosting.com List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_90727624-EE3B-411B-8BBB-AF0DAC2AC89D Content-Type: multipart/alternative; boundary="Apple-Mail=_69F2F6DE-D2F7-4C63-B087-B100096EC2EC" --Apple-Mail=_69F2F6DE-D2F7-4C63-B087-B100096EC2EC Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 This select is almost instant: WITH RECURSIVE pathname(id, parent_id, basename) AS ( SELECT child.id, child.parent_id, child.basename FROM dirents child WHERE basename =3D '10732.emlx' UNION ALL SELECT parent.id, parent.parent_id, CONCAT(parent.basename, '/', = child.basename) FROM dirents parent, pathname child WHERE parent.id =3D child.parent_id ) SELECT basename FROM pathname where parent_id IS NULL; Note that the non-recursive term selects the children and the recursion = is =E2=80=9Cout=E2=80=9D towards the ancestors. This select doesn=E2=80=99t complete before I get impatient: CREATE RECURSIVE VIEW pathname(id, basename, parent_id, ino, ext, = fullpath) AS SELECT id, basename, parent_id, ino, ext, basename FROM dirents WHERE parent_id IS NULL UNION ALL SELECT child.id, child.basename, child.parent_id, child.ino, = child.ext, CONCAT(parent.fullpath, '/', child.basename) FROM dirents child, pathname parent WHERE parent.id =3D child.parent_id; SELECT * FROM pathname WHERE basename =3D '10732.emlx=E2=80=99; In this case, the non-recursive term starts at the top of the directory = trees and the recursion works =E2=80=9Cin=E2=80=9D towards the children. I=E2=80=99m not surprised that the first is fast and the second is very = slow. My problem is I currently have a file called recurse.sql which is = the top query. I go in and edit that file and then execute it via psql = -f recurse.sql. What I=E2=80=99m attempting to do in the second example = is to create a view and then use select on the view to select the rows = that I=E2=80=99m looking for. To rephrase, is it possible to write a view that would work from the = child terms out towards the ancestors? Thank you for your time, Perry --Apple-Mail=_69F2F6DE-D2F7-4C63-B087-B100096EC2EC Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 This = select is almost instant:

WITH RECURSIVE = pathname(id, parent_id, basename) AS (
    = SELECT child.id, = child.parent_id, child.basename
    FROM dirents = child
    WHERE basename =3D '10732.emlx'
  UNION ALL
    SELECT parent.id, parent.parent_id, = CONCAT(parent.basename, '/', child.basename)
    = FROM dirents parent, pathname child
    WHERE parent.id =3D = child.parent_id
)
SELECT basename FROM = pathname where parent_id IS NULL;

Note that the = non-recursive term selects the children and the recursion is =E2=80=9Cout=E2= =80=9D towards the ancestors.

This select doesn=E2=80=99t complete = before I get impatient:

CREATE RECURSIVE VIEW pathname(id, basename, parent_id, ino, = ext, fullpath) AS
     SELECT id, basename, = parent_id, ino, ext, basename
     FROM = dirents
     WHERE parent_id IS NULL
   UNION ALL
    =  SELECT child.id, = child.basename, child.parent_id, child.ino, child.ext, = CONCAT(parent.fullpath, '/', child.basename)
    =  FROM dirents child, pathname parent
    =  WHERE parent.id =3D = child.parent_id;

SELECT * FROM pathname WHERE = basename =3D '10732.emlx=E2=80=99;

In this case, the = non-recursive term starts at the top of the directory trees and the = recursion works =E2=80=9Cin=E2=80=9D towards the children.

I=E2=80=99m not = surprised that the first is fast and the second is very slow.  My = problem is I currently have a file called recurse.sql which is the top = query.  I go in and edit that file and then execute it via psql -f = recurse.sql.  What I=E2=80=99m attempting to do in the second = example is to create a view and then use select on the view to select = the rows that I=E2=80=99m looking for.

To rephrase, is it possible to write a = view that would work from the child terms out towards the = ancestors?

Thank= you for your time,
Perry

= --Apple-Mail=_69F2F6DE-D2F7-4C63-B087-B100096EC2EC-- --Apple-Mail=_90727624-EE3B-411B-8BBB-AF0DAC2AC89D Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEE5yOa/gCtQpb3oCpljxzk9yzE+MAFAmMBY1MACgkQjxzk9yzE +MCRYxAAxWd3XIvq1NkAnoEfBG6xEDLzeIt2lpvFn3MaIb+yLOj3FyXqSmSeG/fJ FOa43JEbmxhBKfzLBBdPKzRZQCYb6hmhEBy1krVbSIz69Rtqk5rQRM9iTIJ0n/Eu wTu7PSRS7IGRIpbCQNQja9RXEJI+XbtMq/HPiTV6Ht7Tm30NPngV7HtXHKENff/f KspWjviFryLP71yZSowEHV8/pxNg4ORnuYXaUq4pzIXp0DZdTRqijHo0UiXT8gAN 7tVojhrobp/dyE9SOCLHQ+wDjX80RqWhvl9lvT25SzZ3KQJuzNPjAjbMFdi1iC05 waslWNNZ2Rx6bhYqRkFo7FSWEMmJcVVSMiQ8UKfGRC0Z+GJXhgauWsBJ1eVQS/CK ICah8YXmWVTsndhgqrutRiVhrsK/xHDRVI625kCpzNj1sgerxZiH9xwkVE8hgOdJ L3RUmN/7fTVGZflQY6BE32GdRpUDyQy5LfUVr5AR69X0hLvvj7ebtXxGFLd5Xj2Z zk9xRsL3haR0kmexoINvlSCoEahgpoQkhoyNWztNAr/tmJraYXo0w74N1xQgk27u +IwlE93GEXl7vT4MCn9UMoYT1J7baHMcVJyvFxjHMopCutzgyrzT+JXpf/1rA4Cl mvN0XXasufX3LHX0BMQhbwk4zDz/Hgy0sZiILGLxoWoBeiFbGcg= =w+Yb -----END PGP SIGNATURE----- --Apple-Mail=_90727624-EE3B-411B-8BBB-AF0DAC2AC89D--