Jump to content

MYSQL Cardinality?


Monkuar

Recommended Posts

Not be a noob but this is getting ridiculous and pissing me off..

 

 

I have this as my indexes

 

 

PRIMARY BTREE Yes No id 182 A

users_username_idx BTREE Yes No username (25) 182 A

users_registered_idx BTREE No No registered 182 A

 

Cardinality for my PRIMARY (ID IS STUCK AT 182) but my TABLE HAS 207 RECORDS, I need to update the 182 to 207 how?

 

Why? because whenever I run this query

 

$result = $db->query('SELECT COUNT(id) FROM '.$db->prefix.'users') or error('Unable to fetch total user count', __FILE__, __LINE__, $db->error());
$stats['total_users'] = $db->result($result);

 

It sucks and shows me 182, not the real "207" id's in my users table, this is really pissing me off.

 

Hell I even deleted it and re made one, still shows 182? Damn I am lost :P

Link to comment
Share on other sites

you could try this :)

 

$result1 = $db->query('ALTER TABLE `'.$db->prefix.'users` DROP `id`;') or error('Unable to fetch total user count', __FILE__, __LINE__, $db->error());
$result2 = $db->query('ALTER TABLE `'.$db->prefix.'users` AUTO_INCREMENT = 1;') or error('Unable to fetch total user count', __FILE__, __LINE__, $db->error());
$result3 = $db->query('ALTER TABLE `'.$db->prefix.'users` ADD `id` int UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;') or error('Unable to fetch total user count', __FILE__, __LINE__, $db->error());
$result = $db->query('SELECT COUNT(id) FROM '.$db->prefix.'users') or error('Unable to fetch total user count', __FILE__, __LINE__, $db->error());
$stats['total_users'] = $db->result($result);

Link to comment
Share on other sites

you could try this :)

 

$result1 = $db->query('ALTER TABLE `'.$db->prefix.'users` DROP `id`;') or error('Unable to fetch total user count', __FILE__, __LINE__, $db->error());
$result2 = $db->query('ALTER TABLE `'.$db->prefix.'users` AUTO_INCREMENT = 1;') or error('Unable to fetch total user count', __FILE__, __LINE__, $db->error());
$result3 = $db->query('ALTER TABLE `'.$db->prefix.'users` ADD `id` int UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;') or error('Unable to fetch total user count', __FILE__, __LINE__, $db->error());
$result = $db->query('SELECT COUNT(id) FROM '.$db->prefix.'users') or error('Unable to fetch total user count', __FILE__, __LINE__, $db->error());
$stats['total_users'] = $db->result($result);

 

thanks for the code but something tells me that would hurt performance once my member's is in the thousands lol :P  im just looking to fix it through mysql first then keep using

$result = $db->query('SELECT COUNT(id) FROM '.$db->prefix.'users') or error('Unable to fetch total user count', __FILE__, __LINE__, $db->error());

whenever

 

thanks tho aha

 

 

i just know it doesn't match with my 207 id's in my table so theres something wrong, and i am looking on a way to fix it through mysql :)  i don't want to run 3 extra queries man

Link to comment
Share on other sites

There is absolutely no reason to try to manipulate the values of the primary key of a database table to suit your fancy. Doing so has the potential to utterly destroy the referential integrity of the database.

 

 

 

i have 207 ROWS...................

 

i count them, I have legimately 207 ROWS of id's but the cardinality is showing 187.............. there is something wrong here, how do I change the 187 to 207 to match how many id's I have in my table that's all I am asking  :-[

Link to comment
Share on other sites

Since I did delete 25 id's

 

i'll just use

$result = $db->query('SELECT COUNT(id) FROM '.$db->prefix.'users') or error('Unable to fetch total user count', __FILE__, __LINE__, $db->error());
$stats['total_users'] = $db->result($result);
$newstats= $stats['total_users']+25;

 

topic solved, lol thanks all

 

Link to comment
Share on other sites

Unless I'm really missing something here, I have my doubts that you actually have 207 records, since both the SELECT COUNT() and cardinality values are showing 182. Insert a new record and see what value its primary key has.

it was my fault, i apologize.. i was looking through the records in descending order and found like

 

10

7

6

5

4

1

 

so it does seem like I did delete some, (no idea why it was my fault)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.