Jump to content

Poll options - 2 queries to MySQL or Unserialize()?


WebCM

Recommended Posts

I'm making some changes in poll module. I don't know which method of storing options of poll is better. The main data of polls are in POLLS table. :)

 

Speed and efficiency is the most important issue. There are 2 methods:

 

1. Storing options in ANSWERS table and executing 2 queries to get poll's data and options. Number of records connected with a poll in that table is equal to number of poll's options.

 

Fields in ANSWERS table:

Poll ID | Sequence (optional) | Option | Amount of votes

 

2. Storing options in another field in POLLS table. They would be being unserialized after getting data from database. Perhaps, it's faster method.

 

Tests of serialize() and unserialize():

Seconds: 0.000138 | 9.5E-005

Miliseconds: 0.122 | 0.095

 

What do you think about it? Which method should I use?

Link to comment
Share on other sites

I personally would go with the two queries because the data size stored will be much greater with serialize, plus the transfer will be larger.

 

I might test this my self later cause it sounds like an interesting question....

Link to comment
Share on other sites

I hate to double post, but for what little sanity I have left, I can't find the edit button >.<.

 

 

Anyway, I got bored and decided to test this since I was kinda curios.

 

I'll attach the PHP files and MySQL dump, and the results were as follows:

 

 

The serialized data took 0.029667854309082 seconds for 100 tries....

The non serialized data took 1.224319934845 seconds for 100 tries....

The serialized data took 0.033412933349609 seconds for 100 tries....

The non serialized data took 3.6272881031036 seconds for 100 tries....

The serialized data took 0.033421039581299 seconds for 100 tries....

The non serialized data took 5.8956971168518 seconds for 100 tries....

The serialized data took 0.03874397277832 seconds for 100 tries....

The non serialized data took 7.9741280078888 seconds for 100 tries....

The serialized data took 0.03899097442627 seconds for 100 tries....

The non serialized data took 10.081195116043 seconds for 100 tries....

The serialized data took 0.050368070602417 seconds for 100 tries....

The non serialized data took 12.292681932449 seconds for 100 tries....

The serialized data took 0.054697036743164 seconds for 100 tries....

The non serialized data took 14.470578193665 seconds for 100 tries....

The serialized data took 0.060650110244751 seconds for 100 tries....

The non serialized data took 16.641561985016 seconds for 100 tries....

The serialized data took 0.070524930953979 seconds for 100 tries....

The non serialized data took 18.825333118439 seconds for 100 tries....

The serialized data took 0.084330081939697 seconds for 100 tries....

The non serialized data took 21.411001205444 seconds for 100 tries....

 

First I generated some random questions/answers for polls or what ever, using serialize for the answers on one and then creating another table for the other method.

 

I just realized that my generating script was on crack, but the results shouldn't be affected too crazy much (I might fix it later ;p).

 

[attachment deleted by admin]

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.