Raised This Month: $51 Target: $400
 12% 

Solved select on DB bad perfermance


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Alexunder
Member
Join Date: Jun 2018
Old 12-17-2018 , 18:22   select on DB bad perfermance
Reply With Quote #1

Hello guys
I wrote this code , and i'll have 2-4 output record but when i call it server make a lag for 1 sec to all the plugins connect on mehthod remote database and other plugins like rankme dont have performance problem.
I think my codes are not optimal pls help

Code:
public Action:CommandNameFamily(client, args)
{
	new String:query[255];
	new String:name[32];
	new String:family[32];
	Format(query, sizeof(query), "select name,family from users");
	new Handle:queryH = SQL_Query(db, query);
	while (SQL_FetchRow(queryH)) {
	SQL_FetchString(queryH, 0, name, sizeof(name))
	SQL_FetchString(queryH, 1, family, sizeof(family))
	PrintToChat(client, "\x01 \x04[Test]\x01 %s %s", name, family);
	}
	CloseHandle(queryH);
}

Last edited by Alexunder; 12-18-2018 at 10:23.
Alexunder is offline
timtam95
Member
Join Date: Feb 2018
Old 12-17-2018 , 18:55   Re: select on DB bad perfermance
Reply With Quote #2

you're executing a synchronous query, that's why.
timtam95 is offline
CliptonHeist
Senior Member
Join Date: Feb 2016
Old 12-17-2018 , 19:19   Re: select on DB bad perfermance
Reply With Quote #3

https://wiki.alliedmods.net/SQL_(Sou...ing)#Threading
CliptonHeist is offline
Drixevel
AlliedModders Donor
Join Date: Sep 2009
Location: Somewhere headbangin'
Old 12-18-2018 , 01:29   Re: select on DB bad perfermance
Reply With Quote #4

For clarification, SQL_Query essentially pauses the server until the query is complete and sends the results back in a handle where using SQL_TQuery queries the database in the background with a thread so you should only use threaded queries wherever you can. (I've heard they're deprecating synchronous queries anyways)
Drixevel is offline
Alexunder
Member
Join Date: Jun 2018
Old 12-18-2018 , 06:17   Re: select on DB bad perfermance
Reply With Quote #5

Quote:
Originally Posted by Drixevel View Post
For clarification, SQL_Query essentially pauses the server until the query is complete and sends the results back in a handle where using SQL_TQuery queries the database in the background with a thread so you should only use threaded queries wherever you can. (I've heard they're deprecating synchronous queries anyways)
hanks for informations , can you edit my code ?
Alexunder is offline
brunoronning
Senior Member
Join Date: Jan 2014
Location: Brazil
Old 12-18-2018 , 07:37   Re: select on DB bad perfermance
Reply With Quote #6

Quote:
Originally Posted by Alexunder View Post
hanks for informations , can you edit my code ?
Enjoy:
Spoiler
__________________

Last edited by brunoronning; 12-18-2018 at 08:09. Reason: revert methodmaps
brunoronning is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 09:04.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode