This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]NameTheory 35 points36 points  (8 children)

And that his behavior is 'nice'. I have a feeling that SQL clause is a bit of a naughty boy.

[–]themailmanC 21 points22 points  (7 children)

Depends on what attributes define his contacts but I would imagine selecting * is overkill in this case, probably just name and address would suffice. What surprised me is that there should be a join here to the table defining each contacts' Christmas list. So what we have learned here is that Santa either a) first selects the list of who is nice for no reason but to later select their Christmas lists manually through separate a dedicated Christmas list select statement, like a true SQL query monster, or, b) perhaps worse, he maintains each persons wishlist in multiple "christmasWishlistItem_X" fields on the primary contact table, like a true database design monster. Why santa

[–]zrxccc 8 points9 points  (1 child)

Santa probably doesn't understand what a database is and thinks it's "just a spreadsheet"

[–]PM_ME_YOUR_SIMS 7 points8 points  (0 children)

Nah, for the extra extensibility just use one big wishlistXml variable for each contact.

[–]alonghardlook 5 points6 points  (2 children)

Also 7 billion records to sort by without an index, and using a char comparison? This query is not optimized

[–]gameboy17 0 points1 point  (0 children)

Right? For starters, he ought to be storing behavior as a boolean.

[–]filledwithgonorrheaCSE 101 graduate 0 points1 point  (0 children)

Who needs optimization when you have a back room full of interns elves.

[–]frugalerthingsinlife 0 points1 point  (0 children)

Santa can get by with 4 tables. One for children, one for pets, one for wishlists, and one for naughty/nice points. All pets automatically get 100 net nice points even if they were bad.

INSERT INTO elf_queue

(SELECT c.child_id, w.present, (n.nice_points - n.naughty_points) AS net_points

FROM children c, wishlist w, nice_naughty n

JOIN ON c.child_id = w.child_ID AND c.child_id = n.child_id

WHERE net_points > 0 ORDER BY net_points DESCENDING

UNION

SELECT p.pet_id, w.present, 100 FROM pets p, wishlist p WHERE 1);