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 1f0sRM-0000as-VO for pgsql-general@arkaria.postgresql.org; Tue, 27 Mar 2018 17:31:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f0sRL-0000ru-SJ for pgsql-general@arkaria.postgresql.org; Tue, 27 Mar 2018 17:31:19 +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_SHA384:256) (Exim 4.89) (envelope-from ) id 1f0sRL-0000rk-Fz for pgsql-general@lists.postgresql.org; Tue, 27 Mar 2018 17:31:19 +0000 Received: from mail-pg0-x232.google.com ([2607:f8b0:400e:c05::232]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1f0sRJ-0002ET-7J for pgsql-general@postgresql.org; Tue, 27 Mar 2018 17:31:18 +0000 Received: by mail-pg0-x232.google.com with SMTP id b9so1674867pgf.6 for ; Tue, 27 Mar 2018 10:31:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=illuminatedcomputing-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=/+TRgzc7aitwCs2yuY9eHjeXE0LwsU9nweWrWcscN6o=; b=ow24gPeqtvpoAxkcJUWPiaSSsdzclbbwbQQLtHZgiOywigK9ILVA9o2Xhcg7cPIxK8 p9Sn34UTlGtfjkSHjzm6h9UWeOvDDi7mxtCen6ImDeGeCSUQpqgFzT5wDusJM1F/jnzv 8BecLiYXZqlFYQ+oTrmGqLXRUQkFr+K7kKVKEQHTDHDc+EK7nKHjccGFVXdKVKzorwp/ MHGvGrBgZrBzbV3WH4+jy53nOwU51+p0SSelM/qv3MHgfIYT/PyFVnTiPHEiICsNtcTD eqjuj0L7xW3uz+PqjWvvLaZiYfWA1rg1vukXq1I/hDan8/rMEIWMQvtt1y1RyY0BjTz6 oUeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=/+TRgzc7aitwCs2yuY9eHjeXE0LwsU9nweWrWcscN6o=; b=b51975AsLFY7sqGHObaAQK8z3H7zOnGb+Ye9kDLa4Da3UuXRRY/FPWMO0sfMKjyp/r 9CDwsf+Nwh+5uU257CkbdyzcdswuIoaa4EtDPbgwE/BaiZOVr19Nq+cpag1T/qcPInOb JjJZ1yUgD+Iv7fI4vIidmxEliDImorDLyf4qyLQrmp1PdnPXQUnpe0LRrSAtqTihi0Om 9gsXWE0t+j2Bp/hdcM5cR5u3Dpni/7AK8PJPeeQpqUWAdmjemn4Oqe40ubnh6m5qjFoI vBAg0xMEkuVn/zvEzB+vOpVStqSYWdjvYeiSZx3AopliQiS8RCHrHVu6uW4QLBNfcxZm nAnA== X-Gm-Message-State: AElRT7FUCLdlIfLIldneFL4S0ius87796Rcrjl26KKzdzz8IhoiZUlcw O0Kop83YoBG86u15dF3vrzSMpeJ3 X-Google-Smtp-Source: AIpwx49e3e+jARtol/RO2QzjxTQHgp7BEVP2FffMzHogSyJKhERYcf70GOAxGEqycTbk4hzt4tqdjQ== X-Received: by 10.101.96.65 with SMTP id b1mr153225pgv.340.1522171874423; Tue, 27 Mar 2018 10:31:14 -0700 (PDT) Received: from [192.168.2.201] (static-50-53-109-254.bvtn.or.frontiernet.net. [50.53.109.254]) by smtp.googlemail.com with ESMTPSA id s78sm4091892pfa.161.2018.03.27.10.31.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Mar 2018 10:31:13 -0700 (PDT) Subject: Re: Proposition for better performance To: hmidi slim Cc: pgsql-general@postgresql.org References: <2e436152-eda0-d67d-4b20-90da0db4a049@illuminatedcomputing.com> From: Paul Jungwirth Message-ID: <834d8a70-386d-7101-f846-ae572140af92@illuminatedcomputing.com> Date: Tue, 27 Mar 2018 10:31:12 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 03/27/2018 10:04 AM, hmidi slim wrote: > the query that I used to fetch products was: > select * from availability > where ('27-03-2018' between start_date and end_date) > and ('31-03-2018' between start_date and end_date); > > I added another column named during of type daterange and I created a > gist index : > create index idx on availability(during); That creates a b-tree index. Also, what did you set `during` to? > select * from availability > where during @> daterange(''27-03-2018', '31-03-2018'); > > With a table of 15M rows I got an execution time of 1 minute. What was the query plan? Did you confirm that it used the index? -- Paul ~{:-) pj@illuminatedcomputing.com