This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 232075 - [74cat] Total row count incorrect
Summary: [74cat] Total row count incorrect
Status: RESOLVED FIXED
Alias: None
Product: db
Classification: Unclassified
Component: Code (show other bugs)
Version: 7.4
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Jiri Rechtacek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-07-01 12:06 UTC by bolsover
Modified: 2013-07-03 02:29 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
screen grab (76.25 KB, image/jpeg)
2013-07-01 12:06 UTC, bolsover
Details

Note You need to log in before you can comment on or make changes to this bug.
Description bolsover 2013-07-01 12:06:28 UTC
Created attachment 136535 [details]
screen grab

Product Version: NetBeans IDE Dev (Build 201306242301)
Java: 1.7.0_25; Java HotSpot(TM) 64-Bit Server VM 23.25-b01
Runtime: Java(TM) SE Runtime Environment 1.7.0_25-b16
System: Windows 7 version 6.1 running on amd64; Cp1252; en_GB (nb)

Running the following query against a PervasiveSQL database returns the correct results - but the Total row count is displayed incorrectly: (See screen grab)

select 
count(act.ACTION_ID) actcount, 
ncr.ncr_id, ncr.RAISED_DATE, ncr.COMPLETE, rca.rc_id, rca.DATE_OPEN, rca.DATE_DUE, rca.COMPLETE,  ca.ca_id, ca.DATE_OPEN, ca.DATE_DUE, ca.COMPLETE 
from Ot_ncr ncr 
left outer join Ot_ncr_action act on ncr.NCR_ID = act.NCR_ID
left outer join Ot_ncr_root_cause rca on ncr.NCR_ID = rca.NCR_ID 
left outer join Ot_ncr_ca ca on rca.CA_ID = ca.CA_ID
group by ncr.ncr_id, ncr.RAISED_DATE, ncr.COMPLETE, rca.rc_id, rca.DATE_OPEN, rca.DATE_DUE, rca.COMPLETE,  ca.ca_id, ca.DATE_OPEN, ca.DATE_DUE, ca.COMPLETE;

Modification to the query (removing count group by clause) returns the correct row count:
select 
--count(act.ACTION_ID) actcount, 
ncr.ncr_id, ncr.RAISED_DATE, ncr.COMPLETE, rca.rc_id, rca.DATE_OPEN, rca.DATE_DUE, rca.COMPLETE,  ca.ca_id, ca.DATE_OPEN, ca.DATE_DUE, ca.COMPLETE 
from Ot_ncr ncr 
left outer join Ot_ncr_action act on ncr.NCR_ID = act.NCR_ID
left outer join Ot_ncr_root_cause rca on ncr.NCR_ID = rca.NCR_ID 
left outer join Ot_ncr_ca ca on rca.CA_ID = ca.CA_ID
--group by ncr.ncr_id, ncr.RAISED_DATE, ncr.COMPLETE, rca.rc_id, rca.DATE_OPEN, rca.DATE_DUE, rca.COMPLETE,  ca.ca_id, ca.DATE_OPEN, ca.DATE_DUE, ca.COMPLETE;

I will test further against other database to see if I can reproduce the issue.

db
Comment 1 Jaroslav Havlin 2013-07-01 13:38:20 UTC
Database support module uses this query to get total row count:
select count(*) from (enteredQuery) C2668;

In this case:

select count(*) from (
select 
count(act.ACTION_ID) actcount, 
ncr.ncr_id, ncr.RAISED_DATE, ncr.COMPLETE, rca.rc_id, rca.DATE_OPEN,
rca.DATE_DUE, rca.COMPLETE,  ca.ca_id, ca.DATE_OPEN, ca.DATE_DUE, ca.COMPLETE 
from Ot_ncr ncr 
left outer join Ot_ncr_action act on ncr.NCR_ID = act.NCR_ID
left outer join Ot_ncr_root_cause rca on ncr.NCR_ID = rca.NCR_ID 
left outer join Ot_ncr_ca ca on rca.CA_ID = ca.CA_ID
group by ncr.ncr_id, ncr.RAISED_DATE, ncr.COMPLETE, rca.rc_id, rca.DATE_OPEN,
rca.DATE_DUE, rca.COMPLETE,  ca.ca_id, ca.DATE_OPEN, ca.DATE_DUE, ca.COMPLETE;
) C2668;

