Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 4B14B64FCE0 for ; Thu, 4 Sep 2008 23:05:40 -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 60144-04 for ; Thu, 4 Sep 2008 23:05:35 -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 8C95764FCF7 for ; Thu, 4 Sep 2008 23:05:35 -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 m8524vJF011788; Thu, 4 Sep 2008 22:04:57 -0400 (EDT) To: Heikki Linnakangas cc: David Rowley , "'Peter Eisentraut'" , pgsql-patches@postgresql.org Subject: Re: [HACKERS] TODO item: Implement Boyer-Moore searching (First time hacker) In-reply-to: <48C061B3.1090709@enterprisedb.com> References: <48C061B3.1090709@enterprisedb.com> Comments: In-reply-to Heikki Linnakangas message dated "Fri, 05 Sep 2008 01:31:15 +0300" Date: Thu, 04 Sep 2008 22:04:57 -0400 Message-ID: <11787.1220580297@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/48 X-Sequence-Number: 7063 Heikki Linnakangas writes: > After reading the wikipedia article on Boyer-Moore search algorithm, it > looks to me like this patch actually implements the simpler > Boyer-Moore-Horspool algorithm that only uses one lookup table. That's > probably fine, as it ought to be faster on small needles and haystacks > because it requires less effort to build the lookup tables, even though > the worst-case performance is worse. It should still be faster than what > we have now. Hmm. B-M-H has worst case search speed O(M*N) (where M = length of pattern, N = length of search string); whereas full B-M is O(N). Maybe we should build the second table when M is large? Although realistically that is probably gilding the lily, since frankly there haven't been many real-world complaints about the speed of these functions anyway ... > The skip table really should be constructed only once in > text_position_start and stored in TextPositionState. That would make a > big difference to the performance of those functions that call > text_position_next repeatedly: replace_text, split_text and text_to_array. +1. The heuristic about big a skip table to make may need some adjustment as well, since it seems to be considering only a single search. regards, tom lane