Showing posts with label points. Show all posts
Showing posts with label points. Show all posts

Monday, March 26, 2012

Generic question about leaf-level of non-clustered indexes

In the case of a heap, I understand the leaf-level contains some sort
of RowId which points directly to the right page in the table. Good,
pretty quick.
If the table contains a clustered index, I understand this is what's
used as bookmark in all the non-clustered indexes of that table.
Question:
Couldn't this be extremely inefficient if the clustered index is not
unique?
If I created a non unique clustered index on a (small) column with low
selectivity, I might end up with thousands of rows for each value in
the clustered index.
Then a bookmark on such a value does not seem too good, does it?
I suppose there would be several pages read before reaching the actual
data page...
Thanks
EricThis is a multi-part message in MIME format.
--=_NextPart_000_00F4_01C3777E.0F0200C0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Under the covers, it builds a "uniqueifier", so that all "keys" in the =clustered index are unique, even if you created it on a non-unique =column.
-- Tom
---
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com/sql
"Eric Mamet" <eric_mamet_test@.yahoo.co.uk> wrote in message =news:11269dcb.0309100520.6d6a4e1f@.posting.google.com...
In the case of a heap, I understand the leaf-level contains some sort
of RowId which points directly to the right page in the table. Good,
pretty quick.
If the table contains a clustered index, I understand this is what's
used as bookmark in all the non-clustered indexes of that table.
Question: Couldn't this be extremely inefficient if the clustered index is not
unique?
If I created a non unique clustered index on a (small) column with low
selectivity, I might end up with thousands of rows for each value in
the clustered index.
Then a bookmark on such a value does not seem too good, does it?
I suppose there would be several pages read before reaching the actual
data page...
Thanks
Eric
--=_NextPart_000_00F4_01C3777E.0F0200C0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
&

Under the covers, it builds a ="uniqueifier", so that all "keys" in the clustered index are unique, even if you created =it on a non-unique column.
-- Tom
---T=homas A. Moreau, BSc, PhD, MCSE, MCDBASQL Server MVPColumnist, SQL =Server ProfessionalToronto, ON Canadahttp://www.pinnaclepublishing.com/sql">www.pinnaclepublishing.com=/sql
"Eric Mamet" wrote in message news:11269d=cb.0309100520.6d6a4e1f@.posting.google.com...In the case of a heap, I understand the leaf-level contains some sortof =RowId which points directly to the right page in the table. Good,pretty quick.If the table contains a clustered index, I understand this =is what'sused as bookmark in all the non-clustered indexes of that table.Question: Couldn't this be extremely inefficient if =the clustered index is notunique?If I created a non unique clustered =index on a (small) column with lowselectivity, I might end up with =thousands of rows for each value inthe clustered index.Then a bookmark on =such a value does not seem too good, does it?I suppose there would be =several pages read before reaching the actualdata page...ThanksEric

--=_NextPart_000_00F4_01C3777E.0F0200C0--|||This is a multi-part message in MIME format.
--=_NextPart_000_0037_01C3782F.68E72280
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
To add to Tom's comments, From memory this will add four bytes to the =size of your field for the subsequent non unique values. Plus an =addition two bytes because you now have a non fixed length column. As =you can see the extra overhead can be huge on something like an INT. If =there is another column you can add to the clustered index that can make =it unique, then I would consider this as it may actually use less space. = I.e. two INTs unique may use less space that one INT with low =selectivity.
-- Barry McAuslin
Crucis Technical Solutions Limited
support@.sqlfe.com
http://www.sqlfe.com
"Tom Moreau" <tom@.dont.spam.me.cips.ca> wrote in message =news:exfAK%235dDHA.568@.TK2MSFTNGP11.phx.gbl...
Under the covers, it builds a "uniqueifier", so that all "keys" in the =clustered index are unique, even if you created it on a non-unique =column.
-- Tom
---
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com/sql
"Eric Mamet" <eric_mamet_test@.yahoo.co.uk> wrote in message =news:11269dcb.0309100520.6d6a4e1f@.posting.google.com...
In the case of a heap, I understand the leaf-level contains some sort
of RowId which points directly to the right page in the table. Good,
pretty quick.
If the table contains a clustered index, I understand this is what's
used as bookmark in all the non-clustered indexes of that table.
Question: Couldn't this be extremely inefficient if the clustered index is not
unique?
If I created a non unique clustered index on a (small) column with low
selectivity, I might end up with thousands of rows for each value in
the clustered index.
Then a bookmark on such a value does not seem too good, does it?
I suppose there would be several pages read before reaching the actual
data page...
Thanks
Eric
--=_NextPart_000_0037_01C3782F.68E72280
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
&

