Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Kalyan.

Asked: August 05, 2016 - 4:14 am UTC

Last updated: August 15, 2016 - 8:54 am UTC

Version: 11.2.0.2.7

Viewed 1000+ times

You Asked

Hi Tom,

We have an issue with one of our select queries. The query returns in-consistent results (at times) for the same input.

The query is fired from a Web Application (named PIPES) using JDBC templates (Spring). A Transaction is created for the Select query.

Query and Table (ACCOUNT) details given below

SELECT channel_account_id "existingAccountId" FROM PIPESSCHEMA.ACCOUNT WHERE mac = 'xxxx'

We are pretty sure that at the time of the 'select' query for a given 'mac', there is no INSERT or DELETE happening for the same 'mac'.The code has been reviewed multiple times.

100 percent sure that there are no inserts/deletes happening.All Logs have been turned on.The issue could not be replicated in Testing environments.It happens only in Production and that too intermittently.FYI- The testing environments Databases have only one schema, whereas the PROD database, which cates to multiple Web Apps has multiple schemas (and there is a Table by the name ACCOUNT in more than one schema)

I am pasting below the snippet from the Production Logs. At 5.12 PM the query returned 9 Account IDs for the 'mac' 32641870. At 5.19 PM in a span of 7 minutes, the same query returned only 1 Account-id. No inserts or deletes have happened during that time.

Session -1 : 2016-06-29 17:12:45+1000,295 log_level=DEBUG, event_source=UpdateAccountsTable Accounts from DB for Mac 32641870 in Thread 672 is [COR000174227-182182-AU-AUD, COR000111559-182182-AU-AUD, COR000111567-182182-AU-AUD, CRD53b432ce5db8cf2022c584b4295e64ec6dbde9d6-646a2ae9d23b6ba91168e4ff7fd26978, CSH000123796203, COR000184226-182182-AU-AUD, COR000184564-182182-AU-AUD, COR000184622-182182-AU-AUD, COR000184630-182182-AU-AUD, COR000184820-182182-AU-AUD]

Session -2: 2016-06-29 17:19:32+1000,900 log_level=DEBUG, event_source=UpdateAccountsTable, Accounts from DB for 32641870 in Thread 503 is [CRD53b432ce5db8cf2022c584b4295e64ec6dbde9d6-646a2ae9d23b6ba91168e4ff7fd26978]


Both Session-1 and Session-2 create a Transaction and execute the same query which is

SELECT channel_account_id "existingAccountId" FROM schema.ACCOUNT
WHERE mac = :mac

The 'mac' is 32641870.

Session-1 and Session-2 do not insert/delete . They just do a 'Select'. There are no jobs running in the Database that removes/adds Accounts.


There are no deletes/inserts happening for the 'mac' by another session between session-1 and session-2. We have verified this by adequate placing Log-Debug statements. Exhaustive code-review was also done and this has been ruled out.


There are multiple schemas in the same Database and all of them have a Table named - ACCOUNT. We have added the schema name (PIPES) to the query but the issue still persists.

Is this an oracle related issue. A thread pointing to a similar issue is in the below link. Please have a look

http://oracle.ittoolbox.com/groups/technical-functional/oracle-db-l/has-anyone-seen-oracle-return-a-different-result-set-when-the-same-query-is-run-multiple-times-4083907


ACCOUNT TABLE

'CREATE TABLE ACCOUNT
(
ID NUMBER NOT NULL,
CHANNEL_ACCOUNT_ID VARCHAR2(100) NOT NULL,
ACCOUNT_ID VARCHAR2(100) NOT NULL,
SYSTEM_CODE CHAR(3) NOT NULL,
MAC VARCHAR2(16) NOT NULL,
ACCOUNT_NUMBER VARCHAR2(64),
ACCOUNT_SHORT_NAME VARCHAR2(64),
ACCOUNT_NAME VARCHAR2(120),
BSB_CODE VARCHAR2(20),
BILLER_CODE VARCHAR2(20),
PRODUCT_TYPE VARCHAR2(30),
ACCESS_LEVEL VARCHAR2(30),
CONSTRAINT ACCOUNT_PK PRIMARY KEY (ID) using index tablespace USER_INDEX,
CONSTRAINT ACCOUNT_UK1 UNIQUE (CHANNEL_ACCOUNT_ID, MAC)
)'

Request your assistance.

Please let me know if more information is needed

Thanks,
Kalyan



and Chris said...

It's pretty much impossible for us to tell you why you're getting "inconsistent" results in cases like this. There's just too much we don't know about your system.

Unless you can provide a test case that is!

We can suggest some things to help you narrow down the issue though. The first step is ensuring you have good logging. It looks like you already have this in place.

So you could also investigate:

- Enabling fine-grained auditing. This will tell you if there is DML you weren't expecting. e.g. from another app, job, etc.

http://www.oracle.com/technetwork/database/security/index-083815.html
https://oracle-base.com/articles/10g/auditing-10gr2

- Enabling flashback data archive. Using this you at see what was in the table at a point in time. And all the changes between two times.

http://www.oracle.com/technetwork/issue-archive/2008/08-jul/flashback-data-archive-whitepaper-129145.pdf
https://oracle-base.com/articles/12c/flashback-data-archive-fda-enhancements-12cr1

This is included in the EE license from 11.2.0.4. You need to license it separately before that.

The combination of these two should help you zero in on why you're getting results you don't expect.

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Kalyan Ramachandran, August 25, 2016 - 10:43 pm UTC

Thanks for the suggestions. Got a DBA assigned. Will check the happenings in the DB and let you know.