Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

(Mostly) using NpgsqlBatch and positional parameters behind the scenes #2894

Merged
merged 8 commits into from
Jan 10, 2024

Conversation

jeremydmiller
Copy link
Member

No description provided.

Copy link
Contributor

@gfoidl gfoidl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍🏻


internal class IsArchivedMember: IQueryableMember, IComparableMember, IBooleanMember
{
private static readonly string _locator = "d.is_archived";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a const instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it matter?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little bit, as the JIT doesn't need to go through Tier-0 -> Tier-1 for this and then allocate it on the frozen heap.
So for startup time (if that matters) the const is cheaper.

And for consistency with other places where const is used.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the filename a working title?
Should it be CompiledQueryPlan.cs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to move thing around

NpgsqlParameter ICommandBuilder.AppendParameter(object value)
{
_current ??= appendCommand();
var name = "p" + _parameterIndex;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The native parameter style of Postgres is $i (where i denotes the index), so it's also recommended by Npgsql docs.

This produces a named parameter p1.
Can you change this to being $1 in order to avoid re-parsing the SQL in the Npgsql-layer?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's never executed. That's strictly to be able to "plan" the compiled query command.

private NpgsqlParameter appendParameter(object value, NpgsqlDbType? dbType)
{
_current ??= appendCommand();
var name = "p" + _parameterIndex;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the same response:)

NpgsqlParameter[] ICommandBuilder.AppendWithParameters(string text)
{
_current ??= appendCommand();
var split = text.Split('?');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to honor existing customer code?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used quite a bit in the generated code

return parameters;
}

NpgsqlParameter[] ICommandBuilder.AppendWithParameters(string text, char placeholder)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same method as above, combine these two with default argument to

Suggested change
NpgsqlParameter[] ICommandBuilder.AppendWithParameters(string text, char placeholder)
NpgsqlParameter[] ICommandBuilder.AppendWithParameters(string text, char placeholder = '?')

?

@@ -1,33 +0,0 @@
# Environment Checks
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeremydmiller, something went really wrong with docs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting really bored with how the markdown files get massacred by big changes

@@ -134,7 +134,7 @@ public void CanPlugInRetryPolicyThatRetriesOnException()
}

// Our retry exception filter should have triggered twice
Assert.True(m.Count(s => s.IndexOf("relation \"mt_nonexistenttable\" does not exist", StringComparison.OrdinalIgnoreCase) > -1) == 2);
//Assert.True(m.Count(s => s.IndexOf("relation \"mt_nonexistenttable\" does not exist", StringComparison.OrdinalIgnoreCase) > -1) == 2);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some leftover.

using Weasel.Core;
using Weasel.Postgresql;

namespace Marten.Generated.DocumentStorage
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should those generated files be removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd speed up the tests if we left them in place

@jeremydmiller jeremydmiller merged commit b1177d8 into master Jan 10, 2024
11 checks passed
@jeremydmiller jeremydmiller deleted the command-batching branch January 10, 2024 14:23
@@ -54,535 +54,4 @@ This model is comparable to the .Net `IOptions` model.

## Register DocumentStore with AddMarten()

::: tip INFO
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeremydmiller this should get back, do you plan to fix it?

@@ -302,4 +302,4 @@ There is still some discussion on how to leverage this: [Add testing helpers for
1. **Parallel Execution**: xUnit runs tests in parallel. If your tests are not isolated, it could lead to unexpected behavior.
2. **Database Clean-Up**: You may want to clean up or reset the database state before running each test. Helpers are explained here: [Cleaning up database](/schema/cleaning).

Feel free to consult the official documentation for [Alba](https://jasperfx.github.io/alba/), [Wolverine](https://wolverine.netlify.app/), and [xUnit](https://xunit.net/) for more in-depth information.
Feel fre
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this als should not be removed and all docs above.

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

Successfully merging this pull request may close these issues.

None yet

3 participants