mauricio / postgresql-async

Async, Netty based, database drivers for PostgreSQL and MySQL written in Scala
Apache License 2.0
1.43k stars 222 forks source link

Convert paramter to wrong type , and causes very large performances problems #254

Closed xiaobaojiang closed 6 years ago

xiaobaojiang commented 6 years ago

https://github.com/mauricio/postgresql-async/blob/master/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/column/PostgreSQLColumnEncoderRegistry.scala#L33

 classOf[Int] -> (IntegerEncoderDecoder -> ColumnTypes.Numeric),
    classOf[java.lang.Integer] -> (IntegerEncoderDecoder -> ColumnTypes.Numeric),

    classOf[java.lang.Short] -> (ShortEncoderDecoder -> ColumnTypes.Numeric),
    classOf[Short] -> (ShortEncoderDecoder -> ColumnTypes.Numeric),

    classOf[Long] -> (LongEncoderDecoder -> ColumnTypes.Numeric),
    classOf[java.lang.Long] -> (LongEncoderDecoder -> ColumnTypes.Numeric),

Convert Integer、Long、Short、Float and Double to Numeric , and the attribute of table is Integer or Long, If you use preparedStatement , and will causes larger performances problems.

e.g Having table users, and has attribute uid with primary key.

  1. use statment and find searching by index
    explain analyse select * from users where uid in (200,500,800);
  2. use preparedStatement with correct paramter type, and find searching by index
    PREPARE fooplan (int, int, int) AS
    select *
    from users
    where uid in ($1, $2, $3);
    explain analyse EXECUTE fooplan(200, 500, 800);
  3. use preparedStatement with wrong paramter type, and find searching by seq
    PREPARE fooplan1 (numeric, numeric, numeric) AS
    select *
    from users
    where uid in ($1, $2, $3);
    explain analyse EXECUTE fooplan1(200, 500, 800);
gabfssilva commented 6 years ago

related to #212 and #241

oshai commented 5 years ago

I fixed/reverted this in jasync-sql(fork) 0.8.30: https://github.com/jasync-sql/jasync-sql/pull/16 . more details in the issue: https://github.com/jasync-sql/jasync-sql/issues/15