Skip to content

Enable ForceIndex extension #16034

Closed as duplicate
Closed as duplicate

Description

@neoaisac

As a developer using MySQL to make a query perform better I might want to use the FORCE INDEX syntax to ensure MySQL won't use a table scan to query my table.

Example:

var myQuery = dbContext.Set<User>()
   .ForceIndex("IX_User_CreatedDate")
   .Where(user => user.CreatedDate > DateTime.UtcNow());

If I had a way to extend the query providers underneath, I could write my own IQueryable extension method that would enable me to do this, but as it stands, I can't.

Is there any guidance as how could I achieve this?

Activity

  1. smitpatel commented on Jun 11, 2019

    @smitpatel
    Contributor

    @neoaisac - Can you write what would be the SQL generated for such query?

  2. neoaisac commented on Jun 11, 2019

    @neoaisac
    Author

    It would be similar to...

    SELECT *
    FROM User FORCE INDEX(IX_User_CreatedDate)
    WHERE CreatedDate > '2019-06-11'
    
  3. neoaisac commented on Jun 11, 2019

    @neoaisac
    Author

    I'm trying to get this done through interception but I can't figure out how to get the Expressions connected with the interception for this, and almost everything I look into is marked as "Internal API" so it seems a bit unsafe to get it done this way.

  4. smitpatel commented on Jun 11, 2019

    @smitpatel
    Contributor

    Duplicate of #6717

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions