Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Array parameters values are not visible with EnableSensitiveDataLogging #1779

Closed
Xayton opened this issue Mar 23, 2021 · 1 comment
Closed

Comments

@Xayton
Copy link

Xayton commented Mar 23, 2021

Hello, coming from a previous version of npgsql EF Core (2.2), I noticed the following change regarding executed query logging.
Given the following code:

// Enable sensitive data logging: will log the queries and the parameters too.
protected override void OnConfiguring(DbContextOptionsBuilder builder) => builder.EnableSensitiveDataLogging();

[...]

var ids = new int[] {1, 2, 3};
var x = _context.Blogs.Where(b => ids.Contains(b.Id)).ToList();

With the previous version I was getting the following log, where the ids values were not parameterized, but they were clearly visible:

Executed DbCommand (3ms) [Parameters=[], CommandType='Text']
SELECT b.name
FROM blogs AS b
WHERE b.id IN (1, 2, 3)

Now with npgsql EF Core 5.0 I'm getting this log:

Executed DbCommand (11ms) [Parameters=[@__ids_0='System.Int32[]' (DbType = Object)], CommandType='Text']
SELECT b.name
FROM blogs AS b
WHERE b.id = ANY (@__ids_0)

The generated SQL is fine, even better because ids are now parameterized, but their value is not visible anymore, making harder to run the query manually for debugging purposes.

  • Is there a way to get the contents of the ids array in the "Parameters" section of the log?
  • Is this a regression or is by design?

Thank you!

@roji
Copy link
Member

roji commented Apr 6, 2021

@Xayton this isn't a regression - in fact it's an improvement in how the Npgsql EF provider translates your LINQ query. The previous translation with IN (1, 2, 3) (which is in use for all other non-PG providers) has serious performance issues, since the SQL varies with different parameter values (bad for query plans, prepared command caching etc). The new translation makes use of PostgreSQL arrays to use a single SQL for all queries, significantly improving performance.

Unfortunately, arrays are a PostgreSQL-specific feature, and so EF Core doesn't know how to log them. I've opened dotnet/efcore#24595 to track this.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants