JDBC Driver shows erratic behavior when filtering on CURRENT_DATE #3184
-
Hello all, I have been encountering an issue whereby I see erratic behavior on a particular query that runs through the JDBC driver. For the sake of clarification, we have two types applications involved here:
In AppX, there are two tables: What we notice is that from the external tools, the query returns an incorrect result based on the value and the position of that filter. For one particular Accordingly, for both partno's there is also an entry in The corresponding query is as follows:
What happens is the following: When we query When we query Hereafter, we deployed For the correct result with -28 days, it's using a Hash Right Join. For the incorrect result with -27 days, it's using a Nested Loop Left Join. To make matters worse, when we take the working -28 query and add another WHERE statement which filters directly on the subject partno, it now also starts to generate the incorrect result. To add to the confusing, whenever we take the "incorrect" -27 query move the current date filter to the Me and my team are completely puzzled by this and are unable to understand what makes the data to come out of query incorrectly. The reason for coming to this place is that the build-in query tool of AppX is consistantly generting the correct results and all of the records show correctly in the build-in database explore there. We therefore have a strong suspicion that the issue resides somewhere in the JDBC driver. Interesantly enough, upon analysing the query plan, AppX also chooses to go the Hash Right Join and Nested Loop Left Join route based on the number of days but as mentioned, output the data correctly. As such, we are hoping that someone is able to help us understand what exactly is root cause of the behavior we are seeing here, if the dev team of the driver is the right one to contact and more importantly, what action we can take to consistantly get the correct data out of the database. Thanks in advance for your time and effort helping us! |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 8 replies
-
any chance you can see the logs on the server to see what the query is ? |
Beta Was this translation helpful? Give feedback.
-
That's unfortunate. Can you paste the explain output in text please |
Beta Was this translation helpful? Give feedback.
-
Are both using the pgjdbc driver ? |
Beta Was this translation helpful? Give feedback.
-
OK, so the only thing that is different about the JDBC driver is that we use the V3Protocol, you can try adding |
Beta Was this translation helpful? Give feedback.
-
Hmm OK, can you send me the explain outputs in text form? |
Beta Was this translation helpful? Give feedback.
-
So I posted a summary of this on pgsql-hackers https://www.postgresql.org/message-id/CADK3HHLiv-btGRshBhum0sSOM0VaoE9ottzPi-S3sRMNBKKV9A@mail.gmail.com I'd suggest you reply with more information |
Beta Was this translation helpful? Give feedback.
-
You would have to subscribe to the mailing list. In the meantime, would it be possible to replicate this system temporarily so that we could see the postgresql logs, or ask the service provider for them ? |
Beta Was this translation helpful? Give feedback.
-
thanks @tvondra appreciate you helping out |
Beta Was this translation helpful? Give feedback.
FWIW I did respond in the pgsql-hackers that I suspect this might be consistent with corrupted index. That'd be consistent with the erratic behavior you see after switching from seqscan to index scan, where the index is "missing" some of the keys (or can't find them for whatever reason). Hard to know for sure, of course.
I'd try a couple things:
set enable_nestloop=off, see if the results get correct
try bt_index_check on i_39773, might notice some corruption
rebuild the index