You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by Daniel John Debrunner <dj...@debrunners.com> on 2005/01/04 21:06:06 UTC

Re: (DERBY-13) Quoted names with embedded period mishandled in from

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Comments on the patch 'Derby-13.diff' attached to the Jira bug Derby-13

I think we are making progress, but some comments:

- - How do you (or someone else) know the bug is fixed if there are no
test cases added for it?

- - I would expect a more complete change to use TableName, rather than
String for exposed name. That is, an exposed name is always handled as a
TableName and not a string. Your approach is to keep the exposed name as
a String and convert it to a TableName as required. I think it will be a
lot cleaner if it is always a TableName and never a String. Ie.
getExposedName() returns a TableName.
I think your code then leads to a problem, where the schema name for an
exposed name is incorrect, as you take the schema name of the table, not
the current schema. Though I could be wrong on this. Namely in this
situation, what is the actual value for the exposed (correlation) name?

set current schema A;

select * from B.T1 AS C


What is the correlation name

  C (no associated schema?)
  A.C
  B.C

??

I briefly looked through the SQL spec a while ago on this issue and
couldn't find the answer.

Dan.


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFB2vcuIv0S4qsbfuQRAh89AKC833wihGxL+9Dl0Ez0WRPgEIwobgCgiUkk
e3gpw1RQQpembWsgOGy6sfA=
=OEii
-----END PGP SIGNATURE-----


Re: (DERBY-13) Quoted names with embedded period mishandled in from

Posted by Shreyas Kaushik <Sh...@Sun.COM>.
 My answers inline.


Daniel John Debrunner wrote:

>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>Shreyas Kaushik wrote:
>
>  
>
>>Yes it does.
>>
>>Daniel John Debrunner wrote:
>>
>>    
>>
>>>Does the fix correctly implement duplicate name checking as detailed in
>>>this mail?
>>>
>>>http://mail-archives.apache.org/eyebrowse/ReadMsg?listName=derby-dev@db.apache.org&msgNo=1569
>>>      
>>>
>
>Hmmm, I don't see how the change in FromList (extracted below) will
>correctly handle
>
>select ... FROM A.T1 as C, B.T2 as C
>
>It seems that the leftTable variable will be set to <A.C> and rightTable
>set to <B.C> which will not compare as equal. Am I missing something? If
>the patch had tests I could see if this case was handled.
>  
>
So if I understand you correctly the SQL statement of the above format 
should give an error.
That being the case it does take care of this case, giving the error as 
shown below:

ij> select * from app."S1.T1" as C, s1.t1 as C;
ERROR 42X09: The table or alias name 'C' is used more than once in the 
FROM list.

>The code in FromList is not that clear to me, could be helped by
>comments, and it concerns me that a TableName object is created out of a
>schema name and a correlation name when such a construct has no valid
>meaning. I see that you are hampered by the fact that there is no way to
>tell if a correlation name has been used. In msgNo 1569 I laid out that
>it would be best if there were two getExposed methods, but now I think a
>single String getExposedName() will do, as long as it returns null if no
>correlation name was used. That might have a ripple effect though the
>code, but the best way to fix a bug is sometimes a minor rework, rather
>than just band-aids on existing bad code. I think the fact that exposed
>name handling has three bugs shows a re-work is needed. In any re-work I
>would start out with explicitly stating how exposed names are handled
>for a table in the from list and for a column reference, and then how
>the two uses relate and compare.
>
>
>Other comments on the patch are:
>
>- - for the code extract below as a minor nit I would avoid using terms
>like 'leftTable' or 'rightTable' unless left and right actual have
>meaning, which they don't here. One table in a list is being compared
>against the others in the list.
>  
>
I can change the naming for these, what could be some possible variable 
names that are suitable.

>- - The other set of changes related to getAllResultColumns() again have
>the possible issue of creating a TableName out of a schema name and
>correlation name. I assume these are to fix derby-12, again comments
>would be useful.
>  
>
I can add the comments here.

>Also any comments you have on if this fixes Derby-18 and Derby-12 would
>be helpful.
>  
>
It takes care of Derby-12.
But Derby-18 is  slightly more than what this patch tries to address.
 (Derby -18 is related to column binding when qualified with a schema name)

