/    Sign up×
Community /Pin to ProfileBookmark

comparing tables performance

Hi, I’ve got 2 tables in MySQL, changelist and fed. I’m going through the changelist table and seeing if the phonenumber is found in the fed table, and if it is deleteing it. I’m kinda new to php+MySQL, and was wondering if there was another way to do this to maybe speed up the process?

[code=php]
//compare dnc.changelist to dnc.fed, removing D’s first, then adding A’s
//grab the phone numbers from dnc.changelist
$sQuery = ‘SELECT fullphone FROM `dnc`.`changelist` WHERE `changetype`=’D”;
$result = mysql_query($sQuery);
if (!$result) {
die(‘Query failed: ‘ . mysql_error());
}
//fetch rows in reverse order
for ($i = mysql_num_rows($result) – 1; $i >= 0; $i–) {
if (!mysql_data_seek($result, $i)) {
echo “Cannot seek to row $i: ” . mysql_error() . “n”;
continue;
}

if (!($row = mysql_fetch_assoc($result))) {
continue;
}
//searching through fed file
//————————-
$query = ‘SELECT `fullphone` from `dnc`.`fed` WHERE `fullphone`= ‘.
$row[‘fullphone’];
$res = mysql_query($query);
$temp_res = mysql_fetch_assoc($res);
if(!empty($temp_res)){
$qQuery = ‘DELETE FROM `dnc`.fed` ‘.
‘WHERE `fullphone`=’.$row[‘fullphone’].”;
mysql_query($qQuery) or die(“Failed while deleting D type record”);
$_SESSION[‘deleted’] = $_SESSION[‘deleted’]+1;
}
}
[/code]

then I go through again and start adding the ones that have an A in the changetype field in dnc.changelist, anyone have a different way of doing this? or maybe I should look more into the sql side of the code for faster results?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@tarsusOct 12.2006 — Instead of querying and then deleting for each separate number, I'd build an array of the numbers to use in a single delete:

[code=php]$phone_array=Array();

for ($i = mysql_num_rows($result) - 1; $i >= 0; $i--) {
if (!mysql_data_seek($result, $i)) {
echo "Cannot seek to row $i: " . mysql_error() . "n";
continue;
}

if (!($row = mysql_fetch_assoc($result))) {
continue;
}
//searching through fed file
//-------------------------
$phone_array[]='fullphone=' . $row['fullphone'];
$_SESSION['deleted'] = $_SESSION['deleted']+1;
}

$query = 'DELETE FROM dnc.fed WHERE '
$query .= implode(' OR ',$phone_array);
$res = mysql_query($query);[/code]
Copy linkTweet thisAlerts:
@carlhauthorOct 12.2006 — that sounds like a pretty good idea, the table i'll populate the phone_array with can sometimes have 1million+ records though, so maybe do the first couple hundred the reset the phone_array with the next couple hundred, so it's doing it more than just one at a time

i'm just a bit worried about trying to load the all the phone numbers in the array at once, since the server i'm running on is used for other things too, and i've got the php-cgi.exe set to use at most 50% cpu, and the cpu usage seems to jump up pretty fast. i know limiting it can be a part of the cause of my slower performance, but i don't have another server to run it off of.
×

Success!

Help @carlh spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...