Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fr2HT-0001DZ-AQ for pgsql-general@arkaria.postgresql.org; Sat, 18 Aug 2018 14:32:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fr2HR-0000mY-Nm for pgsql-general@arkaria.postgresql.org; Sat, 18 Aug 2018 14:32:41 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fr2HR-0000mR-A8 for pgsql-general@lists.postgresql.org; Sat, 18 Aug 2018 14:32:41 +0000 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fr2HN-00069t-SZ for pgsql-general@postgresql.org; Sat, 18 Aug 2018 14:32:40 +0000 Received: by mail-wm0-x234.google.com with SMTP id f21-v6so10109161wmc.5 for ; Sat, 18 Aug 2018 07:32:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:references:in-reply-to:subject:date:message-id:mime-version :content-transfer-encoding:content-language:thread-index; bh=0ZPcw41yhx724/vUT7qH44GNCki5C5sumSkSYC0St1M=; b=L7WVxauZa3o76mbTp7XGCI8sPidIuMsfljLL1sovA9nXw5PXFp9I58iJaGPzBuJ1ZO lI4PwkvinhTJrsORoWyBn7PFodWuLf7/eW8RRBnVXm0O/UcGs/oVMTjMgSzY+X7HgXij i3bxdyicc99cAtoSUK5nCnumv+gf7gm4NAxsksvE/crcagQym276iIY+xGOolToY8R/c skA38rZRaLjVTmyUn8tPSY/4Ty4UEVRSyqcYMB67+vVTv6gX4IwMsr9cul5aodXnMt0t JMkqKWDbiSTExuSWjHbTlOXwe3qBc1Xb4eNIOL+E5zNUoEtsUNYoKEghOAgRzIdAcNnZ fKxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:references:in-reply-to:subject:date :message-id:mime-version:content-transfer-encoding:content-language :thread-index; bh=0ZPcw41yhx724/vUT7qH44GNCki5C5sumSkSYC0St1M=; b=PI6LS6tHgjYzJu7DuJx0TOn4CR5Fox/mETx5TBgUzI/LdlYh4AjyTlL6x0QFP4VYfP 4V2OxUQNxMb3sJAljtvCI0Aqvv/RefFDRsWGwgwSz1lrvVE57znR9foG4rwTj1IHIlZ6 I5ZEGMJ8WW/Bv3kODOY21JyuRNKZAZYrVxH9u/UL3ehK3pQ9hQNT4C+bqdMtWuaFlutL qpU84QformMrwk1J0bvUQZSZO0ORVKSGoToiZnTGKNc9WUdcRWrRMH/LR93WCXe8HjpR mQai0QJ7cl6kNZQKBU7rj5iPJC/3xtsnaLbzlcvxhJ5vXzf+nrScUIbghpuv17eRCpfJ gZ+w== X-Gm-Message-State: AOUpUlEV0UZkSIsEox89EA4dmpgALHN3ZaR5b4bS2nHuOFg2xNVexryy HqsjKueDMSLnvNTL/HAJ8sJfzB4T X-Google-Smtp-Source: AA+uWPweTZ+MnupSlLDqtOFQXJVqtumDiP9FGXLlvQ3rdkdOY5B3nVScyhwUo0HoZC0lfN+GaPadFg== X-Received: by 2002:a1c:8952:: with SMTP id l79-v6mr20206441wmd.7.1534602755588; Sat, 18 Aug 2018 07:32:35 -0700 (PDT) Received: from PC016 (mail.ibeq.com. [212.100.42.241]) by smtp.gmail.com with ESMTPSA id g2-v6sm13995563wrd.71.2018.08.18.07.32.34 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Aug 2018 07:32:34 -0700 (PDT) From: To: References: <004b01d436d6$ff96c840$fec458c0$@gmail.com> <42ce9b74-0671-ecba-3deb-dc8bc8d5e9b3@a-kretschmer.de> <005301d436e3$cb120960$61361c20$@gmail.com> In-Reply-To: Subject: AW: AW: CTE with JOIN of two tables is much faster than a regular query Date: Sat, 18 Aug 2018 16:32:34 +0200 Message-ID: <005701d43700$4dd920b0$e98b6210$@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 16.0 Content-Language: de Thread-Index: AQMeRW6BypEtj0kC9MzG04zOKiRbkAFjbbbQAakvIgECfdth6QJ/4KOO List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > -----Urspr=C3=BCngliche Nachricht----- > Von: Adrian Klaver > Gesendet: Samstag, 18. August 2018 16:24 >=20 > To try to replicate what the CTE is doing I would try: > SELECT * > FROM Doc > JOIN (SELECT uDocRef, F.oID, Doc.szText > FROM F JOIN Doc ON F.uDocRef =3D Doc.udocid) AS D > ON D.uDocRef =3D Doc.udocid > WHERE D.szText ILIKE '%480GB%' No difference - still starting with the full scan on Doc and lasting 67 = seconds:=20 "Nested Loop (cost=3D8006.98..8700.40 rows=3D5 width=3D750) (actual = time=3D66845.857..66852.705 rows=3D10 loops=3D1)" " -> Hash Join (cost=3D8006.56..8694.93 rows=3D5 width=3D391) (actual = time=3D66845.838..66852.613 rows=3D10 loops=3D1)" " Hash Cond: (f.udocref =3D doc_1.udocid)" " -> Seq Scan on f (cost=3D0.00..566.05 rows=3D32605 = width=3D32) (actual time=3D0.002..3.428 rows=3D32605 loops=3D1)" " -> Hash (cost=3D8006.32..8006.32 rows=3D19 width=3D359) = (actual time=3D66845.431..66845.431 rows=3D16 loops=3D1)" " Buckets: 1024 Batches: 1 Memory Usage: 19kB" " -> Seq Scan on doc doc_1 (cost=3D0.00..8006.32 = rows=3D19 width=3D359) (actual time=3D9042.984..66845.398 rows=3D16 = loops=3D1)" " Filter: (sztext ~~* '%480GB%'::text)" " Rows Removed by Filter: 125930" " -> Index Scan using doc_udocid_key on doc (cost=3D0.42..1.08 = rows=3D1 width=3D375) (actual time=3D0.008..0.008 rows=3D1 loops=3D10)" " Index Cond: (udocid =3D f.udocref)" "Planning time: 252.162 ms" "Execution time: 66852.737 ms"