473,811 Members | 3,182 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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=$ph onenumber. Example -
---
$result = mysql_result();
while ( mysql_fetch_row ($result))
$1 = function1($phon enumber)
$2 = function2($phon enumber)
...
$8 = function8($phon enumber)
---
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 1229
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=$ph onenumber. Example -
---
$result = mysql_result();
while ( mysql_fetch_row ($result))
$1 = function1($phon enumber)
$2 = function2($phon enumber)
...
$8 = function8($phon enumber)
---
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
6160
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. "Decimal Number" sometimes serves to distinguish Base 10 numbers, eg "15", from Base 2 numbers, Eg "1111". At other times "Decimal Number" serves to differentiate a number from an integer. For the rest of this post I shall only use either...
14
1662
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
2580
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 with a link to old information that suggests use of "navigator": http://developer.irt.org/script/43.htm
65
12636
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 method was a piece of C code which turned out to be incorrect and incomplete but by modifieing it would still be usuable. The first method was this piece of text:
2
1643
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 State_t(this, StateShutdown); How can I later check which method the State is pointing to? And is
4
1799
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 results to a variable. I have been using a couple of ways so far in my project.: 1. strFirst=objDR("Fname") 2. strFirst=objDR.GetOrdinal("Fname")
53
3323
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 web developer in the future so it would help if I use the langauge that most companies use to develop their ASP.NET site? Many thanks, Jon.
14
2374
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
1656
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, while substring show what it really does, so I'm not able to evaluate the efficiency. Any suggestion?
0
10647
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10384
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10130
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7667
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5553
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4338
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3865
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3017
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.