Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Z5ObF-0003DU-B3 for pgsql-bugs@arkaria.postgresql.org; Thu, 18 Jun 2015 01:26:37 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Z5ObE-0004j8-1T for pgsql-bugs@arkaria.postgresql.org; Thu, 18 Jun 2015 01:26:36 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Z5ObD-0004j2-AK for pgsql-bugs@postgresql.org; Thu, 18 Jun 2015 01:26:35 +0000 Received: from mail-ie0-x230.google.com ([2607:f8b0:4001:c03::230]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1Z5Ob8-0005fx-8T for pgsql-bugs@postgresql.org; Thu, 18 Jun 2015 01:26:33 +0000 Received: by iebgx4 with SMTP id gx4so45476419ieb.0 for ; Wed, 17 Jun 2015 18:26:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:message-id:date:from:reply-to:user-agent:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=JazH/WMn4t+KuIixOM9Db2N7Dx6a7Tpzs9Jy5qgrldA=; b=oHrvbWfjhszOiM0U5b4fXRAX6o9/KuOVxJ3t0C7M3Wxhk9gGxoD7fN3LDQqqynHpXS V9FrKtWbhVBLU76bk92nZRldBTmAUmg2eujYxiXSU/aXqFQ+YrrkXeNiER+XS2gmecHG XeF3UklifFEqTYGbnpX8ZU9WoXsZKR7wu3lxyMHzy8AHiu3KMwK8vMhGl1tzF6qoOKZ/ IqvBzuOSmArZ4c0VEuUdNg1HsZad16qiWP/mxmTcNP76mPnGFOQyKIDkelBFHuyQm5Vp nWMYKbTpYPIJzqSjCml3UrkviZtvGXYbT9PdKEqRUqV2+JhwLZRu0ovBkDiTddoMoyFi Jx+Q== X-Received: by 10.50.49.46 with SMTP id r14mr35231195ign.45.1434590789297; Wed, 17 Jun 2015 18:26:29 -0700 (PDT) Received: from [172.26.2.220] ([173.195.54.28]) by mx.google.com with ESMTPSA id o200sm3831684ioo.43.2015.06.17.18.26.27 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Jun 2015 18:26:28 -0700 (PDT) Message-ID: <55821E42.6040907@iki.fi> Date: Wed, 17 Jun 2015 21:26:26 -0400 From: Heikki Linnakangas Reply-To: hlinnaka@iki.fi User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.7.0 MIME-Version: 1.0 To: digoal@126.com, pgsql-bugs@postgresql.org Subject: Re: BUG #13449: Auto type cast (int -> numeric) non-reasonable, will case performance problem References: <20150617021707.2740.62807@wrigleys.postgresql.org> In-Reply-To: <20150617021707.2740.62807@wrigleys.postgresql.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On 06/16/2015 10:17 PM, digoal@126.com wrote: > When i use an big digital, it auto convert to numeric. and there is no > int&numeric operator, so left opr auto convert to numeric also. > for exp: > postgres=# create table t3(id int); > CREATE TABLE > postgres=# insert into t3 select generate_series(1,10000000); > INSERT 0 10000000 > postgres=# create index idx_t3_id on t3(id); > CREATE INDEX > postgres=# explain analyze select * from t3 where > id>999999999999999999999999999999999; > QUERY PLAN > > ------------------------------------------------------------------------------------------------------------------------------------ > Index Only Scan using idx_t3_id on t3 (cost=0.43..238213.43 rows=3333333 > width=4) (actual time=4052.914..4052.914 rows=0 loops=1) > Filter: ((id)::numeric > '999999999999999999999999999999999'::numeric) > Rows Removed by Filter: 10000000 > Heap Fetches: 10000000 > Planning time: 0.283 ms > Execution time: 4052.944 ms > (6 rows) > > postgres=# explain analyze select * from t3 where > id=999999999999999999999999999999999; > QUERY PLAN > > ---------------------------------------------------------------------------------------------------------------------------------- > Index Only Scan using idx_t3_id on t3 (cost=0.43..238213.43 rows=50000 > width=4) (actual time=3907.391..3907.391 rows=0 loops=1) > Filter: ((id)::numeric = '999999999999999999999999999999999'::numeric) > Rows Removed by Filter: 10000000 > Heap Fetches: 10000000 > Planning time: 0.103 ms > Execution time: 3907.421 ms > (6 rows) > > I think ,this case, PostgreSQL should convert > 999999999999999999999999999999999 to the same type with column id's type > int. and raise error. > > there is some problem, user can use this to SQL injection attack or other > things, Oops, Application has ability to filter the overflow digital, but i > think PostgreSQL also has responsibility to prevent overflow occure. The current behaviour seems perfectly fine to me. If you want to force a specific datatype, you're better off passing the parameter out-of-line, and specify the datatype explicitly. I don't see any security issue here. - Heikki -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs