Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UFTqx-0005V1-Ti for pgsql-jdbc@arkaria.postgresql.org; Tue, 12 Mar 2013 18:23:12 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UFTqx-0006Yr-9J for pgsql-jdbc@arkaria.postgresql.org; Tue, 12 Mar 2013 18:23:11 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UFTqv-0006Xs-PR for pgsql-jdbc@postgresql.org; Tue, 12 Mar 2013 18:23:10 +0000 Received: from st11p05mm-asmtpout005.mac.com ([17.172.108.250] helo=st11p05mm-asmtp005.mac.com) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UFTqr-0004Np-4n for pgsql-jdbc@postgresql.org; Tue, 12 Mar 2013 18:23:08 +0000 Received: from [10.0.10.27] (ip68-2-30-162.ph.ph.cox.net [68.2.30.162]) by st11p05mm-asmtp005.mac.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Jan 3 2012)) with ESMTPSA id <0MJK00KE28DQ4H10@st11p05mm-asmtp005.mac.com> for pgsql-jdbc@postgresql.org; Tue, 12 Mar 2013 18:22:41 +0000 (GMT) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.10.8626,1.0.431,0.0.0000 definitions=2013-03-12_07:2013-03-12, 2013-03-12, 1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 ipscore=0 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=6.0.2-1302030000 definitions=main-1303120136 Content-type: multipart/alternative; boundary="Apple-Mail=_1D2F08CE-A920-449C-82B9-A6A1EB5BDE4D" MIME-version: 1.0 (Mac OS X Mail 6.2 \(1499\)) Subject: Re: A new JDBC driver... From: Kevin Wooten In-reply-to: Date: Tue, 12 Mar 2013 11:22:38 -0700 Cc: "pgsql-jdbc@postgresql.org" Message-id: <47737654-1645-4B3F-8FDF-0156A289A2AF@me.com> References: To: Dave Cramer X-Mailer: Apple Mail (2.1499) X-Pg-Spam-Score: -4.2 (----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org --Apple-Mail=_1D2F08CE-A920-449C-82B9-A6A1EB5BDE4D Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=windows-1252 If you remember what I said, I referred to its age as both a positive = and a negative. I understand that all of this special case code is what = makes things work in the real world. That being said, here are some = things I can remember off the top of my head... =20 Take the simple case of "getString" in the ResultSet. It's full of = special case code, complete with a nice comment about a "hack to be = compatible with text protocol" that has something to do with Dates; It = even specifically references the "hstore" type by name. In addition it = seems there can be up to 5 hashmap lookups, to get the type when going = through getSting depending on the actual type of the column. To truly = understand what this function does is a fun task as it's used in quite a = few places. The getSQLType function has comments about not being able to truly know = which types are arrays and which are not. In comparison the new code = doesn't care because the object is converted to an array by a decoder. = I won't forget to mention that the current code is EXTREMELY slow when = it comes to using getDatabaseMetaData and getMetaData calls; I mention = this because I have a pull request from months ago that fixes the = performance issue that hasn't been integrated yet ;) On Mar 12, 2013, at 2:51 AM, Dave Cramer wrote: > Kevin, >=20 > I think this is a very interesting idea. I've often thought that = writing a stripped down version of the driver that did the basics *very* = well would be an interesting project. >=20 > I'm wondering how to integrate this into the official project to live = beside the current driver, and possibly supersede it ? >=20 > You mention "it is showing it's age" can you be more specific ? >=20 > Regards, >=20 > Dave Cramer >=20 > dave.cramer(at)credativ(dot)ca > http://www.credativ.ca >=20 >=20 > On Mon, Mar 11, 2013 at 9:19 PM, Kevin Wooten wrote: > So=85 I did a crazy thing=85 I created an entirely new JDBC driver. >=20 > (For those who care there's an actual question at the bottom=85 this = isn't just bragging) >=20 > About 10 days ago I set out to fix the current driver's support for = composite and array objects. Currently they are only ever retrieved as = string encoding due to the use of the TEXT format for those types; = parsing these encoded strings seemed just short of a nightmare. = Ambition got the better of me and before I knew it I had a "working" = implementation of the entire FE/BE protocol (save for Copy In/Out). >=20 > I began by hacking the driver to force it into binary mode and pulling = the raw data with getBytes. Then I started building a framework for = recognizing, encoding and decoding all the possible types PostgreSQL = knows about. Once that was working well, my mission was to rework this = into the current driver. This proved almost impossible due to 1) my = limited familiarity with the code and 2) the assumptions it makes about = the formats of things like parameters. In the end it seemed too time = consuming for ME to do this. So, partly for fun, I decided to just = implement the FE/BE protocol and see where it got me. Next thing I knew = I was running queries and retrieving data. Basically it's just a side = project, of a retro-fit, that went wrong and has spiraled out of control = ;) >=20 > Currently my "driver" (I use the term loosely as you can imagine it's = state of compliance about 6 days of real work) looks like this: >=20 > * Basic support for JDBC interfaces (Driver, Connection, = PreparedStatement, ResultSet) > * Can be discovered and loaded automatically through JDBC4 = loader > * Supports ONLY JDBC4 interfaces (no attempt to compile to only = JDBC2/3 is made) > * Lots of stuff missing, non-conformant or just plain broken > * Speaks "BINARY" format almost exclusively > * Extremely clean and simple interface for supporting new types; = VERY DRY (only added in 1 place ever) > * Unsupported formats can fallback to "TEXT" > * Almost all of the current standard types are supported (even = the hard ones like numerics, timestamps, dates) > * Can decode any recognized type to a Java object (this includes any = imaginable composite or array type) > * Connection.setTypeMap and ResultSet.get(int idx, Map) are both = fully supported > * Requests for composite objects that have no custom mapping are = returned as HashMap > * Arrays can be decoded as a List, Map or native array (e.g. = Object[], int[]) > * As an an extension it can decode whole rows into POJO's as = well (acts a tiny bit like MyBatis) > * Asynchronous I/O engine provided by Netty > * All connections share a single group of worker threads > * LISTEN/NOTIFY and notifications can come through = asynchronously > * Netty has a great system for managing buffers and = reading/writing messages that shows increased speed > * Performance wasn't a goal of this project but it's a nice side = effect > * Maven project > * Written against Java 7 > * Obviously to enter any sort of real use the source version = will have to be dialed down > * Shows some serious gains in performance > * Query and retrieve from the ResultSet a million rows with = timestamps and it's about a 4-5x increase in speed > * Obviously some types there is no speed difference > * Again I say, performance was NOT a goal of this project it's = just a nice side effect >=20 > BINARY SUPPORT > As outlined above I started the project to support decoding of = Composite and Array types. To accomplish this I download "pg_type", = "pg_attribute" and "pg_proc" to the client upon connection. I then = create a type registry that holds all the required details of all the = types. Procedures, for both TEXT and BINARY protocols, are looked up = and matched by name (e.g. "bool_send", "money_recv", etc) by a list of = "Procedure Providers". When a DataRow message is received it looks up = the type in the registry and calls the appropriate TEXT or BINARY = decoder to decode the row. When sending parameter data the type is = located and the it's encoder is called to encode the data. Reading = through the driver mailing-lists, it seems using binary only has some = ramifications as far as type coercion and such are concerned; currently = all user initiated queries use the Extended Protocol & Statement = Describe to ensure parameter types/values are correct. >=20 > Where to go from here=85 >=20 > The major question I would like to ask is=85=20 >=20 > Should I continue on this path of a new driver and see if people = join or should I take what I have learned and try to refit it into the = current code? >=20 > I am no dummy. I understand the years of experience the current = driver has to ensure it works well in an extremely large number of = cases. At the same time, anybody who has peeked around in there (and I = have done quite a bit of it) knows its showing its age. My driver is = 100% new code=85 not a stitch of the old was used. Give this, it seems = like transplanting my new "core" into the current project would be like = giving it a brain transplant just after a fresh head transplant; in = other words=85 a rewrite. >=20 > I'd love it if some folks in the know could take a look at my code and = see if it stirs up any ideas on integration or just makes you want to = jump off a bridge. >=20 > If you read this far you get a cookie=85 >=20 > Here is the GitHub project=85 https://github.com/kdubb/pgjdbc-ng >=20 > Kevin >=20 --Apple-Mail=_1D2F08CE-A920-449C-82B9-A6A1EB5BDE4D Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=windows-1252

The getSQLType function has = comments about not being able to truly know which types are arrays and = which are not.  In comparison the new code doesn't care because the = object is converted to an array by a decoder.   I won't forget to = mention that the current code is EXTREMELY slow when it comes to using = getDatabaseMetaData and getMetaData calls; I mention this because I have = a pull request from months ago that fixes the performance issue that = hasn't been integrated yet ;)


On = Mar 12, 2013, at 2:51 AM, Dave Cramer <pg@fastcrypt.com> = wrote:

Kevin,

I = think this is a very interesting idea. I've often thought that writing a = stripped down version of the driver that did the basics *very* well = would be an interesting project.

I'm wondering how to integrate = this into the official project to live beside the current driver, and = possibly supersede it ?

You= mention "it is showing it's age" can you be more specific ?

Regards,

Dave = Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca


On Mon, Mar 11, 2013 at 9:19 PM, = Kevin Wooten <kdubb@me.com> wrote:
So=85 I did a crazy thing=85 I = created an entirely new JDBC driver.

(For those who care there's = an actual question at the bottom=85 this isn't just = bragging)

About 10 days ago I set out to fix the current driver's = support for composite and array objects.  Currently they are only = ever retrieved as string encoding due to the use of the TEXT format for = those types; parsing these encoded strings seemed just short of a = nightmare.  Ambition got the better of me and before I knew it I = had a "working" implementation of the entire FE/BE protocol (save for = Copy In/Out).

I began by hacking the driver to force it into binary mode and = pulling the raw data with getBytes. Then I started building a framework = for recognizing, encoding and decoding all the possible types PostgreSQL = knows about.   Once that was working well, my mission was to = rework this into the current driver.  This proved almost impossible = due to 1) my limited familiarity with the code and 2) the assumptions it = makes about the formats of things like parameters.  In the end it = seemed too time consuming for ME to do this.  So, partly for fun, I = decided to just implement the FE/BE protocol and see where it got me. = Next thing I knew I was running queries and retrieving data. =  Basically it's just a side project, of a retro-fit, that went = wrong and has spiraled out of control ;)

