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 8409913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:02:42+00:00 2026-06-10T00:02:42+00:00

I have a query like this: select count(*) from people where text_field is not

  • 0

I have a query like this:

select count(*) from people where text_field is not null;

It’s slow. Is it kosher to put an index on mediumtext field? What’s the best practice for this?

  • 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-10T00:02:43+00:00Added an answer on June 10, 2026 at 12:02 am

    This is not null query predicate is notorious for being impossible to index. That’s because null comparisons in SQL work non-intuitively.

    Your best bet is to figure out some other way to find these non-empty text_field values. If this query needs to run often, you’ll need to store some kind of flag value.

    For example, add an INT column called text_field_length and populate it with the length of the text_field, then select where text_field_length > 0

    Edit eight years later

    Newer versions of MySQL (5.7 +) and MariaDB now have computed columns. Those computed columns may be indexed.

    So you may add a computed column, maybe called text_field_not_null, to your people table, and an index on that column.

    ALTER TABLE people add column text_field_not_null INT
            AS (IF(text_field IS NULL,0,1)) STORED;
    CREATE INDEX text_field_not_null_dex ON people(text_field_not_null);
    

    Then, this query will exploit that new index.

     SELECT COUNT(*) FROM people WHERE text_field_not_null = 1;
    

    And, the value of this new column gets handled automatically.

    (MySQL has almost caught up to the pricey table servers in this respect.)

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

Sidebar

Related Questions

I have an sql query like this: SELECT IF( (SELECT COUNT(*) FROM `test_table2` WHERE
I have a query like this: SELECT COUNT(*) AS amount FROM daily_individual_tracking WHERE sales
I have a mysql query like this: $topicreplycount = mysql_query('SELECT COUNT(DISTINCT post_msg_id) FROM phpbb_attachments
I have a very simply query like this: SELECT users.id, COUNT(others.id) as c FROM
I have a query like this SELECT user_id FROM user WHERE user_id NOT IN
I have a query like this: SELECT t1.id, (SELECT COUNT(t2.id) FROM t2 WHERE t2.id
I have a query like this SELECT COUNT(u.user_id) AS count1 FROM users WHERE user_id>1001
I have query like this : SELECT EXTRACT(MONTH FROM d.mydate) AS synmonth, SUM(apcp) AS
I have a query like this: select empno,name from emp where job = 'CLERK'
I like to have a query like this: select data from table where (x

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.