I have an interesting question and I cannot find a reply.
I would like to create a database of prime numbers. On this page Prime numbers in a given range , I can find various examples of SQL code that can help me out reach the goal thanks to the Sieve of Eratosthenes.
So if I run this code:
CREATE PROC dbo.PrintPrimeNumbers @startnum int, @endnum int AS WITH t4 AS (SELECT n FROM (VALUES(0),(0),(0),(0)) t(n)) ,t256 AS (SELECT 0 AS n FROM t4 AS a CROSS JOIN t4 AS b CROSS JOIN t4 AS c CROSS JOIN t4 AS d) ,t16M AS (SELECT ROW_NUMBER() OVER (ORDER BY (a.n)) AS num FROM t256 AS a CROSS JOIN t256 AS b CROSS JOIN t256 AS c) SELECT num FROM t16M AS Dividend WHERE Dividend.num <= @endnum AND NOT EXISTS( SELECT 1 FROM t16M AS Divisor WHERE Divisor.num <= @endnum AND Divisor.num BETWEEN 2 AND SQRT(Dividend.num) AND Dividend.num % Divisor.num = 0 AND Dividend.num <= @endnum ); GO EXEC dbo.PrintPrimeNumbers 1, 100; GO
I can easily generate a list of all prime numbers from 0 to 100.
But let's say I want the query to run for the next 20 years, so I set as limit a very large number:
EXEC dbo.PrintPrimeNumbers 1, 1000000000000000000000000000000000000000000000000000000000...;
The query will start and will run... let's say for the next 20 years.
But the Sieve of Eratosthenes has a peculiarity:
If it gets interrupted you have to restart from the beginning.
So my questions start here:
- How can I manage to change the CPU, upgrade RAM, change Hard Drive, etc...
- How can I manage a failover disaster scenario in order to avoid that script to stop?
- Will the failover guarantee that the stored procedure won't stop?
- Cloud redundancy and failover to different providers (Azure / AWS / GCE) will this assure that the script won't stop?
- What if the failover is from Azure to AWS in 2 different parts of the globe? Will this failover keep the stored procedure running?
- Can I take a backup, let's say every month, of the status of that stored procedure, and eventually resume from that image?
- If I run the stored procedure on a virtual machine and I take snapshots, can I resume the stored procedure?
I know for sure that someone is doing this: this online database of factorized prime numbers http://factordb.com/status.php has managed to increase from 200MB (in 2014) to nearly 800MB today (2019).