Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b7TRf-0003ug-7y for pgsql-performance@arkaria.postgresql.org; Mon, 30 May 2016 20:05:51 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1b7TRe-0008Qu-B3 for pgsql-performance@arkaria.postgresql.org; Mon, 30 May 2016 20:05:50 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1b7TRd-0008Qn-NX for pgsql-performance@postgresql.org; Mon, 30 May 2016 20:05:49 +0000 Received: from mail-vk0-x235.google.com ([2607:f8b0:400c:c05::235]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1b7TRW-0001Z6-T7 for pgsql-performance@postgresql.org; Mon, 30 May 2016 20:05:48 +0000 Received: by mail-vk0-x235.google.com with SMTP id c189so233302569vkb.1 for ; Mon, 30 May 2016 13:05:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=F1AxsCElbkZ4Qh3iyxSJiV7tadPAZwvd0KbvH/8q91M=; b=IOtf/n+tQIjgXH9xsVzmTtXqD86xPdDc0q9y2ONf7lPKgQnfPjdLtRIS9ScoIjteko iuJ6lp6EeGeO0FrHLMrFRkG84VHMR2p/KfG/gw/xgSa+p5nrVOj3SWE8DxuI9uFp8gKA YpLdYaWJ/uBuOIfEAxBTF1rtljugmock8S212tTyCrOpi5CWBzdPtFK9PtUaB906bY/w 7ynBYgCJSaZup1svsI4lVvhILrAI8LtrZF5iMmROjRZcyRuJ7wSRjNOL6XDDxt/fia8G RXTUsRYWF/T6Numj8PUs6BMstZv8rk7rsDHX0wyK2Abvj2nk9ExiBcAg1uXUlf4X4Yk5 t8pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=F1AxsCElbkZ4Qh3iyxSJiV7tadPAZwvd0KbvH/8q91M=; b=T5YJRmec3CrPPoW/lTljLGv15qQX+xfSTwcfuUSb/do4hoPRVMapNGJ0QaptFDApr0 c++tldWcBSBle/b7MjrX3NZIYheROOsEhsef1RJza0MblJkoyvgfT91InFKF7ZWfD9xu TG0ZQG0MXEEOx23fTXiwfQGNSnXFkvXdxMcmMZKfB97xypUZNk+EZA8JjqOvav8NI6QB ptP8yke92OMihuQBVcNjgVodaeGpP/6lYvLAO79stKoqKZzPODlO8+KyurWTzoNUgayC 9OEulvQScQLwRFB8myU92twxdDWcc0BqLmtxRq5moJhmcSsHxsw5rt0Um148zivRTQCh 7LFA== X-Gm-Message-State: ALyK8tJ8dAfOJ1f4amUi2DsgD4l1G+OPnEsVyU8UWg3KMff74npmj8KpU5VN6e2fZDATICOzK1rsLQ+qqQ4GFQ== MIME-Version: 1.0 X-Received: by 10.176.0.163 with SMTP id 32mr15054702uaj.103.1464638741695; Mon, 30 May 2016 13:05:41 -0700 (PDT) Received: by 10.103.71.203 with HTTP; Mon, 30 May 2016 13:05:41 -0700 (PDT) In-Reply-To: <574C7E37.7080102@vboehm.de> References: <574C7E37.7080102@vboehm.de> Date: Mon, 30 May 2016 13:05:41 -0700 Message-ID: Subject: Re: similarity and operator '%' From: Jeff Janes To: Volker Boehm Cc: "pgsql-performance@postgresql.org" Content-Type: text/plain; charset=UTF-8 X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org On Mon, May 30, 2016 at 10:53 AM, Volker Boehm wrote: > The reason for using the similarity function in place of the '%'-operator is > that I want to use different similarity values in one query: > > select name, street, zip, city > from addresses > where name % $1 > and street % $2 > and (zip % $3 or city % $4) > or similarity(name, $1) > 0.8 I think the best you can do through query writing is to use the most-lenient setting in all places, and then refilter to get the less lenient cutoff: select name, street, zip, city from addresses where name % $1 and street % $2 and (zip % $3 or city % $4) or (name % $1 and similarity(name, $1) > 0.8) If it were really important to me to get maximum performance, what I would do is alter/fork the pg_trgm extension so that it had another operator, say %%%, with a hard-coded cutoff which paid no attention to the set_limit(). I'm not really sure how the planner would deal with that, though. Cheers, Jeff -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance