Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g9FLJ-0003lG-Sw for pgsql-general@arkaria.postgresql.org; Sun, 07 Oct 2018 20:07:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g9FLH-000624-A2 for pgsql-general@arkaria.postgresql.org; Sun, 07 Oct 2018 20:07:55 +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 1g9FLG-00061x-SC for pgsql-general@lists.postgresql.org; Sun, 07 Oct 2018 20:07:55 +0000 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1g9FLD-0001af-A6 for pgsql-general@lists.postgresql.org; Sun, 07 Oct 2018 20:07:53 +0000 Received: by mail-wm1-x343.google.com with SMTP id 143-v6so6173696wmf.1 for ; Sun, 07 Oct 2018 13:07:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-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=Ma5FKE3mhgXK50V7DxSdJzqWDZwVhbv+2SOG0q3yAHY=; b=s4BY4LNrubYgTaPmyDvKjv4nmc3cStYE4rljNGUjDOZTvASeC1ELdtg0vh9Tuc4J8a //BIsQQlxOfdt/40EMbUB5I/BKlwqoRZTWP8E3s0uriAm4kbxo/9QbIgzXavpFGrjlUW ustRQA0iOKeIGr4/sX3LVD5FrDW3cqBTy5O1oi3yqtHwLl3o5h7tRrCHQYEu2J3rZmeD V5kRpcz2PrX7yuAHv511Jg5PqDOWJUlrWYZgUbC9Dof1pcW4jX6yGyim+nxC0pILUcd8 jHVBWWDNQYAb8r/URWgEy7VDGqQ8uaVZjpiKZB2gLaxkpUy4+za5mET/2FBbbukqsknk n2gg== 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=Ma5FKE3mhgXK50V7DxSdJzqWDZwVhbv+2SOG0q3yAHY=; b=Ns/WYBr+aBFr6mB1OjwMFLVB5PdoZ+/WZ/DB4zOp0S/KFESxVUuVg9c2006xHzjHkZ VFhBUn6myLelf3I/VzHhsA4TFrAVvEtLATWF5wBtLd6IIfwlVfhq61jhmf1F4EzDxCL8 wyZRMIkqQZOgVxbH+LqdQs4No+Gg0hqC7bV6imFETW6IHtDOHS/hxZ8GKe4gus1R5vKc 4dr/XAZAtqEJwgU16PM1xlrll7mydiNnwV5BuZBGV/TNJGNVTkrgcunE1D0ZKpYaTO// 83YYEhk6p7GmCcIRHTu2dbyt2SlwzWv4L3oYIs9DGVGJmvJ1vmPp0dPMGWRek6uorQYB VouQ== X-Gm-Message-State: ABuFfojhJnKzhN1YADPKJlebzhhQMLl9iM56wuqGjLdXTu38WETBjUYa 1F3gE8UPks7i/ENn4KaBeLw56jPbBZptG34fConqFqrsjW8htCJiIR+tiSQFAi44BBjQXhcicYc yIKAWt4NxCVafoiCM/k4MQAi1hMbl1x6ztfelcqzPEP8hqOdipGue+ZPFt5sGvmB1Z2iIW1bb2Y HYBMsFy+9ZR0D52dTVmJ4= X-Google-Smtp-Source: ACcGV61R638grmJ56CPdl8lfmt0qxpv+V4Kt2TF4k2Nky39VzvFmXxz2w/SQX6T5HMsmsDk6pOhGQg== X-Received: by 2002:a1c:ac82:: with SMTP id v124-v6mr13482229wme.10.1538942869012; Sun, 07 Oct 2018 13:07:49 -0700 (PDT) Received: from [10.137.2.19] (ip-86-49-251-104.net.upcbroadband.cz. [86.49.251.104]) by smtp.gmail.com with ESMTPSA id t24-v6sm24438426wra.5.2018.10.07.13.07.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Oct 2018 13:07:48 -0700 (PDT) Subject: Re: Why the index is not used ? To: ROS Didier , "folarte@peoplecall.com" Cc: "pavel.stehule@gmail.com" , "pgsql-sql@lists.postgresql.org" , "pgsql-performance@lists.postgresql.org" , "pgsql-general@lists.postgresql.org" References: <74090066a33740ea8fc442cc70f8afa2@PCYINTPEXMU001.NEOPROD.EDF.FR> <3a14f7f8fbda4e868b663b31e8c5fa16@PCYINTPEXMU001.NEOPROD.EDF.FR> From: Tomas Vondra Message-ID: <88005798-8b90-3535-cc1c-a915a9e12d17@2ndquadrant.com> Date: Sun, 7 Oct 2018 22:07:44 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <3a14f7f8fbda4e868b663b31e8c5fa16@PCYINTPEXMU001.NEOPROD.EDF.FR> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, On 10/07/2018 08:32 PM, ROS Didier wrote: > Hi Francisco > > Thank you for your remark. > You're right, but it's the only procedure I found to make search on > encrypted fields with good response times (using index) ! > Unfortunately, that kinda invalidates the whole purpose of in-database encryption - you'll have encrypted on-disk data in one place, and then plaintext right next to it. If you're dealing with credit card numbers, then you presumably care about PCI DSS, and this is likely a direct violation of that. > Regarding access to the file system, our servers are in protected network areas. few people can connect to it. > Then why do you need encryption at all? If you assume access to the filesystem / storage is protected, why do you bother with encryption? What is your threat model? > it's not the best solution, but we have data encryption needs and > good performance needs too. I do not know how to do it except the > specified procedure.. > > if anyone has any proposals to put this in place, I'm interested. > One thing you could do is hashing the value and then searching by the hash. So aside from having the encrypted column you'll also have a short hash, and you may use it in the query *together* with the original condition. It does not need to be unique (in fact it should not be to make it impossible to reverse the hash), but it needs to have enough distinct values to make the index efficient. Say, 10k values should be enough, because that means 0.01% selectivity. So the function might look like this, for example: CREATE FUNCTION cchash(text) RETURNS int AS $$ SELECT abs(hashtext($1)) % 10000; $$ LANGUAGE sql; and then be used like this: CREATE INDEX idx_cartedecredit_cc02 ON cartedecredit(cchash(cc)); and in the query SELECT pgp_sym_decrypt(cc, 'motdepasse') FROM cartedecredit WHERE pgp_sym_decrypt(cc, 'motdepasse')='test value 32' AND cchash(cc) = cchash('test value 32'); Obviously, this does not really solve the issues with having to pass the password to the query, making it visible in pg_stat_activity, various logs etc. Which is why people generally use FDE for the whole disk, which is transparent and provides the same level of protection. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services