X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.192]) by svr1.postgresql.org (Postfix) with ESMTP id 0B2BED1C50D; Tue, 22 Jul 2003 17:10:21 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr4.postgresql.org [64.117.224.192]) (amavisd-new, port 10024) with ESMTP id 69979-09; Tue, 22 Jul 2003 17:10:15 +0000 (GMT) Received: from pns.mm.eutelsat.org (pns.mm.eutelsat.org [194.214.173.227]) by svr1.postgresql.org (Postfix) with ESMTP id 5295CD1C954; Tue, 22 Jul 2003 14:10:12 -0300 (ADT) Received: from nts-03.mm.eutelsat.org (localhost [127.0.0.1]) by pns.mm.eutelsat.org (8.11.6/linuxconf) with ESMTP id h6MHDtq24674; Tue, 22 Jul 2003 19:13:58 +0200 Received: from GMENDOLA2 (gmendola2.mm.eutelsat.org [194.214.173.26]) by nts-03.mm.eutelsat.org (8.11.6/linuxconf) with SMTP id h6MH7LR15207; Tue, 22 Jul 2003 19:07:21 +0200 Message-ID: <00c101c35074$1e5f5b20$152aa8c0@GMENDOLA2> From: "Mendola Gaetano" To: , Subject: Wrong plan or what ? Date: Tue, 22 Jul 2003 19:10:14 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/212 X-Sequence-Number: 9552 Hi all, I'm running Postgres7.3.3 and I'm performing this simple select: select * from user_logs ul, user_data ud, class_default cd where ul.id_user = ud.id_user and ud.id_class = cd.id_class and cd.id_provider = 39; these are the number of rows for each table: user_logs: 1258955 class_default: 31 ( only one with id_provider = 39 ) user_data: 10274; this is the explain analyze for that query: QUERY PLAN Hash Join (cost=265.64..32000.76 rows=40612 width=263) (actual time=11074.21..11134.28 rows=10 loops=1) Hash Cond: ("outer".id_user = "inner".id_user) -> Seq Scan on user_logs ul (cost=0.00..24932.65 rows=1258965 width=48) (actual time=0.02..8530.21 rows=1258966 loops=1) -> Hash (cost=264.81..264.81 rows=331 width=215) (actual time=30.22..30.22 rows=0 loops=1) -> Nested Loop (cost=0.00..264.81 rows=331 width=215) (actual time=29.95..30.20 rows=6 loops=1) -> Seq Scan on class_default cd (cost=0.00..1.39 rows=1 width=55) (actual time=0.08..0.10 rows=1 loops=1) Filter: (id_provider = 39) -> Index Scan using idx_user_data_class on user_data ud (cost=0.00..258.49 rows=395 width=160) (actual time=29.82..29.96 rows=6 loops=1) Index Cond: (ud.id_class = "outer".id_class) Total runtime: 11135.65 msec (10 rows) I'm able to performe that select with these 3 steps: SELECT id_class from class_default where id_provider = 39; id_class ---------- 48 (1 row) SELECT id_user from user_data where id_class in ( 48 ); id_user --------- 10943 10942 10934 10927 10910 10909 (6 rows) SELECT * from user_logs where id_user in ( 10943, 10942, 10934, 10927, 10910, 10909 ); [SNIPPED] and the time ammount is a couple of milliseconds. Why the planner or the executor ( I don't know ) do not follow the same strategy ? Thank you Gaetano Mendola