This patch does not fully cover Derby-18.

>Dan.
>
>- -				if (fromTable.getExposedName().equals
>- -					(((FromTable) elementAt(index)).getExposedName()) )
>+                leftTable = makeTableName(
>fromTable.getTableName().getSchemaName(),
>+
>fromTable.getExposedName());
>+
>+                if(((FromTable) elementAt(index)).getTableName() == null) {
>+                     rightTable =  makeTableName(null, ((FromTable)
>elementAt(index)).getExposedName());
>+                }
>+
>+                else {
>+                    rightTable = makeTableName(((FromTable)
>elementAt(index)).getTableName().getSchemaName(),
>+                                                ((FromTable)
>elementAt(index)).getExposedName());
>+                }
>+                if(leftTable.equals(rightTable))
> 				{
> 					throw
>StandardException.newException(SQLState.LANG_FROM_LIST_DUPLICATE_TABLE_NAME,
>fromTable.getExposedName());
> 				}
>
>-----BEGIN PGP SIGNATURE-----
>Version: GnuPG v1.2.5 (MingW32)
>Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
>iD8DBQFB44TBIv0S4qsbfuQRAjgCAKC7xhogSSJgQS3YeGVLxiM3ePdBmgCgqGd2
>jRQZ5MXv5Z6nti9/r5iwQDo=
>=FFKt
>-----END PGP SIGNATURE-----
>
>  
>


Re: (DERBY-13) Quoted names with embedded period mishandled in from

Posted by Daniel John Debrunner <dj...@debrunners.com>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Shreyas & I worked through his Derby-13 patch off this list to come to a
conclusion. The summary of that discussion is:


- - I had misunderstood that FromTable.getTableName() already handled the
correlation name, return a TableName of <null,correlationName> in that
case. I had thought that it returned the underlying actual table name.
Once Shreyas pointed that out I started to understand his fix. I do
think that beyond this patch there is some cleanup in this area as if
getTableName() encapsulates exposed name handling, then there should be
no need for any public getExposedName methods.

- - I then questioned when FromTable.getTableName() could return null as
Shreyas was checking for it in the changes in FromList. He re-ran the
tests without the check and hit an exception in lojreorder.sql. Looking
at that I pointed out that the correct check would be if the FromTable
is an instanceof TableOperatorNode, which would map the existing check.

- - and the final change was to not re-build TableName objects in the
FromList duplicate exposed name checking, but use the objects directly
from FromList.getTableName() as TableName objects are re-useable

- - Shreyas also provided some test cases which I added to the existing
select.sql test.

- - I also removed the modifications to TableName from the patch as they
were only cosmetic.


I will commit this tomorrow if there are no other review comments on the
patch.

Dan.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFB8EOcIv0S4qsbfuQRAiYFAJ9ytZTHpNjmJp3qLfSKa0oGh6iWVwCfa5td
fW5smzisdhTyfo6Orl1fbS0=
=h8qk
-----END PGP SIGNATURE-----

Re: (DERBY-13) Quoted names with embedded period mishandled in from

Posted by Daniel John Debrunner <dj...@debrunners.com>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Shreyas Kaushik wrote:

> Yes it does.
>
> Daniel John Debrunner wrote:
>
>>
>>Does the fix correctly implement duplicate name checking as detailed in
>>this mail?
>>
>>http://mail-archives.apache.org/eyebrowse/ReadMsg?listName=derby-dev@db.apache.org&msgNo=1569

Hmmm, I don't see how the change in FromList (extracted below) will
correctly handle

select ... FROM A.T1 as C, B.T2 as C

It seems that the leftTable variable will be set to <A.C> and rightTable
set to <B.C> which will not compare as equal. Am I missing something? If
the patch had tests I could see if this case was handled.

The code in FromList is not that clear to me, could be helped by
comments, and it concerns me that a TableName object is created out of a
schema name and a correlation name when such a construct has no valid
meaning. I see that you are hampered by the fact that there is no way to
tell if a correlation name has been used. In msgNo 1569 I laid out that
it would be best if there were two getExposed methods, but now I think a
single String getExposedName() will do, as long as it returns null if no
correlation name was used. That might have a ripple effect though the
code, but the best way to fix a bug is sometimes a minor rework, rather
than just band-aids on existing bad code. I think the fact that exposed
name handling has three bugs shows a re-work is needed. In any re-work I
would start out with explicitly stating how exposed names are handled
for a table in the from list and for a column reference, and then how
the two uses relate and compare.


