X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 3EB6D3A4570 for ; Mon, 1 Nov 2004 14:39:35 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 40009-09 for ; Mon, 1 Nov 2004 14:39:25 +0000 (GMT) Received: from ms-dienst.rz.rwth-aachen.de (ms-1.rz.RWTH-Aachen.DE [134.130.3.130]) by svr1.postgresql.org (Postfix) with ESMTP id 183A73A3C17 for ; Mon, 1 Nov 2004 14:39:27 +0000 (GMT) Received: from r220-1 (r220-1.rz.RWTH-Aachen.DE [134.130.3.31]) by ms-dienst.rz.rwth-aachen.de (iPlanet Messaging Server 5.2 HotFix 1.12 (built Feb 13 2003)) with ESMTP id <0I6I0096J8PRQT@ms-dienst.rz.rwth-aachen.de> for pgsql-jdbc@postgresql.org; Mon, 01 Nov 2004 15:39:28 +0100 (MET) Received: from relay.rwth-aachen.de ([134.130.3.1]) by r220-1 (MailMonitor for SMTP v1.2.2 ) ; Mon, 01 Nov 2004 15:39:26 +0100 (MET) Received: from post.halifax.rwth-aachen.de (post.halifax.RWTH-Aachen.DE [134.130.49.251]) by relay.rwth-aachen.de (8.13.0/8.13.0/1) with ESMTP id iA1EdQOH010752 for ; Mon, 01 Nov 2004 15:39:26 +0100 (MET) Received: (qmail 14553 invoked from network); Mon, 01 Nov 2004 14:39:31 +0000 Received: from darkenemy.halifax.rwth-aachen.de ([134.130.48.36]) (envelope-sender ) by mail.halifax.rwth-aachen.de (qmail-ldap-1.03) with SMTP for ; Mon, 01 Nov 2004 14:39:31 +0000 Date: Mon, 01 Nov 2004 15:39:24 +0100 From: Ulrich Meis Subject: Re: General Parser In-reply-to: <41861A10.1000607@opencloud.com> To: Oliver Jowett Cc: pgsql-jdbc@postgresql.org Message-id: <200411011539.24508.kenobi@halifax.rwth-aachen.de> MIME-version: 1.0 Content-type: text/plain; charset=iso-8859-1 Content-transfer-encoding: 7BIT Content-disposition: inline User-Agent: KMail/1.7 References: <200411010341.28499.kenobi@halifax.rwth-aachen.de> <41861A10.1000607@opencloud.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200411/4 X-Sequence-Number: 11426 Hi Oliver! On Monday 01 November 2004 12:12, you wrote: > That said, this still needs some work as the various different callers > need different parsing done. For example, we only care about splitting > queries into multiple statements when using the V3 protocol, we only > care about ? placeholders when parsing a query supplied via > prepareStatement, the { call } syntax only makes sense for > CallableStatements, and there's no need to disassemble the SELECT etc if > the application never uses an updatable resultset. I thought about these aspects and in a first draft I splitted off the disassembly of select statements in a separate method. But finally, I merged them again because I thought the overhead would be neglectable. I never considered splitting off the others because they really only involve one char comparison per word(literals/identifiers being one word) or less. All the handling you describe above is done in the addFraction method and that is roughly called once per word. There's not a single loop so we don't add to complexity. If not neglectable in the scope of the parser itself, I would think that it is regarding the whole query execution, i.e. parsing,data conversion, sending the query, the backend handling the query, receiving the results, data conversion. If you have an application that fires tons of queries that the backend needs almost no time to execute for, then those queries are likely to be very short. In that case parsing is quite quickly, too. The cases in detail: As said, all this happens once per word: 1. Splitting multiple statements. if (first == SEMICOLON) {....} That char comparison is all the overhead if it's a single query only. Maybe it would even be nice to be able to throw an exception if multiple queries are used in V2? 2. ? placeholders if (first == QUESTIONMARK) {...} As above. 3. call syntax if (first == QUESTIONMARK) {...} if (fraction.equalsIgnoreCase("call")) {...} Those two comparisons are only done on the first word in a Java Escape and otherwise never executed! 4. select statement disassembly This is the only case I would consider to split off although I think it's not necessary. The whole section is completely ignored if the following holds true, i.e. it's not a select statement and/or we already know it's not to a single table: if (querytype == NONSINGLE) break; Otherwise, we have on average less than one string comparison per word. > I'm not sure how easy it will be to have a single flexible parser and > still have low overhead for the cases where we don't want to completely > disassemble the query. Most of the overhead here comes from determining the tableName for an updatable ResultSet. I can easily move that handling into a separate method. In that case, I would make the parser keep the fractions ArrayList, so that when the table name is actually needed in a ResultSet, the parsing can be done real quick. Tell me if you prefer it that way and I'll do it. I would really recommend to keep the other handling where it is, I don't think it is neccessary to complicate things here. But tell me if I'm wrong. Regards, Uli