MySQL query performance

I create a simple vote, a unique viewer, a unique function count count etc. in php / mysql, and I have one question regarding performance:

Due to the large number of activities on this small system, I want to know what works best for this, using multiple columns INTor 1 single column VARCHAR, of course, in terms of performance:

$uniqueid= STRING generated from system (ip, cookies Etc)
$contentid = INT ID on primary key of content table
$contenttype = INT 0-n   ( comment = 0, poll = 1, filedownload = 2 Etc).
$action = INT 0-n ( vote = 0,  view = 1, download = 2 Etc)


SELECT *
FROM `table`
WHERE `uid` = '$uniqueid' AND `cid` = '$contentid' AND `ct` = '$contenttype' AND `action` = '$action' ;

Or that:

$key  = "$uniqueid-$contentid-$contenttype-$action";

SELECT *
FROM `table`
WHERE `key` = '$key';
+4
source share
3 answers

You must keep them separate.

  • You might want to remove one of the functions later.
  • Can extract usage data from each separately
  • ,
0

.

:

SELECT *
FROM `table`
WHERE `uid` = '$uniqueid' AND `cid` = '$contentid' AND `ct` = '$contenttype' AND `action` = '$action' ;

, , :

create index table_uid_cid_ct_action on table(uid, cid, ct, action)

, =.

0

- , ​​, INT 1 VARCHAR , , .

, , ... ! MySQL - , . . , , . , .

, , INT MySQL. MySQL, , , . , , MyISAM InnoDB,.

. , , MySQL Tuning Primer Script, , MySQL, .

, . MySQL , . MySQL (?) , .

, - MySQL , Script 95% - . 5% - , . , MySQL.

0
source

Source: https://habr.com/ru/post/1539363/