Other comments on the patch are:

- - for the code extract below as a minor nit I would avoid using terms
like 'leftTable' or 'rightTable' unless left and right actual have
meaning, which they don't here. One table in a list is being compared
against the others in the list.

- - The other set of changes related to getAllResultColumns() again have
the possible issue of creating a TableName out of a schema name and
correlation name. I assume these are to fix derby-12, again comments
would be useful.

Also any comments you have on if this fixes Derby-18 and Derby-12 would
be helpful.

Dan.

- -				if (fromTable.getExposedName().equals
- -					(((FromTable) elementAt(index)).getExposedName()) )
+                leftTable = makeTableName(
fromTable.getTableName().getSchemaName(),
+
fromTable.getExposedName());
+
+                if(((FromTable) elementAt(index)).getTableName() == null) {
+                     rightTable =  makeTableName(null, ((FromTable)
elementAt(index)).getExposedName());
+                }
+
+                else {
+                    rightTable = makeTableName(((FromTable)
elementAt(index)).getTableName().getSchemaName(),
+                                                ((FromTable)
elementAt(index)).getExposedName());
+                }
+                if(leftTable.equals(rightTable))
 				{
 					throw
StandardException.newException(SQLState.LANG_FROM_LIST_DUPLICATE_TABLE_NAME,
fromTable.getExposedName());
 				}

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFB44TBIv0S4qsbfuQRAjgCAKC7xhogSSJgQS3YeGVLxiM3ePdBmgCgqGd2
jRQZ5MXv5Z6nti9/r5iwQDo=
=FFKt
-----END PGP SIGNATURE-----


Re: (DERBY-13) Quoted names with embedded period mishandled in from

Posted by Shreyas Kaushik <Sh...@Sun.COM>.
Yes it does.

thanks
Shreyas

