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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:06:06+00:00 2026-05-22T19:06:06+00:00

I have 30,000 rows in a database that need to be similarity checked (using

  • 0

I have 30,000 rows in a database that need to be similarity checked (using similar_text or another such function).

In order to do this it will require doing 30,000^2 checks for each columns.

I estimate I will be checking on average 4 columns.

This means I will have to do 3,600,000,000 checks.

What is the best (fastest, and most reliable) way to do this with PHP, bearing in mind request memory limits and time limits etc?

The server need to still actively serve webpages at the same time as doing this.

PS. The server we are using is an 8 core Xeon 32 GB ram.

Edit:

The size of each column is normally less that 50 characters.

  • 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-22T19:06:07+00:00Added an answer on May 22, 2026 at 7:06 pm

    I guess you just need FULL TEXT search.

    If that not fits you, you have only one chance to solve this: cache the results.
    So you will not have to parse 3bil of records for each requests

    Anyway here how you can do it:

       $result = array();       
    
       $sql = "SELECT * FROM TABLE";
       while( $row = ... ) {
          $result[] = $row;    //> Append the current record     
       }
    

    Now results contains all the rows from your table.

    At this point you said you want to similar_text() all columns with each other.
    To do that and cache the results you need at least a table (as I said in the comment).

       //> Starting calculating the similarity
       foreach($result as $k=>$v) {
          foreach($result as $k2=>$v2) {
    
               //> At this point you have 2 rows, $v and $v2 containing your column
    
               $similarity = 0;
    
               $similartiy += levensthein($v['column1'],$v2['column1']);
               $similartiy += levensthein($v['column2'],$v2['column2']);               
               //> What ever comparison you need here between columns
    
               //> Now you can finally store the result by inserting in a table the $similarity
               "INSERT DELAYED INTO similarity (value) VALUES ('$similarity')"; 
    
          }                      
       }
    

    2 Things you have to notice:

    • I used levensthein because it’s much faster than similar_text (notice it’s value it’s the contrary of similar_text, because the greater the value levensthein returns the less the affinity between string)

    • I Used INSERT DELAYED to greatly lower the database cost

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

Sidebar

Related Questions

I need advice. I have application that imports 10,000 rows containing name & address
I have about 150 000 rows of data written to a database everyday. These
I have a large database of users (~200,000) that I'm transferring from a ASP.NET
I have a table (session) in a database which has almost 72,000 rows. I
I have 16,000 jpg's from a webcan screeb grabber that I let run for
I have 28,000 images I need to convert into a movie. I tried mencoder
I have a large dataset (over 100,000 records) that I wish to load into
I have a table with almost 800,000 records and I am currently using dynamic
I have a CSV file that holds about 200,000 - 300,000 records. Most of
Let's say I have a large database that consists of products in groups. Let'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.