473,406 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Which is the better method??

Let me set this up for y'all...

I have 8 mySQL databases with over 100K records, which include a phone
number field. I call these the storage tanks. They're labeled db1 - db8.

Then I have 1 mySQL database with 1-2K records, they too have a phone
number field. This database is labeled dbX

The task is to see whether each phone number from each record in dbX is
or is not in db1 or db2 or ... db8. Ultimately deduping dbX from db1-8.

I have two methods to attack this situation.

Method 1:
Reiterate through each record in dbX and call a function that returns
the number of rows in a result from each tank. Each function is a SQL
call to SELECT * FROM db# WHERE phonenumber=$phonenumber. Example -
---
$result = mysql_result();
while ( mysql_fetch_row($result))
$1 = function1($phonenumber)
$2 = function2($phonenumber)
...
$8 = function8($phonenumber)
---
Thus having the number of times $phonenumber is in each tank, allowing a
wild if, else if loop to determine if $phonenumber exists in db1-8.

Method 2:
Same thing, but instead of each function being a SQL call, have it be
an in_array() check returning 1 for true or 0 for false. Then doing the
same wild if, else if loop to determine if $phonenumber exists or not.

So, I guess my ultimate question is... Is it better(faster) to make 1-2K
* 8(db1, db2...db8) SQL queries or fill 8 arrays and perform in_array()
checks on those filled arrays.

I have a feeling that Method 2 might be faster... but I'm hoping the
community can help.

Feel free to ask more details.

Frank
Nov 29 '05 #1
1 1210
Frank [GOD] wrote:
Let me set this up for y'all...

I have 8 mySQL databases with over 100K records, which include a phone
number field. I call these the storage tanks. They're labeled db1 - db8.

Then I have 1 mySQL database with 1-2K records, they too have a phone
number field. This database is labeled dbX

The task is to see whether each phone number from each record in dbX is
or is not in db1 or db2 or ... db8. Ultimately deduping dbX from db1-8.

I have two methods to attack this situation.

Method 1:
Reiterate through each record in dbX and call a function that returns
the number of rows in a result from each tank. Each function is a SQL
call to SELECT * FROM db# WHERE phonenumber=$phonenumber. Example -
---
$result = mysql_result();
while ( mysql_fetch_row($result))
$1 = function1($phonenumber)
$2 = function2($phonenumber)
...
$8 = function8($phonenumber)
---
Thus having the number of times $phonenumber is in each tank, allowing a
wild if, else if loop to determine if $phonenumber exists in db1-8.

Method 2:
Same thing, but instead of each function being a SQL call, have it be
an in_array() check returning 1 for true or 0 for false. Then doing the
same wild if, else if loop to determine if $phonenumber exists or not.

So, I guess my ultimate question is... Is it better(faster) to make 1-2K
* 8(db1, db2...db8) SQL queries or fill 8 arrays and perform in_array()
checks on those filled arrays.


If your ultimate aim is purely to delete the duplicate info, why not do
the whole thing in SQL?

e.g.

DELETE db1
FROM db1, db2, db3, db4, db5, db6, db7, db8
WHERE db1.phoneNum = db2.phoneNum OR db1.phoneNum = db3.phoneNum ...
etc.

DELETE db2
FROM db2, db3, db4, db5, db6, db7, db8
WHERE db2.phoneNum = db3.phoneNum OR db2.phoneNum = db4.phoneNum ...
etc.

DELETE db3
FROM db3, db4, db5, db6, db7, db8
WHERE db3.phoneNum = db4.phoneNum OR db3.phoneNum = db5.phoneNum ...
etc.

A total of 7 queries, and no PHP processing (other than to create the
query strings).

Note: NOT TESTED!
--
Oli

Nov 29 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
14
by: Blue Ocean | last post by:
My c++ text tells me that I should define methods this way: class Stack { int method(double t); Stack(int s); ... } int Stack::method(double t)
17
by: lawrence | last post by:
How is it possible that the question "How do I detect which browser the user has" is missing from this FAQ: http://www.faqts.com/knowledge_base/index.phtml/fid/125 and is only here on this...
65
by: Skybuck Flying | last post by:
Hi, I needed a method to determine if a point was on a line segment in 2D. So I googled for some help and so far I have evaluated two methods. The first method was only a formula, the second...
2
by: Russell Hind | last post by:
I have a delegate which I use to store a current 'state' function (for a statemachine inside a form). __delegate void State_t(const Message_c& Message); I assign to it such as m_State = new...
4
by: Lerp | last post by:
Hi all, With regards to calling data from a database and filling in an editing form based on some query, which is the best (least intensive on processor) method for assigning the returned...
53
by: Jon S via DotNetMonster.com | last post by:
Hi all, I'm planning on developing an ASP.NET web site. I know both VB.NET and C# but am unsure on which would be more useful to develop an ASP.NET site with? Also I maybe looking to become a...
14
by: J.S. | last post by:
In a Windows Form application, which is the better method to concatenate large blocks of code? 1. Reading the text from text files. 2. Adding the text to the VB file itself? Thanks! J.S. ...
10
by: Andrea | last post by:
Which method is better to remove a char from a string? A replace or a substring? Considering that first char is at 0 position. Using reflector, replace let lost its track in internal call,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.