Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id C55E39F988B for ; Mon, 5 Nov 2007 16:13:25 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 37231-01-2 for ; Mon, 5 Nov 2007 16:13:15 -0400 (AST) Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.171]) by postgresql.org (Postfix) with ESMTP id 0335A9F995D for ; Mon, 5 Nov 2007 16:08:05 -0400 (AST) Received: by ug-out-1314.google.com with SMTP id j3so993329ugf for ; Mon, 05 Nov 2007 12:08:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; bh=aonoA+Majbub9GxMXsAesKOxATYd9IRE/p8vk9+hCvY=; b=gxVOzP578SAyihbNXNWI5jejjoYvrjrHVsrFVpAjj1EfiCed0lgtUoaO05MSXDk2d1JB8ElFGCqW52Q67J4q1gQVhSA9MEODf2B7IVwWPqVmFs+d7TwaC1M3LK0AUmp53Kx+l6RpWB7CSkc1OJdzx8i9jEmuD02YyFwOuEhVfj4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; b=J/wsZnt5Gt03nw/t1gsuNuVb7QxsbbyLvh0LOXjoOImv7oAOLyYWZg20MnJGsAtsyz0WVp0gFDjBfzEBerQMTAMHWoDt1ypMIsLnVjH2GhUQS7jWOvvQTeipAdhUQ7UQZUbLLgv1xbqc0XSrPZM98Lm4lTWis6mGpqLl895PcwA= Received: by 10.67.27.3 with SMTP id e3mr1419645ugj.1194293284534; Mon, 05 Nov 2007 12:08:04 -0800 (PST) Received: from ?172.24.32.184? ( [62.232.55.118]) by mx.google.com with ESMTPS id e34sm14998819ugd.2007.11.05.12.08.02 (version=SSLv3 cipher=RC4-MD5); Mon, 05 Nov 2007 12:08:02 -0800 (PST) Message-ID: <472F781F.6080200@enterprisedb.com> Date: Mon, 05 Nov 2007 20:07:59 +0000 From: Heikki Linnakangas User-Agent: Icedove 1.5.0.12 (X11/20070730) MIME-Version: 1.0 To: Chris Hoover CC: PGSQL Performance Subject: Re: Which index methodology is better?- References: <1d219a6f0711051043x569b7f51r4cee3353e6ea9f10@mail.gmail.com> In-Reply-To: <1d219a6f0711051043x569b7f51r4cee3353e6ea9f10@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200711/65 X-Sequence-Number: 27480 Chris Hoover wrote: > On this table, a customer can search by customer_id, customer_l_name, > and customer_f_name. > > Is it better to create 3 indexes, or one index on the three columns? > > I did some initial testing with index customer_test_idx(customer_id, > customer_l_name, customer_f_name) and postgres would use the index for > select * from customer where customer_f_name = 'zxy' - so the single > index will cover the three. Postgres can use the index in that case, but it's going to have to scan the whole index, which is a lot slower than looking up just the needed rows. If you do an EXPLAIN ANALYZE on that query, and compare it against "select * from customer where customer_id = 123", you'll see that it's a lot more expensive. I'd recommend having separate indexes. Having just one index probably does take less space, but the fact that you don't have to always scan all of it probably outweighs that. -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com