Click here to Skip to main content
15,881,803 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Yeah I did it... Pin
OriginalGriff3-Jul-12 21:45
mveOriginalGriff3-Jul-12 21:45 
GeneralRe: Yeah I did it... Pin
PIEBALDconsult4-Jul-12 5:50
mvePIEBALDconsult4-Jul-12 5:50 
GeneralBack In The Day Pin
_Maxxx_3-Jul-12 20:54
professional_Maxxx_3-Jul-12 20:54 
GeneralRe: Back In The Day Pin
RobCroll4-Jul-12 4:10
RobCroll4-Jul-12 4:10 
GeneralRe: Back In The Day Pin
_Maxxx_4-Jul-12 12:41
professional_Maxxx_4-Jul-12 12:41 
GeneralRe: Back In The Day Pin
User 5838524-Jul-12 13:40
User 5838524-Jul-12 13:40 
GeneralRe: Back In The Day Pin
_Maxxx_4-Jul-12 14:08
professional_Maxxx_4-Jul-12 14:08 
GeneralSearch Query: My Boss is a Genius Pin
AspDotNetDev3-Jul-12 12:44
protectorAspDotNetDev3-Jul-12 12:44 
We manage an application that searches an internal database. It's slow... takes about 3+ seconds to search. The reason is that there are tons of records and our search query is basically this:
SQL
SELECT * FROM SomeTable WHERE Field LIKE '%Something%'

That "LIKE" (with the initial "%") prevents SQL from using indexes for that field (which leads to a full table scan, meaning hundreds of thousands of records must be loaded). To fix that, I have the brilliant idea to create a new table and split the field across 72 columns (the current max length of the field). Each column would store the field with one less leading character than the previous column. The new query would look something like this:
SQL
SELECT * FROM SomeNewTable WHERE Field1 LIKE 'Something%' OR Field2 LIKE 'Something%' ... OR Field72 LIKE 'Something%'

That's a lot of data, but SQL Server 2005 has a limit of 200+ indexes on any table, so I figure fair trade. However, after showing this to my boss, he comes up with the idea to instead store a new column per word in the search string rather than per character. So we might only have 8 columns instead of 72:
SQL
SELECT * FROM SomeNewTable WHERE Field1 LIKE 'Something%' OR Field2 LIKE 'Something%' ... OR Field8 LIKE 'Something%'

I thought that sounded pretty good, except I thought then auto-complete wouldn't work until a full word was typed. However, thinking about it some more, auto-complete will work, considering people typically type words starting with the first letter (e.g., people will generally type "something" starting with "some" rather than starting with "thing").

My boss just prevented me from creating a horrific table. He's a genius.

Now I just need to consider a few niggling options: different tables for clustered indexes, a single column with each word rather than split-up columns, combinations of sequential words, and SQL Server full text indexing (not even sure if that would apply to this situation, but I'll soon see). Seems I have some design and experimenting ahead of me. Smile | :)

GeneralRe: Search Query: My Boss is a Genius Pin
AspDotNetDev3-Jul-12 12:52
protectorAspDotNetDev3-Jul-12 12:52 
GeneralRe: Search Query: My Boss is a Genius Pin
_Maxxx_3-Jul-12 20:46
professional_Maxxx_3-Jul-12 20:46 
GeneralRe: Search Query: My Boss is a Genius Pin
AspDotNetDev3-Jul-12 21:15
protectorAspDotNetDev3-Jul-12 21:15 
GeneralI hate outsourcing... PinPopular
Rhys Gravell1-Jul-12 23:40
professionalRhys Gravell1-Jul-12 23:40 
GeneralRe: I hate outsourcing... PinPopular
CDP18021-Jul-12 23:43
CDP18021-Jul-12 23:43 
GeneralRe: I hate outsourcing... Pin
ZurdoDev2-Jul-12 2:43
professionalZurdoDev2-Jul-12 2:43 
GeneralRe: I hate outsourcing... Pin
Brisingr Aerowing2-Jul-12 3:00
professionalBrisingr Aerowing2-Jul-12 3:00 
GeneralRe: I hate outsourcing... Pin
emajyn2-Jul-12 4:28
emajyn2-Jul-12 4:28 
GeneralRe: I hate outsourcing... Pin
PIEBALDconsult2-Jul-12 7:19
mvePIEBALDconsult2-Jul-12 7:19 
GeneralRe: I hate outsourcing... Pin
AspDotNetDev2-Jul-12 7:31
protectorAspDotNetDev2-Jul-12 7:31 
GeneralRe: I hate outsourcing... PinPopular
Rhys Gravell2-Jul-12 21:32
professionalRhys Gravell2-Jul-12 21:32 
GeneralRe: I hate outsourcing... Pin
Gary Huck3-Jul-12 2:34
Gary Huck3-Jul-12 2:34 
GeneralRe: I hate outsourcing... Pin
PIEBALDconsult3-Jul-12 3:29
mvePIEBALDconsult3-Jul-12 3:29 
GeneralRe: I hate outsourcing... Pin
Bernhard Hiller3-Jul-12 20:25
Bernhard Hiller3-Jul-12 20:25 
GeneralRe: I hate outsourcing... Pin
Rhys Gravell3-Jul-12 20:28
professionalRhys Gravell3-Jul-12 20:28 
GeneralThis probably falls into the 'weird' category Pin
CDP18021-Jul-12 22:57
CDP18021-Jul-12 22:57 
GeneralRe: This probably falls into the 'weird' category Pin
User 24844372-Jul-12 19:22
User 24844372-Jul-12 19:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.