Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id BAF1664FD10 for ; Sat, 6 Sep 2008 19:51:24 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 50710-05 for ; Sat, 6 Sep 2008 19:51:22 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 3E45A64FCBA for ; Sat, 6 Sep 2008 19:51:22 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id m86MoloO026523; Sat, 6 Sep 2008 18:50:47 -0400 (EDT) To: "David Rowley" , "'Heikki Linnakangas'" , "'Peter Eisentraut'" , pgsql-patches@postgresql.org Subject: Re: [HACKERS] TODO item: Implement Boyer-Moore searching (First time hacker) In-reply-to: <26072.1220739661@sss.pgh.pa.us> References: <26072.1220739661@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Sat, 06 Sep 2008 18:21:01 -0400" Date: Sat, 06 Sep 2008 18:50:47 -0400 Message-ID: <26522.1220741447@sss.pgh.pa.us> From: Tom Lane 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: 200809/74 X-Sequence-Number: 7089 I wrote: > I looked this over a bit and was immediately confused by one thing: > the introductory comment says that the skip table size ought to be based > on the length of the haystack, which makes sense to me, but the code is > actually initializing it on the basis of len2, ie, the length of the > needle. Isn't that a bug? Was the same bug present in the tests you > made to determine the best table sizes? BTW, to the extent that you feel like testing a different idea, I would suggest: * don't bother initializing the skiptable when len1 < len2 * otherwise, choose its size based on len1 - len2, not just len1 or len2. This is (one less than) the maximum number of search loop consultations of the skip table that can happen, so it seems like a plausible number, and better than either length alone. regards, tom lane