Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Z5EQR-0003NN-Iw for pgsql-bugs@arkaria.postgresql.org; Wed, 17 Jun 2015 14:34:47 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Z5EQQ-0006Oy-JP for pgsql-bugs@arkaria.postgresql.org; Wed, 17 Jun 2015 14:34:46 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Z52ve-0004Fj-3X for pgsql-bugs@postgresql.org; Wed, 17 Jun 2015 02:18:14 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1Z52vV-0005mH-Gj for pgsql-bugs@postgresql.org; Wed, 17 Jun 2015 02:18:11 +0000 MIME-Version: 1.0 Subject: BUG #13449: Auto type cast (int -> numeric) non-reasonable, will case performance problem To: pgsql-bugs@postgresql.org From: digoal@126.com Date: Wed, 17 Jun 2015 02:17:07 +0000 Message-ID: <20150617021707.2740.62807@wrigleys.postgresql.org> X-Pg-Spam-Score: -1.9 (-) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 The following bug has been logged on the website: Bug reference: 13449 Logged by: digoal Email address: digoal@126.com PostgreSQL version: 9.4.4 Operating system: CentOS 6.x x64 Description: 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. -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs