Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 72B13200CE0 for ; Fri, 11 Aug 2017 00:03:06 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 70D2D16C461; Thu, 10 Aug 2017 22:03:06 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 8CE1A16C465 for ; Fri, 11 Aug 2017 00:03:05 +0200 (CEST) Received: (qmail 82767 invoked by uid 500); 10 Aug 2017 22:03:04 -0000 Mailing-List: contact issues-help@drill.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@drill.apache.org Delivered-To: mailing list issues@drill.apache.org Received: (qmail 82681 invoked by uid 99); 10 Aug 2017 22:03:04 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Aug 2017 22:03:04 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 951BB180F95 for ; Thu, 10 Aug 2017 22:03:03 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -99.202 X-Spam-Level: X-Spam-Status: No, score=-99.202 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id GB4Sd-Z6i6fP for ; Thu, 10 Aug 2017 22:03:02 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id 1AD695F3D1 for ; Thu, 10 Aug 2017 22:03:02 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 5E9A0E0E6A for ; Thu, 10 Aug 2017 22:03:01 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id A2A3424181 for ; Thu, 10 Aug 2017 22:03:00 +0000 (UTC) Date: Thu, 10 Aug 2017 22:03:00 +0000 (UTC) From: "Padma Penumarthy (JIRA)" To: issues@drill.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Comment Edited] (DRILL-5697) Improve performance of filter operator for pattern matching MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Thu, 10 Aug 2017 22:03:06 -0000 [ https://issues.apache.org/jira/browse/DRILL-5697?page=3Dcom.atlassian= .jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D1612= 2402#comment-16122402 ]=20 Padma Penumarthy edited comment on DRILL-5697 at 8/10/17 10:02 PM: ------------------------------------------------------------------- I did bunch of experiments to figure out what should be the best approach. Basically, here is what we do for "like" operation : 1. Build a charSequence wrapper for varChar UTF8 input. If input is all AS= CII, we directly read the byte as character from PlatformDependent. Else, w= e decode UTF-8 bytes, copy them to charBuffer and read characters from that= .=20 2. regex matching is done on this charSequenceWrapper, which provides charA= t functionality as explained above. All the numbers below are processing time of filter operation. Baseline: select count(\*) from `/Users/ppenumarthy/MAPRTECH/padma/testdata` where l_= comment like '%a'=20 1m 10 sec select count(\*) from `/Users/ppenumarthy/MAPRTECH/padma/testdata` where l_= comment like 'a%' 9.7 sec select count(\*) from `/Users/ppenumarthy/MAPRTECH/padma/testdata` where l_= comment like '%a%' 1m 6 sec For all ASCII, since getByte is doing a bounds check every time we call it,= I want to see if getting the bytes in one shot is better. That did not he= lp much with performance. In fact, it made it worse for 'a%' type of match= . select count(\*) from `/Users/ppenumarthy/MAPRTECH/padma/testdata` where l_= comment like '%a' 1m 2s (vs 1m 10 sec baseline) select count(\*) from `/Users/ppenumarthy/MAPRTECH/padma/testdata` where l_= comment like 'a%' 16.688s (vs 9.7 sec baseline) select count(\*) from `/Users/ppenumarthy/MAPRTECH/padma/testdata` where l_= comment like '%a%' 55 sec (vs 1min 6 sec baseline) Use find instead of matcher.matches(). The numbers are better, but not by m= uch. select count(\*) from `/Users/ppenumarthy/MAPRTECH/padma/testdata` where l_= comment like '%a'; 30 sec (vs 1min 10 sec baseline) select count(\*) from `/Users/ppenumarthy/MAPRTECH/padma/testdata` where l_= comment like 'a%'; 14 sec (vs 9.794s baseline) select count(\*) from `/Users/ppenumarthy/MAPRTECH/padma/testdata` where l_= comment like =E2=80=98%a%=E2=80=99; 32 sec (vs 1min 6s baseline) Next, I tried building charBuffer always (even if it is all ASCII) and use = String functions startsWith, endsWith and contains. Numbers are better. But, not by much. select count(\*) from `/Users/ppenumarthy/MAPRTECH/padma/testdata` where l_= comment like '%a' 45 sec (vs 1min 10 sec baseline) select count(\*) from `/Users/ppenumarthy/MAPRTECH/padma/testdata` where l_= comment like =E2=80=98%a%=E2=80=99 34 sec (vs 1min 6s baseline) select count(\*) from `/Users/ppenumarthy/MAPRTECH/padma/testdata` where l_= comment like =E2=80=98a%=E2=80=99 46 (vs 9.794s baseline) I tried Google RE2 library. Got much worse numbers than what we are getting= with Java Regex Library. Finally, I implemented simple character by character comparison functions f= or each of the special cases=20 and got pretty good numbers. select count(\*) from `/Users/ppenumarthy/MAPRTECH/padma/testdata` where l_= comment like '%a' 6.576 sec (vs. 1m 10s baseline) select count(\*) from `/Users/ppenumarthy/MAPRTECH/padma/testdata` where l_= comment like 'a%' 6.190s (vs 9.794s baseline) select count(\*) from `/Users/ppenumarthy/MAPRTECH/padma/testdata` where l_= comment like '%a%' 11.34s (vs. 1m 6s baseline) was (Author: ppenumarthy): I did bunch of experiments to figure out what should be the best approach. Basically, here is what we do for "like" operation : 1. Build a charSequence wrapper for varChar UTF8 input. If input is all AS= CII, we directly read the byte as character from PlatformDependent. Else, w= e decode UTF-8 bytes, copy them to charBuffer and read characters from that= .=20 2. regex matching is done on this charSequenceWrapper, which provides charA= t functionality as explained above. All the numbers below are processing time of filter operation. Baseline: select count(\*) from `/Users/ppenumarthy/MAPRTECH/padma/testdata` where l_= comment like '%a'=20 1m 10 sec select count(\*) from `/Users/ppenumarthy/MAPRTECH/padma/testdata` where l_= comment like 'a%' 9.7 sec select count(\*) from `/Users/ppenumarthy/MAPRTECH/padma/testdata` where l_= comment like '%a%' 1m 6 sec For all ASCII, since getByte is doing a bounds check every time we call it,= I want to see if getting the bytes in one shot is better. That did not he= lp much with performance. In fact, it made it worse for 'a%' type of match= . select count(\*) from `/Users/ppenumarthy/MAPRTECH/padma/testdata` where l_= comment like '%a' 1m 2s (vs 1m 10 sec baseline) select count(\*) from `/Users/ppenumarthy/MAPRTECH/padma/testdata` where l_= comment like 'a%' 16.688s (vs 9.7 sec baseline) select count(\*) from `/Users/ppenumarthy/MAPRTECH/padma/testdata` where l_= comment like '%a%' 55 sec (vs 1min 6 sec baseline) Use find instead of matcher.matches(). The numbers are better, but not by m= uch. select count(\*) from `/Users/ppenumarthy/MAPRTECH/padma/testdata` where l_= comment like '%a'; 30 sec (vs 1min 10 sec baseline) select count(\*) from `/Users/ppenumarthy/MAPRTECH/padma/testdata` where l_= comment like 'a%'; 14 sec (vs 9.794s baseline) select count(\*) from `/Users/ppenumarthy/MAPRTECH/padma/testdata` where l_= comment like =E2=80=98%a%=E2=80=99; 32 sec (vs 1min 6s baseline) Next, I tried building charBuffer always (even if it is all ASCII) and use = String functions startsWith, endsWith and contains. Numbers are better. But, not by much. select count(\*) from `/Users/ppenumarthy/MAPRTECH/padma/testdata` where l_= comment like '%a' 45 sec (vs 1min 10 sec baseline) select count(\*) from `/Users/ppenumarthy/MAPRTECH/padma/testdata` where l_= comment like =E2=80=98%a%=E2=80=99 34 sec (vs 1min 6s baseline) select count(\*) from `/Users/ppenumarthy/MAPRTECH/padma/testdata` where l_= comment like =E2=80=98a%=E2=80=99 46 (vs 9.794s baseline) I tried Google RE2 library. Got much worse numbers than what we are getting= with Java Regex Library. Finally, I implemented simple character by character comparison functions f= or each of the special cases=20 and got pretty good numbers. select count(\*) from `/Users/ppenumarthy/MAPRTECH/padma/testdata` where l_= comment like '%a' 6.576 sec (vs. 1m 10s baseline) select count(\*) from `/Users/ppenumarthy/MAPRTECH/padma/testdata` where l_= comment like 'a%' 6.190s (vs 9.794s baseline) select count(\*) from `/Users/ppenumarthy/MAPRTECH/padma/testdata` where l_= comment like '%a%' 11.34s (vs. 1m 6s baseline) > Improve performance of filter operator for pattern matching > ----------------------------------------------------------- > > Key: DRILL-5697 > URL: https://issues.apache.org/jira/browse/DRILL-5697 > Project: Apache Drill > Issue Type: Improvement > Components: Execution - Flow > Affects Versions: 1.11.0 > Reporter: Padma Penumarthy > Assignee: Padma Penumarthy > > Queries using filter with sql like operator use Java regex library for pa= ttern matching. However, for cases like %abc (ends with abc), abc% (starts = with abc), %abc% (contains abc), it is observed that implementing these cas= es with simple code instead of using regex library provides good performanc= e boost (4-6x). Idea is to use special case code for simple, common cases a= nd fall back to Java regex library for complicated ones. That will provide = good performance benefit for most common cases. -- This message was sent by Atlassian JIRA (v6.4.14#64029)