Please, try to execute this query and check whether the result is correct.
Thank you in advance.
Comment 2 bolsover 2013-07-01 19:01:37 UTC
The query:
select count(*) from (
select
count(act.ACTION_ID) actcount,
ncr.ncr_id, ncr.RAISED_DATE, ncr.COMPLETE, rca.rc_id, rca.DATE_OPEN, rca.DATE_DUE, rca.COMPLETE,  ca.ca_id, ca.DATE_OPEN, ca.DATE_DUE, ca.COMPLETE 
from Ot_ncr ncr 
left outer join Ot_ncr_action act on ncr.NCR_ID = act.NCR_ID 
left outer join Ot_ncr_root_cause rca on ncr.NCR_ID = rca.NCR_ID 
left outer join Ot_ncr_ca ca on rca.CA_ID = ca.CA_ID 
group by ncr.ncr_id, ncr.RAISED_DATE, ncr.COMPLETE, rca.rc_id, rca.DATE_OPEN, rca.DATE_DUE, rca.COMPLETE,  ca.ca_id, ca.DATE_OPEN, ca.DATE_DUE, ca.COMPLETE;
) C2668;

Causes an SQL error:
Error code 0, SQL state 37000: [Pervasive][ODBC Engine Interface]Syntax Error: er join Ot_ncr_ca ca on rca.CA_ID = ca.CA_ID 
group by ncr.ncr_id, ncr.RAISED_DATE, ncr.COMPLETE, rca.rc_id, rca.DATE_OPEN, rca.DATE_DUE, rca.COMPLETE,  ca.ca_id, ca.DATE_OPEN, ca.DATE_DUE, ca.COMPLET<< ??? 
Line 3, column 1

Error code 0, SQL state 37000: [LNA][Pervasive][ODBC Engine Interface]Syntax Error: << ??? >>)
Line 11, column 1

