• File Not Available (unregistered) in reply to qqqqqq
    qqqqqq:
    Just curious, do rdbms' have the query-equivalent of file-not-found?

    Here's another one:

    ORA-00942: table or view does not exist

  • Inferis (unregistered) in reply to home homine lupus est
    Anonymous:
    A snip of code, this javascript code leak:

    <font face="Courier New">// This function returns an array containing two functions.
    function function_array() {
    // Once this function is done running, this variable is still
    // accessible to the functions created here.
    var private_data = 0;

    var result = new Array();
    result[0] = function() { return (private_data += 1); }
    result[1] = function() { return (private_data *= 2); }
    return result;
    }

    </font>

    That's not a leak, that's a closure.
  • (cs) in reply to chrismcb
    chrismcb:
    Alex Papadimoulis:

    Everyone knew about The Report. On a moderately sunny day, with just the right wind speed and the planets properly aligned, The Report would run in a reasonable amount of time: two, maybe three minutes. But on every other day, The Report would take an incredible amount of time (measured in hours) to run, if it decided to run at all that day.

    I'm not an SQL person, so I can't quite grasp the true sense of this WTF, although that code does look heinous.

     

    What I don't understand is, WHY would this report take longer on same does than on others? Should it just always take a long time? And as more data is added, shouldn't it take even longer? What am I missing? Or are the tables of data per day?

    As if the use joins to a function with nested cursors isn't bad enough, the cursors are dynamic and thus the contents can change on each fetch...this could explain why the execution time varied so much.

  • (cs) in reply to Philbert Desanex

    This thread has been pretty funny ... seeing all these debates about ways of writing different functions in procedural languages and how they can be made more efficient and so on is exactly why there are so many people writing crappy SQL code.   They don't understand that there is huge different between optimizing SQL and optimizing procedural code, so they try to think about and optimize their SQL the way they would any other language.  And thus, many WTFs are born ....


  • (cs) in reply to Jeff S
    Jeff S:
    This thread has been pretty funny ... seeing all these debates about ways of writing different functions in procedural languages and how they can be made more efficient and so on is *exactly* why there are so many people writing crappy SQL code.   They don't understand that there is huge different between optimizing SQL and optimizing procedural code, so they try to think about and optimize their SQL the way they would any other language.  And thus, many WTFs are born ....

    Shhh! You'll make them stop, and I need the laughs.
  • (cs) in reply to RyuO
    RyuO:
    Jeff S:
    This thread has been pretty funny ... seeing all these debates about ways of writing different functions in procedural languages and how they can be made more efficient and so on is *exactly* why there are so many people writing crappy SQL code.   They don't understand that there is huge different between optimizing SQL and optimizing procedural code, so they try to think about and optimize their SQL the way they would any other language.  And thus, many WTFs are born ....

    Shhh! You'll make them stop, and I need the laughs.


    Don't worry, for every lamer being disabused, 10 new lamers are born.
  • coz (unregistered)

    Brilliant!....or "Brillant!"

    It looks like the task/jobs of multi-tasking-threaded-enterprise application were stored in the Database...I've dealt with this before...but this is worse...it seems that the queueing algorithm used to move ID's from one table to another....

    Notice the carrefull consideration on the transaction...5 ROWS at a Time...

    So maybe another Thread could run a quick "SELECT count(*) FROM cojobs" and thus getting some progress-bar info...because, after all...it's The Report....

    Now that it runs in 5 seconds..the GUI of the application seems to freeze (for short time)....hmmm...that reminds about the WTF with the scanner and the image processing technique a while ago...

     

     

  • (cs) in reply to coz
    coz:

    Brilliant!....or "Brillant!"

    It looks like the task/jobs of multi-tasking-threaded-enterprise application were stored in the Database...I've dealt with this before...but this is worse...it seems that the queueing algorithm used to move ID's from one table to another....

    Well, Oracle has a feature called DBMS_JOB that is made for managing "cronjobs" within the database. For example, you could use this feature to move old transaction records from the production table to the archive table every night at 02:00am.
  • (cs) in reply to An apprentice
    Anonymous:
    Keith Gaughan:

    Hmmm... smells like trolling... but I'll bite.

    Let's use some Python code as an example. I'll write all the different ways of expressing this code that I can think of below:

    ...snip...

    # Or there's always reduce()
    return reduce(max, [x, y])

    Sorry for nitpicking, but I think you meant return reduce(max, map(func, [x, y])). Nice and convoluted, too bad the functional features are getting removed...

    D'oh! Yup, that's more or less what I mean. Actually, I was going to give

    reduce(max, [func(x), func(y)])

    but using map() is much better :-)

  • (cs) in reply to Yo
    Anonymous:
    ammoQ:
    Anonymous:
    qqqqqq:
    Just curious, do rdbms' have the query-equivalent of file-not-found?

    This looks like something that fits:

    ORA-00320 cannot read file header from log string of thread string

    Cause: The file is not available.



    UTL_FILE would create other errors, in the most cases it throws user-defined exceptions.


    oracle-sql-test> r
      1  begin
      2  for i in reverse -20000..-1
      3  loop
      4  if (upper(sqlerrm(i)) like '%FILE%NOT%FOUND%') then
      5  dbms_output.put_line(sqlerrm(i));
      6  end if;
      7  end loop;
      8* end;
    ORA-00404: Convert file not found: ''
    ORA-01141: error renaming data file  - new file '' not found
    ORA-01169: DATAFILE number 1 not found.  Must be present
    ORA-01170: file not found ''
    ORA-01512: error renaming log file  - new file  not found
    ORA-03296: cannot resize datafile - file  not found
    ORA-06133: NETTCP: file not found
    ORA-16071: dependency archived log file not found
    ORA-16572: Data Guard configuration file not found
    ORA-19613: datafile  not found in backup set
    ORA-19615: some files not found in backup set
    ORA-19632: file name not found in control file
    ORA-19687: SPFILE not found in backup set
    ORA-19696: control file not found in backup set
    ORA-19697: standby control file not found in backup set

    PL/SQL procedure successfully completed.



    Of course there are "FNF" messages... :)

     

     

    wtf?

  • dept non style dep (unregistered) in reply to Jeff S

    I think the posted code is ugly because these UPPERCASE words everywhere, looks almost like a FORTRAN rippoff, only uglier. And looks unelegant because is not OOP oriented.
    Theres also the problem is simply wrong code for the way SQL work. But maybe SQL itself lack ...something, so the unaware will avoid that holes.

    Its posible to write elegant SQL code?

    --Tei







  • Doug (unregistered) in reply to BiggBru
    BiggBru:
    Alex Papadimoulis:

    No one had a good explanation for why The Report acted this way, nor did they want to find out. It was The Policy: questioning The Report might upset it; if The Report got upset, it might not run; and if The Report didn't run, its users would be deprived its bountiful data. The Report was good to its users most of the time, and no one wanted to change that. That is, no one, except Steven Dargal.

    <font face="Georgia">How many virgins had to be sacrificed daily to please The Report? </font>




    I don't know, but I'm sure those programmer dudes weren't happy about being sacrificed.

    :-)
  • Zahlman (unregistered) in reply to Keith Gaughan
    Keith Gaughan:
    Anonymous:
    Keith Gaughan:

    Hmmm... smells like trolling... but I'll bite.

    Let's use some Python code as an example. I'll write all the different ways of expressing this code that I can think of below:

    ...snip...

    # Or there's always reduce()
    return reduce(max, [x, y])

    Sorry for nitpicking, but I think you meant return reduce(max, map(func, [x, y])). Nice and convoluted, too bad the functional features are getting removed...

    D'oh! Yup, that's more or less what I mean. Actually, I was going to give

    reduce(max, [func(x), func(y)])

    but using map() is much better :-)



    There's also:

    <font face="Courier New">(a, b) = (func(x), func(y))
    (a, b)[b > a]
    </font>
  • (cs) in reply to home homine lupus est
    Anonymous:
    mrprogguy:

    Maybe it will.  But the idiom

    <font face="Courier New" size="2">if(func(x) > func(y))
        then return func(x);
        else return func(y);</font>

    ...

    What's truly scary is that this particular construct shows up in the original K&R, and you'd think those guys would know better, even in 197x.



    The joy of PHP:

    <font face="Courier New">$customer = new Client();
    $john = $customer;</font>

    This PHP code create 3 objects.

    If you arent not scared enough. You sould read that about leaks on Mozilla:

    http://www.mozilla.org/scriptable/avoiding-leaks.html

    A snip of code, this javascript code leak:
    <font face="Courier New">
    </font>
    <font face="Courier New">// This function returns an array containing two functions.
    function function_array() {
    // Once this function is done running, this variable is still
    // accessible to the functions created here.
    var private_data = 0;

    var result = new Array();
    result[0] = function() { return (private_data += 1); }
    result[1] = function() { return (private_data *= 2); }
    return result;
    }

    // This function returns the string "Results: 1, 2, 4, 0, 5, 1, 10."
    function test() {
    var fns1 = function_array();
    var fns2 = function_array();
    return "Results: " +
    fns1[0]() + ", " + // increments first private_data to 1
    fns1[1]() + ", " + // doubles first private_data to 2
    fns1[1]() + ", " + // doubles first private_data to 4
    fns2[1]() + ", " + // doubles second private_data to 0
    fns1[0]() + ", " + // increments first private_data to 5
    fns2[0]() + ", " + // increments second private_data to 1
    fns1[1]() + "."; // doubles first private_data to 10</font>
    }
    --Tei

    captcha: "knowhutimean" .. .heee..WTF?



    Utterly untrue as of PHP5. PHP4 has evil object-orientation. PHP5 has sensible, non-evil object-orientation where all variables holding objects actually hold references.

  • Unklegwar (unregistered) in reply to Bus Raker

    I generally assume that if I think I need to use a cursor, I've done something wrong, or I need to go read a book.

    If I still think I need a cursor, I go ask someone with vastly more DB experience than I.

    If I STILL think I need a cursor, I cross my fingers and write one :-)

  • Sam (unregistered) in reply to Doug
    BiggBru:

    <FONT face=Georgia>How many virgins had to be sacrificed daily to please The Report? </FONT>



    Fortunately, they had a large IT staff on hand.
  • (cs) in reply to dept non style dep
    Anonymous:
    I think the posted code is ugly because these UPPERCASE words everywhere, looks almost like a FORTRAN rippoff, only uglier. And looks unelegant because is not OOP oriented.
    Theres also the problem is simply wrong code for the way SQL work. But maybe SQL itself lack ...something, so the unaware will avoid that holes.

    Its posible to write elegant SQL code?

    --Tei



    Yes.  Absolutely.  Unfortunately, not many do ..... it is so easy to learn and to get started that I think people assume after a day or so that they are experts in SQL and don't need to learn any more. 
  • (cs) in reply to Zahlman
    Zahlman:

    There's also:

    (a, b) = (func(x), func(y))
    (a, b)[b > a]

    Show-off! ;-)

  • (cs) in reply to JoeBloggs
    Hey, if you're using a proper functional language, it'll cache the return values of func(x) and func(y) for later use, and you don't need to use such counterintuitive things as temporary variables.
    But if you're even halfway sane you'll use temps anyway for any sort of complex situation. F'rexample:

    gf x y
      | fx > fy = fx
      | otherwise = fy
      where
        fx = func x
        fy = func y
    

    Except with something actually interesting going on.

  • person guy (unregistered) in reply to hobbified
    hobbified:
    gf x y
      | fx > fy = fx
      | otherwise = fy
      where
        fx = func x
        fy = func y
    
    Parameters? Who needs parameters?

    gf = flip (min . func) . func

  • Frances (unregistered)

       The Holy Hierophant of the Tabernacle of The Report has issued a fatwa against Steven, declaring him an infidel and excommunicating all data generated by the new, pretender "job aggregate summary report." Beware the Report Jihad!

  • Mohammad Musleh (unregistered)

    Yep, I had to deal with such code previously, I remember one incident where a client complained about one of their reports that it’s taking almost an hour and then the connection breaks, so they have never got a chance to see any output, when I looked at the code it was written in T-SQL as stored proc an the structure of the code was using three levels cursors with some calls to UDFs, and that was the straw that broke the back of the camel, the code was more than 35 lines of code that became ~12 lines of code -although you can put all of them in one line- after I re-wrote it in one straight SQL and it runs in ~10 seconds.

  • Frodo Baggins (unregistered) in reply to mrprogguy
    mrprogguy:
    Of course, if you're using one of those massively silly languages that does logical blocking by indentation instead of bracing symbols or commands (as God intended), then you have to write something like this, and you have my condolences.

    Ever heard of python?

  • (cs) in reply to Unklegwar
    Unklegwar:
    I generally assume that if I think I need to use a cursor, I've done something wrong, or I need to go read a book. If I still think I need a cursor, I go ask someone with vastly more DB experience than I.If I STILL think I need a cursor, I cross my fingers and write one :-)

    This

Leave a comment on “The Magical Mystery Report”

Log In or post as a guest

Replying to comment #:

« Return to Article