Currently my "driver" (I use the term loosely as you can imagine = it's state of compliance about 6 days of real work) looks like = this:

* Basic support for JDBC interfaces (Driver, Connection, = PreparedStatement, ResultSet)
* Can be discovered and = loaded automatically through JDBC4 loader
* Supports ONLY JDBC4 interfaces = (no attempt to compile to only JDBC2/3 is made)
* Lots of stuff missing, = non-conformant or just plain broken
* Speaks "BINARY" format almost = exclusively
* = Extremely clean and simple interface for supporting new types; VERY DRY = (only added in 1 place ever)
* Unsupported formats can = fallback to "TEXT"
* = Almost all of the current standard types are supported (even the hard = ones like numerics, timestamps, dates)
* Can decode any recognized type to a Java object (this includes any = imaginable composite or array type)
* Connection.setTypeMap and = ResultSet.get(int idx, Map) are both fully supported
* Requests for composite = objects that have no custom mapping are returned as HashMap
* Arrays can be decoded as a = List, Map or native array (e.g. Object[], int[])
* As an an extension it = can decode whole rows into POJO's as well (acts a tiny bit like = MyBatis)
* Asynchronous I/O engine provided by Netty
* All connections share a single = group of worker threads
* LISTEN/NOTIFY and = notifications can come through asynchronously
* Netty has a great system for = managing buffers and reading/writing messages that shows increased = speed
* Performance wasn't a = goal of this project but it's a nice side effect
* Maven project
* = Written against Java 7
* = Obviously to enter any sort of real use the source version will have to = be dialed down
* Shows some serious gains in performance
* Query and retrieve from the = ResultSet a million rows with timestamps and it's about a 4-5x increase = in speed
* = Obviously some types there is no speed difference
* Again I say, = performance was NOT a goal of this project it's just a nice side = effect

BINARY SUPPORT
= As outlined above I started the project to support decoding of = Composite and Array types.  To accomplish this I download = "pg_type", "pg_attribute" and "pg_proc" to the client upon connection. =  I then create a type registry that holds all the required details = of all the types.  Procedures, for both TEXT and BINARY protocols, = are looked up and matched by name (e.g. "bool_send", "money_recv", etc) = by a list of "Procedure Providers".  When a DataRow message is = received it looks up the type in the registry and calls the appropriate = TEXT or BINARY decoder to decode the row.  When sending parameter = data the type is located and the it's encoder is called to encode the = data. Reading through the driver mailing-lists, it seems using binary = only has some ramifications as far as type coercion and such are = concerned; currently all user initiated queries use the Extended = Protocol & Statement Describe to ensure parameter types/values are = correct.

Where to go from here=85

The major question I would like to = ask is=85 

= Should I continue on this path of a new driver and see if people = join or should I take what I have learned and try to refit it into the = current code?

I am no dummy.  I understand the years of experience the = current driver has to ensure it works well in an extremely large number = of cases.  At the same time, anybody who has peeked around in there = (and I have done quite a bit of it) knows its showing its age. =   My driver is 100% new code=85 not a stitch of the old was = used.  Give this, it seems like transplanting my new "core" into = the current project would be like giving it a brain transplant just = after a fresh head transplant; in other words=85 a rewrite.

I'd love it if some folks in the know could take a look at my code = and see if it stirs up any ideas on integration or just makes you want = to jump off a bridge.

If you read this far you get a = cookie=85

Here is the GitHub project=85  https://github.com/kdubb/pgjdbc-ng

Kevin


= --Apple-Mail=_1D2F08CE-A920-449C-82B9-A6A1EB5BDE4D--