Skip to content

Multiple query execution plans for query with named parameters #803

Open
@nicolaepopa

Description

I am using named parameters to build my queries:

`queryString := 'insert into sch.MyTable(Field1,Field2,Field3) values(@field1,@field2,@field3)'

_, err := sn.DbConn.Exec(queryString,
sql.Named("Field1", myStruct.Field1),
sql.Named("Field2", myStruct.Field2),
sql.Named("Field3", myStruct.Field3)
)`
All fields are strings
Running this multiple times with different sizes of strings result in multiple query plans:

`(@field1 nvarchar(4),@field2 nvarchar(16),@field3 nvarchar(16))

INSERT INTO sch.MyTable (Field1,Field2,Field3)

VALUES (@field1, @field2,@field3);`

The size of the nvarchar field declaration varies depending on the size of the input string and SQL creates a plan for each variation.
Is there something that I can do that would result in a single query plan for this query?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions