Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gEUYz-00015T-1I for pgadmin-hackers@arkaria.postgresql.org; Mon, 22 Oct 2018 07:23:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gEUYx-00058j-FV for pgadmin-hackers@arkaria.postgresql.org; Mon, 22 Oct 2018 07:23:43 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gEUYx-00058Z-4M; Mon, 22 Oct 2018 07:23:43 +0000 Received: from mail-ed1-x542.google.com ([2a00:1450:4864:20::542]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gEUYu-0001Pe-Fw; Mon, 22 Oct 2018 07:23:41 +0000 Received: by mail-ed1-x542.google.com with SMTP id x31-v6so36877683edd.8; Mon, 22 Oct 2018 00:23:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=BIOUR64ADUHauQLEjIpYjRJ/UMI9VrxodLRL7tJ/1UU=; b=SgjysP2NVqZG9MdBdm6yS9kHR9YXQ30hve5lPzQx1zfdFHBnboL7T0QxrUNfyxgJa+ iCJaonrHLzXESw2X0ci6/WgQXGViHhsPFiy95JHQ9VDI0hdNOXDXKcMt42rh1TDbLGrG j72y+n4lWKnAS4Ics3Pl58nwiuah1bhVDfqg1nS1uC1Fu+IxW6i+q+vQbaIE/Gh+j3oO /WiHp4USYLalCRLT8G3zhFMxkodQtBNbUlm6yZLxqpa4RF5TcXlhMVIuu7ZEyB+3aVy4 JOEFlMGpjA26CDU8O4EV70C+V2g7YMHdrpaWo2CvBLsklilv63j0a3mvxg9i3VRw+4FI vKYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=BIOUR64ADUHauQLEjIpYjRJ/UMI9VrxodLRL7tJ/1UU=; b=AYwh7Z8NSW7jPgZzoBE5x6kq3LggoccLW78U3vPlUqjS0mDGBs9H4sq4vuvunkIKL3 RFeNIhW3wdlxeYjvBlRCzvoEwdLwjDTNpXIolzUNF+pICgsI0XKipLJ9cFJhsB8xqZ8m Q0G7wvFjeKTw5vFLw3WVvz95q1OTECER7EAISQynvVwKZUjLDZG95Xvb5Qg7UBJrolPM wZmERjR3Hc6p3TePOzkQ16GwXczDnx5M7BcNjNBDZm3dlq9cysP7X/kNup6305OY9I98 qtoAhfRDNK52CE1SPghufuNAcPxdSko//UihsPgsB396L72HhvvL06qTwogXd01UJCJf ZuAw== X-Gm-Message-State: ABuFfohm0JzoHDFCwps94wBi88ou8Lxccpg+ynD/LdQUEqq2XEIlFa/M G+EW5h5bXe7tAkDKYobAI2E= X-Google-Smtp-Source: ACcGV62BXASeZgOpKswl04V5cEmDzvpsbdsGWP1IeiPlvIiXwDYHJaV7PUX3jWjdZYykR54lZ5UPFA== X-Received: by 2002:a50:8ea1:: with SMTP id w30-v6mr12942770edw.280.1540193017662; Mon, 22 Oct 2018 00:23:37 -0700 (PDT) Received: from hollewijn.internal (217-19-30-105.dsl.cambrium.nl. [217.19.30.105]) by smtp.gmail.com with ESMTPSA id d12-v6sm13532937ede.32.2018.10.22.00.23.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Oct 2018 00:23:36 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.1\)) Subject: Re: Optimizing Postgresql ILIKE while query From: Alban Hertroys In-Reply-To: Date: Mon, 22 Oct 2018 09:23:35 +0200 Cc: pgadmin-hackers@lists.postgresql.org, pgsql-general@lists.postgresql.org, manoj.t.kumar@ericsson.com, rajesh.tiwari@ericsson.com Content-Transfer-Encoding: quoted-printable Message-Id: <89E1AC86-A512-4396-A227-3E951477876D@gmail.com> References: To: aman gupta X-Mailer: Apple Mail (2.3445.9.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On 22 Oct 2018, at 7:56, aman gupta wrote: >=20 > Issue: >=20 > We have the base table which contains 22M records and we created a = view on top of it while querying the view with ILIKE clause it took 44 = seconds and with LIKE Clause 20 Seconds >=20 > Query: >=20 > fm_db_custom_db=3D# EXPLAIN (ANALYZE, TIMING OFF) > select = destination,hostname,inputfilename,inputtime,logicalservername,outputfilen= ame,outputtime,processinglink,source,totalinputbytes,totalinputcdrs,totalo= utputbytes,totaloutputcdrs from mmsuper.test_20m_view where = inputfilename ilike = '%SDPOUTPUTCDR_4001_BLSDP09_ADM_4997_18-10-15-02549.ASN%'; Perhaps, when you have a question about timing, you shouldn't turn off = the timing in the query plan? Now we can't see where the time is spent. > That's all sequential scans that each remove a significant amount of = rows. That probably costs a significant amount of time to do. It looks like you don't have any indices on the underlying table(s) at = all. I'd start there and then look at the ILIKE problem again. By that = time, Pavel's suggestion for a trigram index on that text field is = probably spot-on. Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.