So - It seems that this is an issue of the generated SQL not being supported by the pervasive SQL dialect.
Comment 3 matthias42 2013-07-01 19:07:55 UTC
(In reply to comment #2)
> So - It seems that this is an issue of the generated SQL not being supported by
> the pervasive SQL dialect.

The parser is right - it is incorrect - please try this:

--------------------------

select count(*) from (
select 
count(act.ACTION_ID) actcount, 
ncr.ncr_id, ncr.RAISED_DATE, ncr.COMPLETE, rca.rc_id, rca.DATE_OPEN,
rca.DATE_DUE, rca.COMPLETE,  ca.ca_id, ca.DATE_OPEN, ca.DATE_DUE, ca.COMPLETE 
from Ot_ncr ncr 
left outer join Ot_ncr_action act on ncr.NCR_ID = act.NCR_ID
left outer join Ot_ncr_root_cause rca on ncr.NCR_ID = rca.NCR_ID 
left outer join Ot_ncr_ca ca on rca.CA_ID = ca.CA_ID
group by ncr.ncr_id, ncr.RAISED_DATE, ncr.COMPLETE, rca.rc_id, rca.DATE_OPEN,
rca.DATE_DUE, rca.COMPLETE,  ca.ca_id, ca.DATE_OPEN, ca.DATE_DUE, ca.COMPLETE
) C2668;

--------------------------

Notice the missing semi-colon in the last row of the inner query (the mentioned eleventh line).
Comment 4 bolsover 2013-07-01 19:11:53 UTC
Ah - I thought the ';' might be out of place - I already tried 

select count(*) from (
select
count(act.ACTION_ID) actcount,
ncr.ncr_id, ncr.RAISED_DATE, ncr.COMPLETE, rca.rc_id, rca.DATE_OPEN, rca.DATE_DUE, rca.COMPLETE,  ca.ca_id, ca.DATE_OPEN, ca.DATE_DUE, ca.COMPLETE 
from Ot_ncr ncr left outer join Ot_ncr_action act on ncr.NCR_ID = act.NCR_ID 
left outer join Ot_ncr_root_cause rca on ncr.NCR_ID = rca.NCR_ID 
left outer join Ot_ncr_ca ca on rca.CA_ID = ca.CA_ID 
group by ncr.ncr_id, ncr.RAISED_DATE, ncr.COMPLETE, rca.rc_id, rca.DATE_OPEN, rca.DATE_DUE, rca.COMPLETE,  ca.ca_id, ca.DATE_OPEN, ca.DATE_DUE, ca.COMPLETE
) C2668;  

This time I get a different error:

Error code 0, SQL state S0021: [LNA][Pervasive][ODBC Engine Interface]Column names in each view must be unique.

I'm reading through the pervasiveSQL (V10) documentation - but have not yet found a solution..
Comment 5 bolsover 2013-07-01 19:28:06 UTC
If I modify the query as:

select count(*) from (
select count(act.ACTION_ID) as actcount, count(conc.CONCESSION_ID) as conccount,  ncr.ncr_id as ncr_ncr_id, ncr.raised_date as ncr_raised_date, ncr.complete as ncr_complete, rca.rc_id as rca_rc_id, rca.date_open as rca_date_open, rca.date_due as rca_date_due, rca.complete as rca_complete,  ca.ca_id, ca.date_open as ca_date_open, ca.date_due as ca_date_due, ca.complete as ca_complete  from Ot_ncr ncr  left outer join Ot_ncr_action act on ncr.NCR_ID = act.NCR_ID left outer join Ot_ncr_concession conc on act.CONCESSION_ID = conc.CONCESSION_ID left outer join Ot_ncr_root_cause rca on ncr.NCR_ID = rca.NCR_ID  left outer join Ot_ncr_ca ca on rca.CA_ID = ca.CA_ID group by ncr.ncr_id, ncr.RAISED_DATE, ncr.COMPLETE, rca.rc_id, rca.DATE_OPEN, rca.DATE_DUE, rca.COMPLETE,  ca.ca_id, ca.DATE_OPEN, ca.DATE_DUE, ca.COMPLETE
) C2668;

I get valid SQL and correct result (63)
Comment 6 bolsover 2013-07-01 19:31:28 UTC
Sorry for confusion - I added an extra table in the last query - but it does not matter - the solution is to add the field alias names - but I guess that could be tricky in the NB query parser.
Comment 7 Jaroslav Havlin 2013-07-02 08:13:14 UTC
(In reply to comment #3)
> The parser is right - it is incorrect - please try this:
> [...]
> Notice the missing semi-colon [...]
I'm sorry, my fault. Thank you, Matthias, for correcting me.

It's quite valid to show that total count cannot be computed, but in this case total count is 1, which is incorrect.

The problem is that if the the query "select count(*) from (<original query>)" fails, another query, "select count(*) from <part of the original query after FROM>" is used, but only if it contains no "GROUP BY" statement.
In this case, "GROUP BY" wasn't detected, and the query was used despite risk of incorrect result.
Fixed here: http://hg.netbeans.org/core-main/rev/06f0fbe9e4ac

(In reply to comment #6)
> Sorry for confusion - I added an extra table in the last query - but it does
> not matter - the solution is to add the field alias names - but I guess that
> could be tricky in the NB query parser.
Yes, that would need full SQL parser, and it it would still leave some uncovered cases. So, just showing N/A should be acceptable, I hope.

Thank you very much for reporting and for your help.
Comment 8 Quality Engineering 2013-07-03 02:29:56 UTC
Integrated into 'main-silver', will be available in build *201307022300* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/06f0fbe9e4ac
User: Jaroslav Havlin <jhavlin@netbeans.org>
Log: #232075: Total row count incorrect