Forum Replies Created

Viewing 15 posts - 211 through 225 (of 1,413 total)

  • Reply To: Calculating Prime Numbers With One Query

    Jeff Moden wrote:

    @steve-2 Collins,

    Sorry... I tried your latest code on a max value of  "just" 1 million.  I stopped it at 2 hours and 8 minutes.

    Well that's disappointing.  Could it be...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Calculating Prime Numbers With One Query

    Jeff Moden wrote:

    Ok... I'm a little gobsmacked... I ran your code with zero changes and it's riddled with syntax errors and,yet, it ran without error.

    What is the following supposed to do...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Calculating Prime Numbers With One Query

    Jeff Moden wrote:

    The doubled-up relational symbology isn't floating my boat on an SQL Server forum, either.

    There are functions also as I'm sure you're already aware

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Calculating Prime Numbers With One Query

    I don't know.  Setting STATISTICS ON doesn't work on Fiddle

    Simplified without the 4th CTE

    declare @max_number       int = 100;
    declare @half_max_number int...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Calculating Prime Numbers With One Query

    As one query

    DECLARE @maxNumber INT = 1000;

    WITH BitArray AS (
    SELECT [value] AS Id, 1 AS Bit FROM generate_series(1, (@maxNumber - 1) / 2,...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Calculating Prime Numbers With One Query

    Aha the recursive CTE has been replaced with a 3rd usage of the GENERATE_SERIES function

    https://dbfiddle.uk/bhPaKD5f

    -- Create a table to store the bit array
    CREATE TABLE BitArray (
    ...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Calculating Prime Numbers With One Query

    More from ChatGPT-4

    Now, let me explain how the Sieve CTE works and how it fits in with the rest of the query.

    The Sieve of Eratosthenes algorithm works by iteratively marking...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Calculating Prime Numbers With One Query

    After giving it a few tries lately I've been trying to get GPT-4 to do things which wouldn't otherwise be attempted.  So here is AI's implementation of the Sieve of...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Calculating Prime Numbers With One Query

    Ok the proof by induction is acceptable

    If 2 doesn't add or subtract from what's being measured that's a good reason to get rid of it imo

    For my projects the upgrade...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Calculating Prime Numbers With One Query

    Jonathan AC Roberts wrote:

    including p.N%6 IN(1, 2) It does increase the performance a bit, so I would argue it is appropriate. It changes the number of prime candidates from n/2 (odd numbers)...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Calculating Prime Numbers With One Query

    Jonathan AC Roberts wrote:

    Shifting gears, there's a slight enhancement to Steve's algorithm that reduces the execution time from 2 seconds to 1.8 seconds. This improvement involves testing whether the prime candidate is...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Calculating Prime Numbers With One Query

    That's the article which had shaped my low expectations.  Good to know it's been improved.  It's also interesting Jonathan used GENERATE_SERIES in place of the non-itvf method of TOP and...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Calculating Prime Numbers With One Query

    These are great comparisons.  The so-far winning code was jointly arrived at.  Interesting in a straight comparison GENERATE_SERIES appears faster than fnTally

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Calculating Prime Numbers With One Query

    At the moment I don't have access to an instance of SQL 2022 to test with.  That could change in the near future tho.  For now I was just fishing...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Calculating Prime Numbers With One Query

    Why mess with fnTally when what we really need is for Jeffrey to rewrite the query?  Ha, then we also get a baseline of the functions.  Also how does the...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

Viewing 15 posts - 211 through 225 (of 1,413 total)