Jump to content

Mass MySQL keyword extraction


akinonyx
 Share

Recommended Posts

Problem: I'm trying to build a junction table for a many to many relationship. Table A contains a title string that contains in it names that are stored in Table B. Both tables have nearly a million rows.

 

Bad solution: The method I'm using right now is using PHP I fetch and store one table into an associative array. I then do a mysql_fetch loop on the second table and run this code to populate an array that is used to build the multi-insert SQL.

	$title = preg_replace ($names, $keys, $title);
	if (preg_match_all ('/(\d+)/', $title, $matches))
                   foreach ($matches[1] as $m)
                      $inserts[$row['id'].'-'.$m] = 1;

This works, but I'm looking for possibly a less cpu/memory intensive method. My remote server can't handle it, and we're talking hours and hours on a local server. It seems the bottleneck is with the preg_replace. I've also tried str_replace, which is only slightly faster. So, a method where I wouldn't have to pass around such large arrays, or an entirely different approach is what I'm looking for. Any ideas?

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.