Issue information

Issue ID
#2848
Status
Fixed
Severity
Fair
Started
Hercules Elf Bot
Mar 11, 2009 10:04
Last Post
Hercules Elf Bot
Apr 19, 2012 18:57
Confirmation
Yes (1)
No (0)

Hercules Elf Bot - Mar 11, 2009 10:04

Originally posted by [b]theultramage[/b]
http://www.eathena.ws/board/index.php?autocom=bugtracker&showbug=2848

I have noticed that several places use the following pattern:

1. prepare "INSERT INTO table ( ... ) VALUES (?,?,?)"
2. bind params
3. execute statement
4. if more stuff to be inserted, goto 2

If the number of entries is big, this will cause the server to spam the SQL database with a lot of tiny requests, which is inefficient and introduces processing lag. This is especially bad when the mapserver does it (mapreg code).

The traditional way would be to craft a long VALUES list by escaping the params, sprinf-ing them into a string and appending it to the rest of the query.
I received a suggestion that this same approach is possible with prepared statements - just generate VALUES (?,?,?),(?,?,?),(?,?,?), ... and bind all the params before executing.

This removes some parsing and communication overhead. Also, both of these steps can be done in parallel, since Sql_BindParam only records the param in an in-memory structure and doesn't require the entire query to be prepared first. Plus it's always better than the alternative query spam approach.

This post has been edited by theultramage: Mar 11 2009, 03:07 AM

Hercules Elf Bot - Mar 18, 2012 23:12

Originally posted by [b]Epoque[/b]
I don't see anywhere in the source where this issue might occur. It's likely anything to be affected by this has been fixed.

Hercules Elf Bot - Mar 19, 2012 3:22

Originally posted by [b]Brian[/b]
Here is one example:

[quote name='sketchyphoenix' timestamp='1331689296' post='85213']
I was going through char/inter.c and noticed this reg function

[url="http://pastebin.com/raw.php?i=A72NNkyt"]http://pastebin.com/raw.php?i=A72NNkyt[/url]
[/quote]

That [font=courier new,courier,monospace]for()[/font] loop does an insert query for every global_reg_value variable the player has.

This post has been edited by Brian on Mar 19, 2012 3:25

Hercules Elf Bot - Mar 19, 2012 11:25

Originally posted by [b]MarkZD[/b]
As Brian showed it was not fixed, so may any re-open this issue?

Maybe, there're another places where it happens, it should be looked carefully.

This post has been edited by MarkZD on Mar 19, 2012 11:25

Hercules Elf Bot - Mar 19, 2012 14:44

Originally posted by [b]Epoque[/b]
That particular for loop should now be fixed in [rev='15729'].

Hercules Elf Bot - Mar 20, 2012 1:20

Originally posted by [b]Brian[/b]
awesome possum! Thanks Epoque <3

This post has been edited by Brian on Mar 20, 2012 1:21