Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 23DE364FC39 for ; Wed, 10 Dec 2008 00:25:07 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 42159-08 for ; Wed, 10 Dec 2008 00:25:04 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail-bw0-f14.google.com (mail-bw0-f14.google.com [209.85.218.14]) by mail.postgresql.org (Postfix) with ESMTP id 98F8E64FC37 for ; Wed, 10 Dec 2008 00:25:03 -0400 (AST) Received: by bwz7 with SMTP id 7so236334bwz.19 for ; Tue, 09 Dec 2008 20:25:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=vGXVjdDzjfaDZCHWei0BLKl8nyv1/aLxLA06RjsDxnA=; b=PoQUAPfZ2X69zJKytsgpKMePnit/EWzA89IHu+GWQHQvyUSITd7AszRniLPKIKVNHF oVOiCtkJQhfRv6gLrDHxmIFb+7nfJdFILVeWVZtEDoogXjY6v6vnIPuc3TuAFXd83u+0 zzGxeN+CRJzRhMSNRRyAzMkYqqAH0g+pDRCcY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=mS4Gbzuyo0XCIctNOJItA44FxCFrwdgTNK5BWT6d3iWkq0t7AF3fuxa3XSL6BlyH7o gvR+NHgOXsTv+Dg1DDDOdKHHiq8VlEfYrnObLjbOF+k4YpsTlrTVnJBpuxpVQEG0KA6A bcnaAWeBYqADsf0gX0C6aVhqMDzTMTk57e3AI= Received: by 10.223.112.204 with SMTP id x12mr906198fap.70.1228883101945; Tue, 09 Dec 2008 20:25:01 -0800 (PST) Received: by 10.223.106.209 with HTTP; Tue, 9 Dec 2008 20:25:01 -0800 (PST) Message-ID: <603c8f070812092025k6325e0fcud001b205a507a634@mail.gmail.com> Date: Tue, 9 Dec 2008 23:25:01 -0500 From: "Robert Haas" To: "Gregory Stark" Subject: Re: benchmarking the query planner Cc: "Greg Stark" , "Kevin Grittner" , "jd@commandprompt.com" , "Josh Berkus" , "Greg Smith" , pgsql-hackers@postgresql.org In-Reply-To: <87ljuq4rmk.fsf@oxford.xeocode.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <603c8f070812061019r5aca3aajeaa5493b11c5feff@mail.gmail.com> <9897C4AF-6D47-4F44-AD3D-F5A82AC392DB@enterprisedb.com> <87ljuq4rmk.fsf@oxford.xeocode.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200812/602 X-Sequence-Number: 129231 On Mon, Dec 8, 2008 at 10:24 AM, Gregory Stark wrote: > I tried a different query, trying to get quadratic growth and again failed. It The profiling results I sent the other day show an exactly-linear increase in the number of times eqjoinsel invokes FunctionCall2. Reading through the the eqjoinsel_inner loop in selfuncs.c beginning around line 2042, I think what is happening is this: since the two tables are really the same table, nvalues1 and nvalues2 are the same array, and therefore contain the same elements in the same order. As a result, for each i, we skip over the first i - 1 entries in nvalues2, which have already been matched, and then compare element i of nvalues1 to element i of nvalues2 and mark them both as matched. Although this is technically an O(n^2) algorithm, the constant is very low, because this code is Really Fast: if (hasmatch[j]) continue; To get observable quadratic behavior, I think you might need to construct two MCV arrays where all the values are the same, but the arrays are not in the same order. I believe they are sorted by frequency, so it might be sufficient to arrange things so that the N'th most common value in one table is the (statistics_target + 1 - N)'th most common value in the other. It might also help to use a function with a real slow comparison function (perhaps one intentionally constructed to be slow). ...Robert