Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3491100
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:35:46+00:00 2026-05-18T11:35:46+00:00

I have a pretty basic positional inverted index, in which I store a lot

  • 0

I have a pretty basic positional inverted index, in which I store a lot of words (search terms) and I use this to implement an efficient general purpose search.

My problem is that the query plan compilation is actually taking notably longer than the execution itself, I wondered if there’s something that can be done about that.

  1. I’m using dynamic T-SQL (building up the query from strings)
  2. I’m using a lot of CTEs
  3. There’s a bunch of filter check boxes that depend on the initial search result for population (take the search result and get me the count of some property of some entity). e.g. for each person found by the search text give me the distinct number of organizations involved and their respective frequency (count). These needs to be reevaluated a lot.
  4. I’ve done parameterization (given them default sizes, not some constants though, that should be fine eh?) and qualified all tables, I rely on views where possible.

The query structurally changes every time I apply a new filter or change the number of search terms which necessitates recompilation and takes time, other than that the query plan works really well.

The thing is these CTEs and filter box results are virtually the same or near identical even if they are not structurally equivalent, I’m wondering if there’s anything that can be done to improve the compilation time.

If you wanna see the T-SQL I can provide samples, it’s just that it’s big, it’s roughly 100 lines of T-SQL per search. I thought I’d ask first, before we go down that road, maybe the solution is a lot simpler that I believe it to be?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T11:35:47+00:00Added an answer on May 18, 2026 at 11:35 am

    Have you considered applying the OPTIMIZE FOR query hint?

    If you can split the large query into smaller parameterised stored procedures and combine their results, they are more likely to be cached.

    There is also the option of optimizing for ad hoc workloads in SQL Server 2008 (although this might be a last resort):

    sp_CONFIGURE 'show advanced options',1
    RECONFIGURE
    GO
    
    sp_CONFIGURE ‘optimize for ad hoc workloads’,1
    RECONFIGURE
    GO
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a pretty basic jquery script which uses an h2 as a trigger
I have a pretty basic X11 app that I run on Linux that I'm
I have a pretty basic query, but I'd like it to return the results
I have a pretty basic jQuery ajax thing happening, but I want to mix
I have an application that generates some pretty basic reports. I have installed the
I have an error stating something like: The method foo() is undefined for the
I have created an experimental fast rectangular object tracking system; it will be used
I've been stuck for ages now trying to implement threading or background image loading
Possible Duplicate: What does '?' do in C++? xo = ((temp.npieces%2)==1)? 1 : 2;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.