Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hnjN2-0005sd-Ao for pgsql-performance@arkaria.postgresql.org; Wed, 17 Jul 2019 12:49:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hnjN0-0008TF-Tl for pgsql-performance@arkaria.postgresql.org; Wed, 17 Jul 2019 12:49:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hnjN0-0008T8-G6 for pgsql-performance@lists.postgresql.org; Wed, 17 Jul 2019 12:49:18 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hnjMw-00011k-VS for pgsql-performance@lists.postgresql.org; Wed, 17 Jul 2019 12:49:17 +0000 Received: by mail-wr1-x444.google.com with SMTP id n9so24750882wru.0 for ; Wed, 17 Jul 2019 05:49:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=HVBztTAPGnLfHa7WqnFH0pt0AzerwwTC45behfeY9Fc=; b=l70Wd4lIGyFLjDaYys9BJyG6U1n5capNniVx0B7/n4zepzuPkRnJPrTGQnEm0ya3le 6E4JNh59tvE1Noofkanc0evlb6kWHPj1evqjtYaOijXA6yPjql0v0lFKGLxfmwpyXCEw gHDCHE9irmO4jsX3eO8hhpsjzVPFDPdEtTZh4VvDzY3ggSXNpFAdcAf81sH3SCuxnomp +mwizyWSET0bcd0T3ULsDG6bNYDGj19rJFHhuYsGbDP08UPMD6114XPKksSqmyynhXG9 FmshS1A1jFpr+wXwhp8eEM7DX89O8LfdFXAFUP0cjdo8ZNqY5VGtKMArRIuZA3CdYVK7 q+3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=HVBztTAPGnLfHa7WqnFH0pt0AzerwwTC45behfeY9Fc=; b=IDlqu480awKZ+Z+GHGbRFjeCy3P3IKH0SVPM8BMtUilDKcsb818D3d6oBUjLJNL8jg HBICFxLWszIiC0ZHIR4BhB7zWPGSjeYAEP2SbI6GnNFGKPIF+1UM7J5VnjeqesKlc5PD T+CWXLDLZLK5QeU0hl05Y1hK3bUZsPNRXAR57YZvMVqF8PrynyVVYy8gFsmaeTn9bO6q kdv0aMd7UmxMJhSF0YHtBvXYFq/qV5GnKuKArryt8S3ReGRY2tzo3vuZhnnaATWIyAiY MkjKsjdTnQkEHbVBFRMIaY+DEZDI3rxQaHmgbLsrT+WfOZ2TnylyOlDJNYcnfS/CGnZF DcVQ== X-Gm-Message-State: APjAAAWZ65vfifq6oD8pGqGWp3cZ5hPPeU+bMW6E3C364qjB/e8inKjl Ya5MfDWM61iEi/1YQWmx2TM9HA== X-Google-Smtp-Source: APXvYqwUSRBQBurma1RF4l3w75ew2jOUT5Fv9rUrXwgvMZk8nELxYlzr8sm0V8Gj4U1olpYtlxWFGw== X-Received: by 2002:adf:8bd1:: with SMTP id w17mr45532834wra.50.1563367753969; Wed, 17 Jul 2019 05:49:13 -0700 (PDT) Received: from localhost (static-84-42-175-93.net.upcbroadband.cz. [84.42.175.93]) by smtp.gmail.com with ESMTPSA id z7sm20851522wrh.67.2019.07.17.05.49.13 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 17 Jul 2019 05:49:13 -0700 (PDT) Date: Wed, 17 Jul 2019 14:48:46 +0200 From: Tomas Vondra To: Sergei Kornilov Cc: mayank rupareliya , "pgsql-performance@lists.postgresql.org" Subject: Re: Searching in varchar column having 100M records Message-ID: <20190717124846.xbvcvfjg5hdcnaed@development> References: <27574631563364400@iva5-fb4da115b4b5.qloud-c.yandex.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <27574631563364400@iva5-fb4da115b4b5.qloud-c.yandex.net> User-Agent: NeoMutt/20180716-1444-295967-dirty List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, Jul 17, 2019 at 02:53:20PM +0300, Sergei Kornilov wrote: >Hello > >Please recheck with track_io_timing = on in configuration. explain >(analyze,buffers) with this option will report how many time we spend >during i/o > >> Buffers: shared hit=2 read=31492 > >31492 blocks / 65 sec ~ 480 IOPS, not bad if you are using HDD > >Your query reads table data from disks (well, or from OS cache). You need >more RAM for shared_buffers or disks with better performance. > Either that, or try creating a covering index, so that the query can do an index-only scan. That might reduce the amount of IO against the table, and in the index the data should be located close to each other (same page or pages close to each other). So try something like CREATE INDEX ios_idx ON table (field, user_id); and make sure the table is vacuumed often enough (so that the visibility map is up to date). regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services