Query speed: replace into vs insert into ... select distinct

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
sunderwind
Forum Newbie
Posts: 9
Joined: Thu Aug 29, 2002 4:24 am
Location: Irving, TX
Contact:

Query speed: replace into vs insert into ... select distinct

Post by sunderwind »

Can anyone tell me which of the following would generally be faster? I do not know what my client has done to optimize mysql. Their mysql is running on a Sun E450 with 4 sparc 450 and 4 gigs of ram.

from_id is an int and to_id is the primary key in the table.

replace into [table] (to_id) select from_id from ....
This result set could have as many as 300,000 rows.

or

insert into [table] (to_id) select distinct from_id from ....
This result set could has as many as 100,000 rows.
User avatar
gotDNS
Forum Contributor
Posts: 217
Joined: Tue May 07, 2002 5:53 pm
Location: West Chester, PA

Post by gotDNS »

I suppose the bottom one would generally be faster, if you think about it, also because less result rows possible, too.

later on, -Brian
Post Reply