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 1ho5jN-0001po-4t for pgsql-performance@arkaria.postgresql.org; Thu, 18 Jul 2019 12:41:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ho5jL-00021s-29 for pgsql-performance@arkaria.postgresql.org; Thu, 18 Jul 2019 12:41:51 +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 1ho5jK-000206-IV for pgsql-performance@lists.postgresql.org; Thu, 18 Jul 2019 12:41:50 +0000 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ho5jH-00064u-D1 for pgsql-performance@lists.postgresql.org; Thu, 18 Jul 2019 12:41:50 +0000 Received: by mail-wm1-x344.google.com with SMTP id x15so25448098wmj.3 for ; Thu, 18 Jul 2019 05:41:46 -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=87qEywuZPwZ8+BN9Jo3pYpVIL76taU7XHu8zMm4h018=; b=oJipou5Dcr8W3JqkdWPg480gqqFXu8WR625e4KwyRPDwF0WobhF9uN83UcM0WHy6LN t+BFAkLuJv9zw5nolD/G1N8W1idcLfs+4nmPwk75YLkbp9XoUew0aRfr9InsK0D2mb8s P6QP+eZl2mD1q7nKPwGENfqyP+WIF/MCzuy6wRgpG22S6LQoSY9aGX94LzGMLFHLzA/1 CosxsozOn4nQBPc6UUgHmSU9Ogyx+zUmIxiHF+r4su/JxfKvlejs1UbCliraqGcAzR0o RiAgLlmv1InBSQT99n34dKk4FcQtBR9ccWX7I0Vf+4SGd1z20rT+0ZTfN5GnJz8I5irX 7wNg== 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=87qEywuZPwZ8+BN9Jo3pYpVIL76taU7XHu8zMm4h018=; b=dkmDPRwddxGeaAfGrS1jIGNy+Ll3v6vo1Ho6vrNaBRuBBxWnH/RI4UI4ZJbj3VrtHp QHSlHfVcCgy0MvssTJgs9a+KXAPSOm6I7bDeBo5LkqfJUylm5fJ653iH2dWx4WycMxvR z7ZtXxyIXfavOVqhR6dhyNjKpdBYAtzthCQ8EbkcJ8sFA9jqUyZD1Tnw3Ok8nhIALkmo QFRU1IRWyzZqo294dPtLrtDj6HxyF4ZAzX5J+D/jdjg8WKHMp+E2T4Za+MC4X4Bs/WRp NtCUuMX7JxBvJXB3kW8sayISpcZbCcMl8nO7U6CT75igextLx9/GJqYxxdMZ0nST5R4E atcA== X-Gm-Message-State: APjAAAXzJQoPVQh3Vy7W22q4Fb/r0eakamWSn5JuvXk3aGJq1K7jPGQw oLZSWwUvLQa1789e9vlEqg70FQ== X-Google-Smtp-Source: APXvYqzDPFtlNsfYYTzwhGRlLMieuZBuVnpSy2bY67UCZZIxeGPKs6bVQgqZBwOAtBgMCnrH8nRDXw== X-Received: by 2002:a1c:9d53:: with SMTP id g80mr37260937wme.103.1563453703258; Thu, 18 Jul 2019 05:41:43 -0700 (PDT) Received: from localhost (static-84-42-175-93.net.upcbroadband.cz. [84.42.175.93]) by smtp.gmail.com with ESMTPSA id x83sm27715442wmb.42.2019.07.18.05.41.42 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 18 Jul 2019 05:41:42 -0700 (PDT) Date: Thu, 18 Jul 2019 14:41:09 +0200 From: Tomas Vondra To: mayank rupareliya Cc: pgsql-performance@lists.postgresql.org Subject: Re: Searching in varchar column having 100M records Message-ID: <20190718124109.2k22rkcrhviee5po@development> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716-1444-295967-dirty List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, Jul 18, 2019 at 05:21:49PM +0530, mayank rupareliya wrote: >*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.* > > >Thanks Sergei.. >*track_io_timing = on helps.. Following is the result after changing that >config.* > >Aggregate (cost=10075.78..10075.79 rows=1 width=8) (actual >time=63088.198..63088.199 rows=1 loops=1) > Buffers: shared read=31089 > I/O Timings: read=61334.252 > -> Bitmap Heap Scan on fields (cost=72.61..10069.32 rows=2586 width=0) >(actual time=69.509..63021.448 rows=31414 loops=1) > Recheck Cond: ((field)::text = 'Klein'::text) > Heap Blocks: exact=30999 > Buffers: shared read=31089 > I/O Timings: read=61334.252 > -> Bitmap Index Scan on index_field (cost=0.00..71.96 rows=2586 >width=0) (actual time=58.671..58.671 rows=31414 loops=1) > Index Cond: ((field)::text = 'Klein'::text) > Buffers: shared read=90 > I/O Timings: read=45.316 >Planning Time: 66.435 ms >Execution Time: 63088.774 ms > How did that help? It only gives you insight that it's really the I/O that takes time. You need to reduce that, somehow. > >*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).* > >Thanks Tomas... I tried this and result improved but not much. > Well, you haven't shown us the execution plan, so it's hard to check why it did not help much and give you further advice. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services