Daniel John Debrunner wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Shreyas Kaushik wrote:
> 
> 
>>Hi,
>>
>>  Can the patch i proposed for this be accepted? I see no activity
>>hapeening on this ( no comments apart from Amit's).
> 
> 
> Does the fix correctly implement duplicate name checking as detailed in
> this mail?
> 
> http://mail-archives.apache.org/eyebrowse/ReadMsg?listName=derby-dev@db.apache.org&msgNo=1569
> 
> 
> Dan.
> 
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.5 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> 
> iD8DBQFB4pX/Iv0S4qsbfuQRAk/yAKC/siMfqBoKLZKMqjLWFYg6oOX1aQCfQrBy
> ggCL9Vza6qooSmMtRW4qGjI=
> =TG80
> -----END PGP SIGNATURE-----
> 


Re: (DERBY-13) Quoted names with embedded period mishandled in from

Posted by Daniel John Debrunner <dj...@debrunners.com>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Shreyas Kaushik wrote:

> Hi,
>
>   Can the patch i proposed for this be accepted? I see no activity
> hapeening on this ( no comments apart from Amit's).

Does the fix correctly implement duplicate name checking as detailed in
this mail?

http://mail-archives.apache.org/eyebrowse/ReadMsg?listName=derby-dev@db.apache.org&msgNo=1569


Dan.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFB4pX/Iv0S4qsbfuQRAk/yAKC/siMfqBoKLZKMqjLWFYg6oOX1aQCfQrBy
ggCL9Vza6qooSmMtRW4qGjI=
=TG80
-----END PGP SIGNATURE-----


Re: (DERBY-13) Quoted names with embedded period mishandled in from

Posted by Shreyas Kaushik <Sh...@Sun.COM>.
Hi,

  Can the patch i proposed for this be accepted? I see no activity
hapeening on this ( no comments apart from Amit's).

thanks
Shreyas

thanks
Shreyas

Amit Handa wrote:
> Daniel John Debrunner wrote:
> 
>>-----BEGIN PGP SIGNED MESSAGE-----
>>Hash: SHA1
>>
>>I think we need to reset on Derby-13, and also look at Derby-18 at the
>>same time. I was confused over the exposed correlation name, thinking it
>>had a schema, but it doesn't.
>>
>>A table in a list either has an exposed table name or an exposed
>>correlation name. The correlation name is defined by the AS clause and
>>can not have a schema.
>>
>>Thus with
>>
>>set current schema A
>>select ... FROM T1, B.T2, T3 AS TC
>>
>>there should be three exposed names
>>
>>A.T1 as an exposed <table name>
>>B.T2 as an exposed <table name>
>>TC as an exposed <correlation name>
>>
>>The SQL standard rules are then (for table references in the same scope)
>>
>>1) No duplicates can exist among the exposed <table name>s
>>2) No duplicates can exist among the exposed <correlation name>s
>>3) Any <correlation name> must not be the same as the unqualifed part of
>>any exposed <table name>
>>
>>
>>One option in the code might be to have
>>
>>// Returns the exposed table name,
>>// returns null if the table has a correlation name
>>TableName getExposedTableName()
>>
>>// Returns the exposed correlation name,
>>// returns null if the table does not have a correlation name
>>String getExposedCorrelationName()
>>
>>Thus to keep the two concepts separate (since they are), rather than
>>trying to shoehorn them into a single value (as the current code does).
>>Then the duplicate checking would have to be smarter.
>>
> 
> 
> I get what you are saying. Note that we already have the above two methods
> in a subclass of FromTable(FromVTI.java, getExposedName() and getExposedTableName() )
> I am wondering was it intended to be that way i.e. to introduce the (above) methods
> in a subclass and not in base class. Is it by design ?
> And if we go by what is suggested we may be breaking something else.
> The subclasses will now over ride from FromTable.java insted fo FromVTI.java.
> 
> But we can always give a shot at the proposed change.
> Just my thoughts after looking at the issue.
> 
> 
>>I think this would also enable the dubious null schema handling in
>>TableName to be removed, as TableNames should always have a schema.
>>
>>Dan.
>>
>>
>>
>>
>>-----BEGIN PGP SIGNATURE-----
>>Version: GnuPG v1.2.5 (MingW32)
>>Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>>
>>iD8DBQFB3E7SIv0S4qsbfuQRAkxJAKCZUIFXnm/+zsqO1MUnqqfMEyOPNQCg5gTa
>>C/ri7UZzL80BtsaKM2gi59Y=
>>=9aTO
>>-----END PGP SIGNATURE-----
>>
> 
> 
> 
> 
> 
> 


Re: (DERBY-13) Quoted names with embedded period mishandled in from

Posted by Amit Handa <Am...@Sun.COM>.
Daniel John Debrunner wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> I think we need to reset on Derby-13, and also look at Derby-18 at the
> same time. I was confused over the exposed correlation name, thinking it
> had a schema, but it doesn't.
> 
> A table in a list either has an exposed table name or an exposed
> correlation name. The correlation name is defined by the AS clause and
> can not have a schema.
> 
> Thus with
> 
> set current schema A
> select ... FROM T1, B.T2, T3 AS TC
> 
> there should be three exposed names
> 
> A.T1 as an exposed <table name>
> B.T2 as an exposed <table name>
> TC as an exposed <correlation name>
> 
> The SQL standard rules are then (for table references in the same scope)
> 
> 1) No duplicates can exist among the exposed <table name>s
> 2) No duplicates can exist among the exposed <correlation name>s
> 3) Any <correlation name> must not be the same as the unqualifed part of
> any exposed <table name>
> 
> 
> One option in the code might be to have
> 
> // Returns the exposed table name,
> // returns null if the table has a correlation name
> TableName getExposedTableName()
> 
> // Returns the exposed correlation name,
> // returns null if the table does not have a correlation name
> String getExposedCorrelationName()
> 
> Thus to keep the two concepts separate (since they are), rather than
> trying to shoehorn them into a single value (as the current code does).
> Then the duplicate checking would have to be smarter.
> 

I get what you are saying. Note that we already have the above two methods
in a subclass of FromTable(FromVTI.java, getExposedName() and getExposedTableName() )
I am wondering was it intended to be that way i.e. to introduce the (above) methods
in a subclass and not in base class. Is it by design ?
And if we go by what is suggested we may be breaking something else.
The subclasses will now over ride from FromTable.java insted fo FromVTI.java.

But we can always give a shot at the proposed change.
Just my thoughts after looking at the issue.

> I think this would also enable the dubious null schema handling in
> TableName to be removed, as TableNames should always have a schema.
> 
> Dan.
> 
> 
> 
> 
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.5 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> 
> iD8DBQFB3E7SIv0S4qsbfuQRAkxJAKCZUIFXnm/+zsqO1MUnqqfMEyOPNQCg5gTa
> C/ri7UZzL80BtsaKM2gi59Y=
> =9aTO
> -----END PGP SIGNATURE-----
> 






Re: (DERBY-13) Quoted names with embedded period mishandled in from

Posted by Daniel John Debrunner <dj...@debrunners.com>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I think we need to reset on Derby-13, and also look at Derby-18 at the
same time. I was confused over the exposed correlation name, thinking it
had a schema, but it doesn't.

A table in a list either has an exposed table name or an exposed
correlation name. The correlation name is defined by the AS clause and
can not have a schema.

Thus with

set current schema A
select ... FROM T1, B.T2, T3 AS TC

there should be three exposed names

A.T1 as an exposed <table name>
B.T2 as an exposed <table name>
TC as an exposed <correlation name>

The SQL standard rules are then (for table references in the same scope)

1) No duplicates can exist among the exposed <table name>s
2) No duplicates can exist among the exposed <correlation name>s
3) Any <correlation name> must not be the same as the unqualifed part of
any exposed <table name>


One option in the code might be to have

// Returns the exposed table name,
// returns null if the table has a correlation name
TableName getExposedTableName()

// Returns the exposed correlation name,
// returns null if the table does not have a correlation name
String getExposedCorrelationName()

Thus to keep the two concepts separate (since they are), rather than
trying to shoehorn them into a single value (as the current code does).
Then the duplicate checking would have to be smarter.

I think this would also enable the dubious null schema handling in
TableName to be removed, as TableNames should always have a schema.

Dan.




-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFB3E7SIv0S4qsbfuQRAkxJAKCZUIFXnm/+zsqO1MUnqqfMEyOPNQCg5gTa
C/ri7UZzL80BtsaKM2gi59Y=
=9aTO
-----END PGP SIGNATURE-----


Re: (DERBY-13) Quoted names with embedded period mishandled in from

Posted by Shreyas Kaushik <Sh...@Sun.COM>.

Daniel John Debrunner wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Comments on the patch 'Derby-13.diff' attached to the Jira bug Derby-13
> 
> I think we are making progress, but some comments:
> 
> - - How do you (or someone else) know the bug is fixed if there are no
> test cases added for it?

I can give a shot at writing tests.
> 
> - - I would expect a more complete change to use TableName, rather than
> String for exposed name. That is, an exposed name is always handled as a
> TableName and not a string. Your approach is to keep the exposed name as
> a String and convert it to a TableName as required. I think it will be a
> lot cleaner if it is always a TableName and never a String. Ie.
> getExposedName() returns a TableName.

In java/engine/org/apache/derby/impl/sql/compile/CurrentOfNode.java
the exposedTableName object is built using the makeTableName method.
I feel changing the signature of the getExposedName() method would be a
much larger operation and users might not like the change as well as the
current method just returns a String and the new method would return a
TableName object.

> I think your code then leads to a problem, where the schema name for an
> exposed name is incorrect, as you take the schema name of the table, not
> the current schema. Though I could be wrong on this. Namely in this
> situation, what is the actual value for the exposed (correlation) name?
> 
> set current schema A;
> 
> select * from B.T1 AS C
> 
> 
> What is the correlation name
> 
>   C (no associated schema?)
>   A.C
>   B.C
> 
> ??

The correlation name would be "C" ( no associated schema ).

This is because for the query "select * from B.T1 AS C", "*" is not
associated with a table name, that is in the code allTableName will be
null and hence no schema is associated with C. (although the default
schema is A)
> 
> I briefly looked through the SQL spec a while ago on this issue and
> couldn't find the answer.

I agree the SQL spec does not talk about this, hence the above solution.
> 
> Dan.
> 
> 

Can all of you kindly vote for the patch ?

thanks
Shreyas