PHP Mysql speed

i have a database which have 2 columns but about 50M row, when i use only one where statment it will take about 12sec, how can i speed it up? my code like this SELECT id FROM tablename WHERE number=$number
26 Replies
ErickO
ErickO•2y ago
extremely hard to know from this info, do you have an index set up? guessing the 2 columns is id and number?
zimcim
zimcimOP•2y ago
nope i tried but i couldn't work yep
ErickO
ErickO•2y ago
why not?
zimcim
zimcimOP•2y ago
i don't know, it refreshed the page forever every time
ErickO
ErickO•2y ago
🤔 the page? also, what is this number column? what does it contain are we talking numbers from 1 to 10, phone numbers, ids from other sites?
zimcim
zimcimOP•2y ago
i'm using codes on my index.php i tried there and phpmyadmin, both loading forever not from other sites but they are like spesific numbers for users but not like id
ErickO
ErickO•2y ago
doesn't...tell me much are they unique?
zimcim
zimcimOP•2y ago
yeap
ErickO
ErickO•2y ago
ok that's fine then for a 50M row table it will take long to add the index
zimcim
zimcimOP•2y ago
i guess so
ErickO
ErickO•2y ago
keep in mind it's literally recreating the entire table as a sorted tree, so don't despair that will be your solution, can't do much else
Jochem
Jochem•2y ago
think minutes or even an hour or longer for 50M records
ErickO
ErickO•2y ago
yup
Jochem
Jochem•2y ago
also, please tell me you're using pepared statements and not just dumping a PHP variable into a string?
ErickO
ErickO•2y ago
PepeLaugh Jochem, only one question at a time kappa
Jochem
Jochem•2y ago
fair >_> If I need help with my prepared statements, I'll make a new topic ;P
zimcim
zimcimOP•2y ago
english is not my main lang, i couldnt understand 😭
zimcim
zimcimOP•2y ago
yep not pdo using query() on localhost
Jochem
Jochem•2y ago
right, then read that part of the manual. You need to use prepared statements to defend against SQL injection attacks
zimcim
zimcimOP•2y ago
yeah i know there is risk but i'm not gonna share
ErickO
ErickO•2y ago
they also improve performance a liiiitle bit
Jochem
Jochem•2y ago
query is fine as long as you can be 100% sure there is no user submitted data in the query, otherwise you should use prepared statements with prepare and execute
zimcim
zimcimOP•2y ago
my files never gonna be public i just wanna speed 😄
Jochem
Jochem•2y ago
that's fine, just don't form bad habits 🙂
zimcim
zimcimOP•2y ago
thanks for reminding 😄
Want results from more Discord servers?
Add your server