Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 583BE9FA1DA for ; Tue, 26 Dec 2006 15:56:39 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-new, port 10024) with ESMTP id 76723-08 for ; Tue, 26 Dec 2006 15:56:26 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 784279FA06E for ; Tue, 26 Dec 2006 15:56:26 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id kBQJtcnH028035; Tue, 26 Dec 2006 14:55:38 -0500 (EST) To: Kevin Hunter cc: PostrgreSQL Novice List Subject: Re: Partitioning In-reply-to: <45916BBB.5070602@earlham.edu> References: <45916BBB.5070602@earlham.edu> Comments: In-reply-to Kevin Hunter message dated "Tue, 26 Dec 2006 13:36:43 -0500" Date: Tue, 26 Dec 2006 14:55:37 -0500 Message-ID: <28034.1167162937@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200612/99 X-Sequence-Number: 18193 Kevin Hunter writes: > A friend has asked me about creating a unique table for individual users > that sign up for his site. (In essence, each user who signs up would > essentially get a set of CREATE TABLE {users,friends,movies,eats}_ ( > ... ); statements executed, the idea being to reduce the number of rows > that the DB needs to search or index/update in regards to a particular > user id.) The just seems ludicrous to me, because the database still > needs to find those tables from its internal structure, not to mention > that it just seems silly to me from a design perspective. Something > about unable to optimize any queries because not only is the WHERE > clause in flux, but so is the FROM clause. > Question: Could someone explain to me why this would be bad idea, > because I can't put into words why it is. I thought you did a fine job right there ;-). In essence this would be replacing one level of indexing with two, which is unlikely to be a win. If you have exactly M rows in each of N tables then theoretically your lookup costs would be about O(log(N) + log(M)), which is nominally the same as O(log(M*N)) which is the cost to index into one big table --- so at best you break even, and that's ignoring the fact that index search has a nonzero startup cost that'll be paid twice in the first case. But the real problem is that if the N tables contain different numbers of rows then you have an unevenly filled search tree, which is a net loss. Most DBMSes aren't really designed to scale to many thousands of tables anyway. In Postgres this would result in many thousands of files in the same database directory, which probably creates some filesystem lookup inefficiencies in addition to whatever might be inherent to Postgres. Partitioning is indeed something that is commonly done, but on a very coarse grain --- you might have a dozen or two active partitions, not thousands. The point of partitioning is either to spread a huge table across multiple filesystems (and how many filesystems have you got?) or else to make predictable removals of segments of the data cheap (for instance, dropping the oldest month's worth of data once a month, in a table where you only keep the last year or so's worth of data on-line). I can't see doing it on a per-user basis. regards, tom lane