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

  • SEARCH
  • Home
  • 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 8962543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:09:00+00:00 2026-06-15T16:09:00+00:00

I have a table mytable with some columns including the column datekey (which is

  • 0

I have a table mytable with some columns including the column datekey (which is a date and has an index), a column contents which is a varbinary(max), and a column stringhash which is a varchar(100). The stringhash and the datekey together form the primary key of the table. Everything is running on my local machine.

Running

SELECT TOP 1 * FROM mytable where datekey='2012-12-05'

returns 0 rows and takes 0 seconds.
But if I add a datalength condition:

SELECT TOP 1 * FROM mytable where datekey='2012-12-05' and datalength(contents)=0

it runs for a very long time and does not return anything before I give up waiting.

My question:
Why? How do I find out why this takes such a long time?


Here is what I checked so far:

When I click “Display estimated execution plan” it also takes a very long time and does not return anything before I give up waiting.

If I do

SELECT TOP 1000 datalength(contents) FROM mytable order by datalength(contents) desc

it takes 7 seconds and returns a list 4228081, 4218689 etc.

exec sp_spaceused 'mytable'

returns

rows        reserved     data         index_size  unused
564019      50755752 KB  50705672 KB  42928 KB    7152 KB

So the table is quite large at 50 GB.
Running

SELECT TOP 1000 * FROM mytable

takes 26 seconds.

The sqlservr.exe process is around 6 GB which is the limit I have set for the database.

  • 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-06-15T16:09:01+00:00Added an answer on June 15, 2026 at 4:09 pm

    It takes a long time because your query needs DATALENGTH to be evaluated for every row and then the results sorted before it can return the 1st record.
    If the DATALENGTH of the field (or whether it contains any value) is something you’re likely to query repeatedly, I would suggest an additional indexed field (perhaps a persisted computed field) holding the result, and searching on that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database which has a table with an XML column. The XML
I have some columns in my table, descriptions column contains some information like; a1b01,Value
I have a table (call it table myTable). It has the data like this:
A table in Sybase has a unique varchar(32) column, and a few other columns.
I have a table with some columns with data as large as 8000 characters.
Let's say I have a table with 15 columns called MyTable and an UPDATE
I have a single-column table Ids , which whose column ID is of type
I have a table containing some numeric columns, and i have to keep them
I have a table containing some Timespans (as two TIME columns) Eg: TimeBegin TimeEnd
I have a SQL Database that has some Table and in that table there's

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.