Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««123

A New (and Hopefully Better) Approach to Constants Expand / Collapse
Author
Message
Posted Sunday, October 21, 2007 11:39 PM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: 2 days ago @ 7:26 PM
Points: 430, Visits: 2,310
Jonathon Prosper (10/21/2007)

On another note I do appreciate you sticking your head out and writing the article on what is a common database design issue. I'd hate to think that I had contributed to an environment where discussion was negative and not constructive. You have your opinion on your design and its merits and I gave a response. Let's leave it at that.



Jonathon, it is a little confusing as to whom you are speaking in that last paragraph since you mostly address the post by tymberwyld, although you mention "the article", which I wrote. Regardless, I think you touched on a subject that needs to be discussed, and that is the level of politeness and professionalism in these discussion forums. I do not mind that there are several responses to my article that very much disagree with what I was suggesting because, as you pointed out, everyone is entitled to their own opinion. However, I am a bit shocked at some of the pointedly rude, insulting, and down-right unprofessional comments made by a few people.


There is absolutely NO REASON whatsoever for anyone in these forums to be rude to someone else. We aren’t talking politics here, and even if we were it should still be polite. We are all database professionals trying to learn from one another and these forums -- as a means of information and idea exchange -- are a great way for people to learn. But it is a shame when people who are new to this learn that they most likely shouldn't ask questions or share a solution of theirs out of fear of being put-down for it. If someone is knowledgeable enough to know a better way to approach the problem, then it is quite easy to simply say: I would approach it in this way as it has these merits. For example, Joe Celko's first response to my article did just that. He stated that it should be a one-row table, or even a view, and that the CLR poses certain problems. Ok, fine. But I am really bothered by Joe's response to the post by tymberwyld in which he copies the code only to point out, line by line, how much he doesn't like it and also calls it a nightmare and some of the worst code he ever saw. Personally, whether anyone feels that way or not, it is simply not acceptable on any level for someone in these forums to speak to anyone else in that manner and tone. There is just no good reason for it.


Joe, given how well-known you are from writing various books on the subject and being widely regarded as a SQL expert, I would really think that you could use your wonderful insight into these technical issues to more positively teach others better way of doing things; yelling at someone and calling them stupid actually discredits both you and our profession by making us look like the stereo-typical techies that are lacking certain social skills. And once such an attitude comes out in these forums it is all too easy for others -- especially the one being yelled at -- to respond in kind and hence what was a productive discussion turns into immature insults. If someone posts code that appears hideous in your knowledgeable opinion, then rant and rave all you want in your mind, but when writing an actual response please be courteous. You have a lot of knowledge to impart upon others and it is great that you share that with us, but it is hard to listen to even a correct answer when the format the answer is given in is so harsh; I am not even the person being yelled at in this instance and I still don't want to take seriously any part of your response to tymberwyld, no matter how correct you may be, simply due to the tone and insults.


But, I am not singling out Joe since I have seen several posts in these forums that are also insulting and that just has no place here. We are supposed to be helping each other out, not competing for "I am better than you" points. By all of us being respectful of each other we will create a much stronger and more productive community. :)








SQL# - http://www.SQLsharp.com/
Post #413260
Posted Sunday, October 21, 2007 11:45 PM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, March 8, 2010 5:04 AM
Points: 135, Visits: 90
Jonathon, it is a little confusing as to whom you are speaking in that last paragraph since you mostly address the post by tymberwyld, although you mention "the article", which I wrote.


Yes I meant the post. My slip.


-- JP
Post #413261
Posted Sunday, February 10, 2008 12:15 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, February 12, 2008 9:55 AM
Points: 3, Visits: 8
Sorry to necro this thread, but I was looking for alternative solutions and came across this. Thought I'd throw my 2p in.

I've had this problem a lot recently. My solution was to create a single scalar UDF, with a CASE inside it, which I passed a constant name in to, ie:

@myValue = dbo.Constant ( 'asset' )

rather than the more verbose:

SELECT @myValue = Constants.Value FROM Constants WHERE Constants.Name='asset'

I don't like use of CLR for this to be honest and applying UDF in queries is imho a disaster for performance in many cases.
Post #453682
Posted Wednesday, February 13, 2008 3:07 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, October 12, 2009 7:51 AM
Points: 2, Visits: 6
Be cautious. Not all of these approaches optimize out the same.

We use an object factory that is tightly coupled to database tables. To simplify data access we have a single view that becomes in essence a partitioned table, called dbo.Object

This view looks something like this:

create view dbo.Object
as

select 1 as objecttype_id, ID, Description from dbo.object1
union all
select 2 as objecttype_ID, ID, Description from dbo.object2
union all
select 3 as objecttype_ID, ID, Description from dbo.object3
union all
select 4 as objecttype_ID, ID, Description from dbo.object4

Now to query against that view, you can simply predicate on an objecttype. If you check the IO statistics, it is only looking up against the one table, provided you query it properly. Don't bother looking at the Query Plan as it does not truly reflect what the server does to fetch the data.

use this to check io stats:
set statistics io on


--this query works properly
select * from dbo.object
where objecttype_id = 2


--this query does not, as it evaluates each table, but at least it doesn't scan them.
declare @jobtype int
set @objtype = objecttype.object1() -- a udf that returns a value
select * from dbo.object where objecttype_id = @objtype


--this query is closer, but it is creating a working table and is evaluating for every row
select * from dbo.object where objecttype_id = objecttype.object1()

--tried this, hoping that the deterministic decisions were based on the input param to output, but to no avail
--results were same as above.
select * from dbo.object where objecttype_id = objecttype.object1(0)

--Same result
select * from dbo.object where objecttype_id = objecttype.GetType('object1')

--this is the worst, as it scans each table
select * from dbo.object
where objecttype_id = (Select objecttype.object1())


Joining on a settings table is an option, unfortunately as we may be doing multiple joins in tables requiring these constants, we would have to do multiple joins on the settings table, which turns out to be very inefficient.

So until we have a better CONST struct in SQL we will be forced to hardcode values for some of our queries.
Post #455427
« Prev Topic | Next Topic »

Add to briefcase «««123

Permissions Expand / Collapse