Query Selectivity Computation

  • gaurangtalwadkar

    SSC Veteran

    Points: 297

    Hi friends,

    I m executing different queries with different parameter values from my application.

    How to compute selectivity of a query with particular parameter?

  • kinzent

    Mr or Mrs. 500

    Points: 511

    gaurangtalwadkar (5/6/2010)


    Hi friends,

    I m executing different queries with different parameter values from my application.

    How to compute selectivity of a query with particular parameter?

    distinct_values_count / all_values_count

    ---------------------------------------
    Thorn Bird...

  • gaurangtalwadkar

    SSC Veteran

    Points: 297

    I want to know whether der is any in-built function in SQL Server which gives selectivity of the query when the query is executed.

  • Grant Fritchey

    SSC Guru

    Points: 395230

    A query is not selective or not. The data it is accessing may or may not be selective. I don't understand where you're trying to go with this.

    You can query statistics and indexes to determine the selectivity of the underlying data. Is that what you're looking for?

    ----------------------------------------------------
    The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood...
    Theodore Roosevelt

    The Scary DBA
    Author of: SQL Server 2017 Query Performance Tuning, 5th Edition and SQL Server Execution Plans, 3rd Edition
    Product Evangelist for Red Gate Software

  • gaurangtalwadkar

    SSC Veteran

    Points: 297

    Hi everybody,

    how can I get query selectivity estimation in Sql server?

    I m executing query from C# application where I have provide text editor to write sql queries.

  • Grant Fritchey

    SSC Guru

    Points: 395230

    I still don't understand what you're asking for? A query has no selectivity. There is not a measured set of uniquely identifying data about a query. The data stored in tables and indexes have selectivity. You're going to have to better define what it is that you're looking for in order to get a specific answer.

    ----------------------------------------------------
    The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood...
    Theodore Roosevelt

    The Scary DBA
    Author of: SQL Server 2017 Query Performance Tuning, 5th Edition and SQL Server Execution Plans, 3rd Edition
    Product Evangelist for Red Gate Software

  • Lowell

    SSC Guru

    Points: 323331

    he had a similar thread on this;

    i think the original poster is trying to get a formula like (#records matching my WHERE clause) / Total Records, but he thinks it is stored in the statistics of the server?

    That's not the same as the statistics kept in SQL Server, and would vary for every query with a different WHERE statmenet.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply