Issue Details (XML | Word | Printable)

Key: DERBY-1894
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Yip Ng
Reporter: Yip Ng
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Derby

SQLSTATE 42X10 occurs when qualifying a column with a synonym in ORDER BY clause

Created: 27/Sep/06 08:29 PM   Updated: 13/Dec/07 09:05 AM
Return to search
Component/s: SQL
Affects Version/s: 10.1.3.1, 10.2.1.6, 10.2.2.0, 10.3.1.4
Fix Version/s: 10.1.3.2, 10.2.2.0, 10.3.1.4

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works derby1894-trunk-diff01.txt 2006-09-28 10:59 PM Yip Ng 12 kB
Text File Licensed for inclusion in ASF works derby1894-trunk-diff02.txt 2006-10-02 06:37 PM Yip Ng 12 kB
Text File Licensed for inclusion in ASF works derby1894-trunk-stat01.txt 2006-09-28 10:59 PM Yip Ng 0.3 kB
Text File Licensed for inclusion in ASF works derby1894-trunk-stat02.txt 2006-10-02 06:37 PM Yip Ng 0.3 kB
Environment: Any

Issue & fix info: Patch Available
Resolution Date: 06/Oct/06 04:56 PM


 Description  « Hide
SQLSTATE 42X10 occurs when qualifying a column with a synonym in ORDER BY clause, where the synonym was declared in a different schema:

ij version 10.3
ij> connect 'jdbc:derby:wombat;create=true';
ij> create schema test1;
0 rows inserted/updated/deleted
ij> create schema test2;
0 rows inserted/updated/deleted
ij> create table test1.testtable(id bigint not null);
0 rows inserted/updated/deleted
ij> create synonym test2.testtable for test1.testtable;
0 rows inserted/updated/deleted
ij> set schema test1;
0 rows inserted/updated/deleted
ij> select testtable.id from testtable;
ID
--------------------

0 rows selected
ij> set schema test2;
0 rows inserted/updated/deleted
ij> select testtable.id from testtable;
ID
--------------------

0 rows selected
ij> select testtable.id from testtable order by testtable.id;
ERROR 42X10: 'TESTTABLE' is not an exposed table name in the scope in which it appears.
ij>

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Yip Ng made changes - 27/Sep/06 10:21 PM
Field Original Value New Value
Assignee Yip Ng [ yipng ]
Yip Ng made changes - 28/Sep/06 06:24 PM
Status Open [ 1 ] In Progress [ 3 ]
Yip Ng added a comment - 28/Sep/06 10:59 PM
Attaching patch derby1894-trunk-diff01.txt for DERBY-1894. The fix is in FromBaseTable's getFromTableByName() method, where it is using the
resolved synonym table name to do the binding for ORDER BY column.
Patch includes additional tests and derbyall passes. Appreciate if someone
can review it. Thanks.

Yip Ng made changes - 28/Sep/06 10:59 PM
Attachment derby1894-trunk-diff01.txt [ 12341937 ]
Attachment derby1894-trunk-stat01.txt [ 12341936 ]
Yip Ng made changes - 28/Sep/06 11:00 PM
Derby Info [Patch Available]
Mamta A. Satoor added a comment - 02/Oct/06 06:03 PM
Yip, I reviewed the code and it looks good to me. For the tests, should we have a test case where a correlation name is used in order by? May be there is already such a test or may be this test will not test the changes you made but here is a test case based on the sql script included in this Jira entry
set schema test2;
select testtable.id as c1 from testtable order by c1;

Yip Ng added a comment - 02/Oct/06 06:37 PM
Thanks for reviewing the patch, Mamta. I added a couple more testcases this week and also included your suggested testcase. Attaching derby1894-trunk-diff02.txt.

Yip Ng made changes - 02/Oct/06 06:37 PM
Attachment derby1894-trunk-diff02.txt [ 12342124 ]
Attachment derby1894-trunk-stat02.txt [ 12342123 ]
Mamta A. Satoor added a comment - 02/Oct/06 07:48 PM
Yip, I have a feeling that I missing something obvious here but why should following statement (towards the end of the tests that you added) fail?
select t1.id as c1 from t1 where c1 > 0 order by c1;

Yip Ng added a comment - 02/Oct/06 08:40 PM
Good question, Mamta. This is actually not related to synonym. If you do issue the query not using synonym below, it will also fail in Derby.

select t1.id as c1 from t1 where c1 > 0 order by c1;

One reason is the derived column can be an aggregate function, such as count(*), which can be aliased.

select count(t1.id) as cnt from t1 where cnt > 1;

This is illegal, since where clause semantics does not allow this.

Mamta A. Satoor added a comment - 02/Oct/06 08:54 PM
Thanks, Yip. I have no more questions on the patch and I give it a +1.

Repository Revision Date User Message
ASF #452259 Mon Oct 02 23:23:04 UTC 2006 mikem DERBY-1894
contributed by Yip Ng
patch: derby1894-trunk-diff02.txt

The fix is in FromBaseTable's getFromTableByName() method, where it is using
the resolved synonym table name to do the binding for ORDER BY column.
Patch includes additional tests.
Files Changed
MODIFY /db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromBaseTable.java
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/synonym.sql
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/synonym.out

Mike Matrigali added a comment - 02/Oct/06 11:24 PM
committed to trunk:

m3_ibm142:172>svn commit

Sending java\engine\org\apache\derby\impl\sql\compile\FromBaseTable.java
Sending java\testing\org\apache\derbyTesting\functionTests\master\synonym
.out
Sending java\testing\org\apache\derbyTesting\functionTests\tests\lang\syn
onym.sql
Transmitting file data ...
Committed revision 452259.

Mike Matrigali made changes - 02/Oct/06 11:24 PM
Fix Version/s 10.3.0.0 [ 12310800 ]
Repository Revision Date User Message
ASF #452269 Mon Oct 02 23:57:18 UTC 2006 mikem DERBY-1894
contributed by Yip Ng
merging from trunk to 10.1 branch.

The fix is in FromBaseTable's getFromTableByName() method, where it is using
the resolved synonym table name to do the binding for ORDER BY column.
Patch includes additional tests.
Files Changed
MODIFY /db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/compile/FromBaseTable.java
MODIFY /db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/synonym.sql
MODIFY /db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/synonym.out

Mike Matrigali added a comment - 02/Oct/06 11:58 PM
merged from trunk to 10.1 branch:
m101_142:12>svn commit

Sending java\engine\org\apache\derby\impl\sql\compile\FromBaseTable.java
Sending java\testing\org\apache\derbyTesting\functionTests\master\synonym
.out
Sending java\testing\org\apache\derbyTesting\functionTests\tests\lang\syn
onym.sql
Transmitting file data ...
Committed revision 452269.

Mike Matrigali made changes - 02/Oct/06 11:58 PM
Fix Version/s 10.1.3.2 [ 12311972 ]
Repository Revision Date User Message
ASF #453306 Thu Oct 05 18:24:19 UTC 2006 mikem DERBY-1894
contributed by Yip Ng
merging from trunk to 10.2 branch.

The fix is in FromBaseTable's getFromTableByName() method, where it is using
the resolved synonym table name to do the binding for ORDER BY column.
Patch includes additional tests.
Files Changed
MODIFY /db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/compile/FromBaseTable.java
MODIFY /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/lang/synonym.sql
MODIFY /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/master/synonym.out

Mike Matrigali added a comment - 05/Oct/06 06:28 PM
backported fix from trunk to 10.2.1.7 (version does not exist in jira right now - so marked fixed in 10.2.2)

Mike Matrigali made changes - 05/Oct/06 06:28 PM
Fix Version/s 10.2.2.0 [ 12312027 ]
Mike Matrigali added a comment - 06/Oct/06 04:56 PM
fix has made it to trunk, 10.2 branch and 10.1 branch

Mike Matrigali made changes - 06/Oct/06 04:56 PM
Status In Progress [ 3 ] Resolved [ 5 ]
Resolution Fixed [ 1 ]
Andrew McIntyre added a comment - 13/Dec/07 09:05 AM
This issue has been resolved for over a year with no further movement. Closing.

Andrew McIntyre made changes - 13/Dec/07 09:05 AM
Status Resolved [ 5 ] Closed [ 6 ]