Philip Newton (pne) wrote in lj_userdoc,
Philip Newton

  • Mood:

[site_nav] Limitations on poll data

In FAQ #148 on limitations on data, it appears to me that some of the values related to polls are outdated or simply wrong. I had a look in to try and see whether the values are correct, and also had a look in, which I hope represents the current database structure as well.

I'll take them one by one:

* Poll Names: 1000 characters

This length restriction does not appear to be enforced in; the name simply gets copied copied from the <lj-poll> tag ( However, the database column is limited to 255 bytes (, so this appears to be the upper limit—anything longer would, presumably, be truncated. (Also, if the name is under 255 characters but more than 255 bytes, it might conceivably get truncated in the middle of a character.)

* Poll Questions: 1000 characters,

This does not appear to be limited by the poll code, either, as far as I can see—and the database column is TEXT, which appears to be able to hold up to 65535 bytes.

maximum of 255 questions

This appears to be limited by the fact that the pollqid field is a "tinyint unsigned" which can hold values from 0 to 255, inclusive. This is not checked by the code, though, which will try to insert IDs that go arbitrarily high; however, it appears that MySQL clips out-of-range values for integer fields, so the 255th question be overwritten by the 256th, resulting in a duplicate key error, which results in a poll error. So the error is noticed but not prevented. But yeah. 255 is the effective maximum.

* Poll Radio and Check Box Options: 500 characters,

Not true. Each item has to fit into a varchar(255) database field, so it's limited to 255 bytes. This restriction is also enforced in code (, though the error message is misleading (poll.error.pitoolong claims that "Text inside an lj-pi tag must be between 1 and 255 characters" when the real upper bound is 255 bytes, and that is what is checked; this can be as few as 63 characters depending on how many bytes are needed to represent each character.

maximum of 255 options

Similar situation as above with number of questions per poll. True, but checked only by having the database give a duplicate key error, not by poll code.

Note that checkbox options are written into one 255-byte field, separated by commas, when the poll is submitted; this means that the number of selected options that will be recorded will vary from one (if it's 254 or 255 bytes) to 128 (if each option is one byte long). If you take an average of 10 bytes per option, you can only store 23 option results (and part of a 24th one). So there's not much point in having too many options in one poll if you expect people to select many or most of them at once. Not sure whether that should be mentioned in this document, though it is a limitation of LiveJournal, and one that people might not expect.

* Poll Text Entry Responses: 255 characters

Kinda-sorta. The database field is 255 bytes, but the HTML input widget is 255 characters. So it's possible to submit 255 characters, but only the first 255 bytes will be recorded.

There are also a couple of errors that don't concern lj_userdoc (such as the bit about cutting off text mid-character and the misleading error message.)

So. I'd recommend something like the following:

* Poll Names: 255 bytes
* Poll Questions: 65535 bytes, maximum of 255 questions
* Poll Radio and Check Box Options: 255 bytes, maximum of 255 options. The maximum number of checkbox options that can be recorded in the database depends on the length of each option text; (sum of option lengths) + (number of options - 1) must be no more than 255. (Additional options can be selected but they will not be recorded in the database.)
* Poll Text Entry Responses: 255 bytes

Tags: cat-features, faq148

  • FAQ232

    There is a typo (or two) in FAQ232. I'm talking about the following sentence: Ddd them to your Friends list them with the Add Friend button at…

  • New FAQ: How do I deal with spam?

    This FAQ is meant to tie together all of our spam-related information, currently spread over several different categories. Ideally, I'd like to have…

  • Identity Account FAQs

    As LiveJournal Support regularly uses the term identity accounts both in answers to users and amongst themselves, and some system pages refer to…

  • Post a new comment


    Comments allowed for members only

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded