pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
AW: AW: CTE with JOIN of two tables is much faster than a regular query
2+ messages / 1 participants
[nested] [flat]

* AW: AW: CTE with JOIN of two tables is much faster than a regular query
@ 2018-08-18 14:32  kpi6288@gmail.com
  1 sibling, 0 replies; 2+ messages in thread

From: kpi6288@gmail.com @ 2018-08-18 14:32 UTC (permalink / raw)
  To: pgsql-general

> -----Ursprüngliche Nachricht-----
> Von: Adrian Klaver <adrian.klaver@aklaver.com>
> Gesendet: Samstag, 18. August 2018 16:24
> 
> 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 = Doc.udocid) AS D
> ON D.uDocRef = Doc.udocid
> WHERE D.szText ILIKE '%480GB%'

No difference - still starting with the full scan on Doc and lasting 67 seconds: 

"Nested Loop  (cost=8006.98..8700.40 rows=5 width=750) (actual time=66845.857..66852.705 rows=10 loops=1)"
"  ->  Hash Join  (cost=8006.56..8694.93 rows=5 width=391) (actual time=66845.838..66852.613 rows=10 loops=1)"
"        Hash Cond: (f.udocref = doc_1.udocid)"
"        ->  Seq Scan on f  (cost=0.00..566.05 rows=32605 width=32) (actual time=0.002..3.428 rows=32605 loops=1)"
"        ->  Hash  (cost=8006.32..8006.32 rows=19 width=359) (actual time=66845.431..66845.431 rows=16 loops=1)"
"              Buckets: 1024  Batches: 1  Memory Usage: 19kB"
"              ->  Seq Scan on doc doc_1  (cost=0.00..8006.32 rows=19 width=359) (actual time=9042.984..66845.398 rows=16 loops=1)"
"                    Filter: (sztext ~~* '%480GB%'::text)"
"                    Rows Removed by Filter: 125930"
"  ->  Index Scan using doc_udocid_key on doc  (cost=0.42..1.08 rows=1 width=375) (actual time=0.008..0.008 rows=1 loops=10)"
"        Index Cond: (udocid = f.udocref)"
"Planning time: 252.162 ms"
"Execution time: 66852.737 ms"






^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* AW: AW: CTE with JOIN of two tables is much faster than a regular query
@ 2018-08-19 09:07  kpi6288@gmail.com
  1 sibling, 0 replies; 2+ messages in thread

From: kpi6288@gmail.com @ 2018-08-19 09:07 UTC (permalink / raw)
  To: pgsql-general

> -----Ursprüngliche Nachricht-----
> Von: Tim Cross <theophilusx@gmail.com>
> Gesendet: Sonntag, 19. August 2018 04:57
> >
> > We're using object mapping / entity frameworks (e.g. XPO, Entity
> Framework Core). These frameworks support regular queries out-of-the
> box; a CTEs require additional effort and are more difficult to maintain.
> >
> 
> Ah, another reason to avoid object mapping/entity frameworks! I guess
> really the same reason - loss of flexibility and expressive power.

While I agree that you loose control over certain details, we are overall quite happy using the frameworks. 

The frameworks nowadays provide the ability to call procedures if required - but using the objects directly is more convenient for the developers. SQL procedures add (just like a CTE) an additional layer to the application design which needs maintenance. That's fine if it really helps overall but we try to avoid it if it isn't needed. 

Regards
Klaus






^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2018-08-19 09:07 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-08-18 14:32 ` kpi6288@gmail.com
2018-08-19 09:07 ` kpi6288@gmail.com

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox