Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UFhIk-0003uw-3T for pgsql-jdbc@arkaria.postgresql.org; Wed, 13 Mar 2013 08:44:46 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UFhIi-0008E3-Rl for pgsql-jdbc@arkaria.postgresql.org; Wed, 13 Mar 2013 08:44:44 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UFhIi-0008Dy-1i for pgsql-jdbc@postgresql.org; Wed, 13 Mar 2013 08:44:44 +0000 Received: from prod2.officenet.no ([195.159.87.246]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UFhIf-0003Ti-7x for pgsql-jdbc@postgresql.org; Wed, 13 Mar 2013 08:44:43 +0000 Received: from localhost ([127.0.0.1] helo=prod2) by prod2.officenet.no with esmtp (Exim 4.76) (envelope-from ) id 1UFhGc-0001Xz-9T for pgsql-jdbc@postgresql.org; Wed, 13 Mar 2013 09:42:34 +0100 Date: Wed, 13 Mar 2013 09:42:33 +0100 (CET) From: Andreas Joseph Krogh To: pgsql-jdbc@postgresql.org Message-ID: In-Reply-To: Subject: Re: A new JDBC driver... MIME-Version: 1.0 X-Mailer: OfficeNet Mail 1.9.0-SNAPSHOT X-Pg-Spam-Score: -3.2 (---) Content-Type: text/html;charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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
P=C3=A5 tirsdag 12. mars 2013 kl. 02:19:11, skrev Kevin Wooten <kdubb@me.com>:
So=E2=80=A6 I did a crazy thing=E2=80= =A6 I created an entirely new JDBC driver.

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

About 10 days ago I set out to fix the current driver's support for composi= te and array objects. =C2=A0Currently they are only ever retrieved as strin= g encoding due to the use of the TEXT format for those types; parsing these= encoded strings seemed just short of a nightmare. =C2=A0Ambition got the b= etter 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. =C2= =A0=C2=A0Once that was working well, my mission was to rework this into the= current driver. =C2=A0This proved almost impossible due to 1) my limited f= amiliarity with the code and 2) the assumptions it makes about the formats = of things like parameters. =C2=A0In the end it seemed too time consuming fo= r ME to do this. =C2=A0So, 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 que= ries and retrieving data. =C2=A0Basically it's just a side project, of a re= tro-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 one= s like numerics, timestamps, dates)
* Can decode any recognized type to a Java object (this includes any imagin= able composite or array type)
* Connection.setTypeMap and ResultSet.get(int idx, Map) are both fully supp= orted
* Requests for composite objects that have no custom mapping are returned a= s 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 t= iny 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 message= s 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 b= e 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 an= d Array types. =C2=A0To accomplish this I download "pg_type", &qu= ot;pg_attribute" and "pg_proc" to the client upon connection= . =C2=A0I then create a type registry that holds all the required details o= f all the types. =C2=A0Procedures, 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". =C2=A0When a Dat= aRow message is received it looks up the type in the registry and calls the= appropriate TEXT or BINARY decoder to decode the row. =C2=A0When sending p= arameter 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 o= nly has some ramifications as far as type coercion and such are concerned; = currently all user initiated queries use the Extended Protocol & Statem= ent Describe to ensure parameter types/values are correct.

Where to go from here=E2=80=A6

The major question I would like to ask is=E2=80=A6=C2=A0

Should I continue on this path of a new driver and see if people join or sh= ould I take what I have learned and try to refit it into the current code?<= br>
I am no dummy. =C2=A0I understand the years of experience the current drive= r has to ensure it works well in an extremely large number of cases. =C2=A0= At the same time, anybody who has peeked around in there (and I have done q= uite a bit of it) knows its showing its age. =C2=A0=C2=A0My driver is 100% = new code=E2=80=A6 not a stitch of the old was used. =C2=A0Give this, it see= ms like transplanting my new "core" into the current project woul= d be like giving it a brain transplant just after a fresh head transplant; = in other words=E2=80=A6 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=E2=80=A6

Here is the GitHub project=E2=80=A6 =C2=A0https://github.com/kdubb/pgjdbc-ng

Kevin
=C2=A0
Coolio!! Can't wait to see what happens next. It's often fresh, ambiti= ous, work like this which brings the world forward.
=C2=A0
--
Andreas Joseph Krogh <andreak@officenet.no>=C2=A0 =C2=A0 =C2=A0 mob: = +47 909 56 963
Senior Software Developer / CTO - OfficeNet AS - http://www.officenet.no
Public key: http://home.officenet.no/~andreak/public_key.asc
=C2=A0
=