Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id E01324758DC for ; Thu, 21 Nov 2002 10:46:53 -0500 (EST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id CC1304758FE for ; Thu, 21 Nov 2002 10:46:51 -0500 (EST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.6/8.12.6) with ESMTP id gALFkqsX012121; Thu, 21 Nov 2002 10:46:52 -0500 (EST) To: "Peter Galbavy" Cc: pgsql-sql@postgresql.org Subject: Re: help optimise this ? In-reply-to: <001d01c29169$79fd1d20$4528a8c0@cblan.mblox.com> References: <001d01c29169$79fd1d20$4528a8c0@cblan.mblox.com> Comments: In-reply-to "Peter Galbavy" message dated "Thu, 21 Nov 2002 14:22:51 +0000" Date: Thu, 21 Nov 2002 10:46:51 -0500 Message-ID: <12120.1037893611@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/332 X-Sequence-Number: 10474 "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