Database questions (speed and datatypes)

Hello all,

A friend of mine wanted me to make a database with numbers with an idication if this number was a prime number. So I made a database (myISAM) with a table primenumbers. In this table I have 2 columns, ‘numbers’ (bigint) and ‘prime’ (tinyint). With a script running on his local computer he adds numbers to this table.

First of all I had two questions about datatypes.

  1. Is bigint the best choise to store numbers, or is there a better solution?
  2. The ‘prime’ column is the indication (1 == prime, 0 == not prime). (He likes to leave this to 0’s and 1’s instead of TRUE and FALSE.) I choose tinyint to store this information, but I doubt this is the best solution. Is there another solution? :rolleyes:

An hour ago we stopped the script from running because I noticed there were no new results coming into the table. Once we stopped the script, we kept track of the results in the table and the new results were slowing being added into the table, like a delay effect. This is still happening now… Is the databse server slow or is there something else going on? :frowning:

Sorry for my English… :blush:

What database are we talking about? MySQL?

How many rows do you have in the table right now?

And how about storing only the prime numbers?

Thank you for your reaction :slight_smile:

MySQL indeed. I have 348,953 rows in the table.

He likes to store both numbers, prime and non-prime. Don’t really know why, but I think it should be able…

what is the largest number that you expect to store in the table?

I think something in the order of 1E12, spread over multiple tables (i guess that’s neccesary).

1e12 is 1,000,000,000,000, which is greater than 2,147,483,647

so yeah, you need BIGINT

but what’s the story with the multiple tables?

please, please heed guido’s suggestion, and store only the primes

Hmm, ok, it seems it’s the best idea, thanks :slight_smile:
And what about the datatype for the 1 or 0 (the ‘prime’ column) ? :slight_smile:

if you’re only going to store the prime numbers, then this column becomes useless, right?

…I’m amazed… I just made the dumbest comment on the entire forum… :stuck_out_tongue:
Sorry, thanks for the help! :slight_smile:

among the leading contenders for today, maybe, but overall? not even close


Phew, haha :stuck_out_tongue: