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 1frDtt-0003EX-Uy for pgsql-general@arkaria.postgresql.org; Sun, 19 Aug 2018 02:57:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1frDtr-0002p6-GD for pgsql-general@arkaria.postgresql.org; Sun, 19 Aug 2018 02:57:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1frDtr-0002oy-6A for pgsql-general@lists.postgresql.org; Sun, 19 Aug 2018 02:57:07 +0000 Received: from mail-pl0-x234.google.com ([2607:f8b0:400e:c01::234]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1frDtj-0007Oa-Ss for pgsql-general@postgresql.org; Sun, 19 Aug 2018 02:57:06 +0000 Received: by mail-pl0-x234.google.com with SMTP id ba4-v6so5441437plb.11 for ; Sat, 18 Aug 2018 19:56:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=references:user-agent:from:to:cc:subject:in-reply-to:date :message-id:mime-version:content-transfer-encoding; bh=CvwyGEIQ7Ed0WxvRcD1w6vMv8ANWnvBZK1pN8paEqsc=; b=lEj119pCzTpGr3B2/HxP7MaSAlHtIqR9D32IOyb0KWmkfG1Nt437763wGking4rNhw yF+gsBQJ4xBcmyasnn4C57QRwvzOve+KtWHhCuZQQya3985fDFhfpc5UELibD9erUNw+ WDL70sMr8krZJWP4SDZwM5HXvRCIR4544iiF8O5zJj/U21tuouxdoTQyUeSK3VP5Bgxg ey0lvg+j5sNVG2Lp46jDvKxxY7AD08yaQxPNni9m5fgi7ijfk/CV6iEquAIggYVJcSsb x3F9qhaMrAD+SMKIKL9FguiXQoU+SXGnXcCBvGURovCv+RRfAyk6JBK+dio3TTfsK/cW uHNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject :in-reply-to:date:message-id:mime-version:content-transfer-encoding; bh=CvwyGEIQ7Ed0WxvRcD1w6vMv8ANWnvBZK1pN8paEqsc=; b=tT0gEmqW0wMbX0FvSFi7yT75m3N/AooSCwsQ/FcI0iMuLkOTgayeXjLcKCz1dJuK2d nwJ72/fXVj3pmRedGbLsXRUo36nrnuDuZidRVtsYW9TLQdB54ATkux0Xsk+zrQSD4tzo 0v5DWQFXTSojvIGqyVk7qBk/P7Utc+2l+08EQ7ZxziCSNhSbp+DtC4oWAH98pcLc8Crg Ik4Rl2ZfUhJ4MXQNQY1bMqrcQ1lg4ypdBuZM3ZkDqFOVNKY6pAXRTKcsjpsjnJmhAAmL CuFDMFKRW/dUJZHt/P4hUxRQqCSa5zsWqOc+ECX8x/hbInN0lRztPmN9LCVPocV7V7i0 xWdg== X-Gm-Message-State: AOUpUlFNk9y85DU+jihT+9kE57dLgj7W9mjmhweu3Fxn9DBlXjzGdyFX LpoNRs1jEhQeHpbL47dZm/MiujIrOM4= X-Google-Smtp-Source: AA+uWPwOqlqHsvTzF3wUwKEnhDhj/Poo9Cb4h1TdEv0he8uSIL046rkixuFmXH7Tz9sPRGtwRuKfOw== X-Received: by 2002:a17:902:7b96:: with SMTP id w22-v6mr39571235pll.24.1534647416712; Sat, 18 Aug 2018 19:56:56 -0700 (PDT) Received: from tim-desktop (2001-44b8-31f2-bb00-1dbd-18db-d55a-50b1.static.ipv6.internode.on.net. [2001:44b8:31f2:bb00:1dbd:18db:d55a:50b1]) by smtp.gmail.com with ESMTPSA id r23-v6sm10359330pfj.5.2018.08.18.19.56.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 18 Aug 2018 19:56:56 -0700 (PDT) References: <004b01d436d6$ff96c840$fec458c0$@gmail.com> <807123113.9511341.1534609514205@mail.yahoo.com> <007201d43711$33120e20$99362a60$@gmail.com> User-agent: mu4e 0.9.18; emacs 26.1 From: Tim Cross To: kpi6288@gmail.com Cc: pgsql-general@postgresql.org Subject: Re: AW: CTE with JOIN of two tables is much faster than a regular query In-reply-to: <007201d43711$33120e20$99362a60$@gmail.com> Date: Sun, 19 Aug 2018 12:56:52 +1000 Message-ID: <87ftzb5aiz.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk kpi6288@gmail.com writes: >> -----Urspr=C3=BCngliche Nachricht----- >> Von: Ravi Krishna >> Gesendet: Samstag, 18. August 2018 18:25 >>=20 >> > What can I do to improve the performance of the regular query without >> using a CTE? >>=20 >> Why do you care ? When I find that I can write a SQL 3 different ways, = I will >> go for the most efficient one. So why not accept the CTE version of thi= s SQL. >> Just curious. > > We're using object mapping / entity frameworks (e.g. XPO, Entity Framewor= k Core). These frameworks support regular queries out-of-the box; a CTEs re= quire additional effort and are more difficult to maintain.=20 > Ah, another reason to avoid object mapping/entity frameworks! I guess really the same reason - loss of flexibility and expressive power. Sorry, having a similar battle with some developers who are insisting on using a particular framework because it makes maintenance easier as it 'automates' creation of controllers (MVC). However, they are frustrated by performance and I'm frustrated as the framework also fails to pass additional information, such as PGAPPNAME, which would make some analysis easier. Part of the reason for the performance issues is because the developers are doing things with result sets within the client that would be far more efficient performed within the database. One way I have resolved this in the past is to create database procedures which present a 'mapped' view back to the framework layer which hides the SQL from the framework. Works well, with the only main downside being you now have SQL in a different (another) place, which can make some people uncomfortable and can be a maintenance issue if all your developers are just front-end devs who treat a database as just a key/value repository. . Tim --=20 Tim Cross