Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id E4594475F1B for ; Thu, 21 Nov 2002 10:50:02 -0500 (EST) Received: from mailstore-1.mail.knowledge.com (frida.london.knowtion.net [213.170.2.69]) by postgresql.org (Postfix) with ESMTP id C6657476536 for ; Thu, 21 Nov 2002 10:49:49 -0500 (EST) Received: from [213.155.153.61] (helo=petergalbavydes) by mailstore-1.mail.knowledge.com with asmtp (Exim 3.33 #1) id 18EtaT-0005u5-00; Thu, 21 Nov 2002 15:49:53 +0000 Message-ID: <006601c29175$a21ce900$4528a8c0@cblan.mblox.com> From: "Peter Galbavy" To: "Tom Lane" Cc: References: <001d01c29169$79fd1d20$4528a8c0@cblan.mblox.com> <12120.1037893611@sss.pgh.pa.us> Subject: Re: help optimise this ? Date: Thu, 21 Nov 2002 15:49:53 -0000 Organization: Knowtion Ltd. MIME-Version: 1.0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/333 X-Sequence-Number: 10475 Wow. Three people have replied with an effectively identical solution. Why didn't I think of this ? Answers on a postcard to... Thanks to all that have replied. Peter ----- Original Message ----- From: "Tom Lane" To: "Peter Galbavy" Cc: Sent: Thursday, November 21, 2002 3:46 PM Subject: Re: [SQL] help optimise this ? > "Peter Galbavy" writes: > > I want to then find either the largest (max) or smallest (min) version of an > > image that falls within some range of sizes: > > Depends on how you want to define "largest" and "smallest", but if > "area" is a good enough definition, seems like this would work: > > select file_md5 from image_instance > where md5 = '546b94e94851a56ee721f3b755f58462' > and image_width between 0 and 160 > and image_length between 0 and 160 > order by image_width * image_length > limit 1; > > Probably an index on md5 would be sufficient to make this go fast --- > I assume you're not going to be storing a vast number of sizes of > the same image. > > regards, tom lane >