To add to Tom's comments, From memory =this will add four bytes to the size of your field for the subsequent non unique =values. Plus an addition two bytes because you now have a non fixed length =column. As you can see the extra overhead can be huge on something like an =INT. If there is another column you can add to the clustered index that can =make it unique, then I would consider this as it may actually use less =space. I.e. two INTs unique may use less space that one INT with low selectivity.
-- Barry McAuslin
Crucis Technical Solutions Limited
support@.sqlfe.comhttp://www.sqlfe.com">http://www.sqlfe.com
"Tom Moreau" = wrote in message news:exfAK%235dDHA.5=68@.TK2MSFTNGP11.phx.gbl...
Under the covers, it builds a ="uniqueifier", so that all "keys" in the clustered index are unique, even if you created =it on a non-unique column.
-- Tom

=---T=homas A. Moreau, BSc, PhD, MCSE, MCDBASQL Server MVPColumnist, SQL =Server ProfessionalToronto, ON Canadahttp://www.pinnaclepublishing.com/sql">www.pinnaclepublishing.com=/sql


"Eric Mamet" wrote in message news:11269d=cb.0309100520.6d6a4e1f@.posting.google.com...In the case of a heap, I understand the leaf-level contains some =sortof RowId which points directly to the right page in the table. Good,pretty quick.If the table contains a clustered index, I understand =this is what'sused as bookmark in all the non-clustered indexes of that table.Question: Couldn't this be extremely inefficient if =the clustered index is notunique?If I created a non unique =clustered index on a (small) column with lowselectivity, I might end up with =thousands of rows for each value inthe clustered index.Then a bookmark on =such a value does not seem too good, does it?I suppose there would be =several pages read before reaching the actualdata page...ThanksEric =

--=_NextPart_000_0037_01C3782F.68E72280--|||This question bothered me and it makes much more sense now.
Thanks very much to both of you.

Friday, March 9, 2012

Generate values between a starting and stopping point (time values).

[RS 2005]

Given the starting and stopping points (time values), how do I generate values between these points.

For example, if I have 08 (representing Hour) as a starting point and 12 as a stopping point.

From this I would like to generate a data sequence like 08, 09, 10, 11, and 12.

So how do I accomplish this? In SQL or in the RS?

The only thing I can think of is using a WHILE loop and a temporary table in SQL (not to keen on doing this).

//H?kan

Use custom code in the report to achieve this. Take the start and end points as input parameters as you might be already doing. Then pass them to the function in custom code and write VB code inside that function to generate all intermediate values. Then store that array in a global variable in the custom code itself which you could refer from anywhere in your report.

Shyam

|||I would either use a function or a stored procedure or a plain query for this.

CREATE FUNCTION dbo.NumberRange

(

@.Starting INT,

@.End INT

)

RETURNS @.Numbers TABLE

(

Number INT

)

AS

BEGIN

WHILE @.Starting <= @.End

BEGIN

INSERT INTO @.Numbers VALUES (@.Starting)

SET @.Starting = @.Starting + 1

END

RETURN

END

SELECT * FROM dbo.NumberRange(1,10)

Jens K. Suessmeyer.

http://www.sqlserver2005.de
|||Hakan is not keen on using SQL and WHILE loops and tables.|||I know, thats why I write the function for him.|||

H?kan,

do you need the data to be included in the dataset so that it can be rendered on the report? If so, you will have to generate it in the SQL as mentioned by Jens. If all you need to do is refer to the intermediate values from other expressions then a global array is fine, but make sure you have null and bounds checks in your custom code before trying to access the array.

|||

I guess the function also has the WHILE loop and tables.

Instead he can have a master table with just one column and values from 00 to 100 and just select the necessary numbers from that table between the given start and end.

Shyam

Sunday, February 19, 2012

Generate 2 decimal points?? how?

HI All,

I use MSSQL as my database and ASP.NET as my front application. I want to display Price value S$23.68.

The dayatype I used is smallmoney, but it display: S$23.6800. HOw do I control the number of decimals point in the column of MSSQL??

Thanks a lot

Suigion

Well for monetry values i use datatype Decimal(9,2)

where 9 is the number of digits before Decimal and 2 is the number of digits that u can use after decimal Point

hope that might helps....!!