1

The table in question has ~30mio records. Using Entity Framework I write a LINQ Query like this:

dbContext.MyTable.FirstOrDefault(t => t.Col3 == "BQJCRHHNABKAKU-KBQPJGBKSA-N");

Devart DotConnect for Oracle generates this:

SELECT
Extent1.COL1,
Extent1.COL2,
Extent1.COL3
FROM MY_TABLE Extent1
WHERE (Extent1.COL3 = :p__linq__0) OR ((Extent1.COL3 IS NULL) AND (:p__linq__0 IS NULL))
FETCH FIRST 1 ROWS ONLY

The query takes about four minutes, obviously a full table scan.

However, handcrafting this SQL:

SELECT
Extent1.COL1,
Extent1.COL2,
Extent1.COL3
FROM MY_TABLE Extent1
WHERE Extent1.COL3 = :p__linq__0
FETCH FIRST 1 ROWS ONLY

returns the expected match in 200ms.

Question: Why is it so? I would expect the query optimizer to note that the right part is false if the parameter is not null, so why doesn't the first query hit the index?

Marc Wittke
  • 2,991
  • 2
  • 30
  • 45
  • can you show the explain plan? – OldProgrammer Sep 22 '22 at 12:48
  • well, sort of. The problem happened in production, where this actual table is a public synonym to another schema. For development I am creating the table in a containerized DB. So I am unsure if this would help. Maybe I can get the DBA guys to share the real plan – Marc Wittke Sep 24 '22 at 10:11

1 Answers1

0

Please set UseCSharpNullComparisonBehavior=false explicitly:

  var config = Devart.Data.Oracle.Entity.Configuration.OracleEntityProviderConfig.Instance;
  config.QueryOptions.UseCSharpNullComparisonBehavior = false;

If this doesn't help, send us a small test project with the corresponding DDL script so that we can investigate the issue.

Devart
  • 119,203
  • 23
  • 166
  • 186