Showing posts with label guys. Show all posts
Showing posts with label guys. Show all posts

Friday, March 30, 2012

Impact of SELECTed colums on the execution plan

Hi guys,

I have something weird that I want to understand.

I have a big table, containing around 17 millions of rows. This table has been progressively indexed over time, mainly by following some of the recommendations of the DB tuning advisor. As a result, we have around ten indexes on this table, some of them are using the new "INCLUDE" feature of SQL2005 indexes with non-key data.

The problem I have is the following : I have a very simple query (SELECT <some columns> FROM that_table WHERE <simple clause conditions>) which should benefit from the indexes built on the table. But depending on the columns I select, the execution plan varies totally !!

With one column selected, the good index is used, and the query is fast.

With two columns selected, the execution plan becomes complicated (several different indexes seeked in parallel). I guess the optimization system is trying to get benefit from some non-key data included in some of the indexes ? But I'm not sure...

With a "SELECT *" no appropriate index is used. The excution plan shows it will do a "clustered index scan" over the primary key (which is not part of the where clause), resulting in a full scan of the table... OK, I know that "SELECT *" is not a good practice, but anyway, this result is very surprising.

(I tried to make it short, I can detail the queries and the construction of the indexes if needed, but the main info is there I think)

How can it be possible to have so many differences, just by changing the list of SELECTed columns ? It's beyond my understanding of what is an index...

Thanks for your help

Mathieu

Hi Mathieu,

There's a few things that could be going on here, and it's hard to make a definitive call without investigating the query plan, but...

If you include columns in the select list that are not served by the index the used in order to serve the where clause, the engine will need to perform what's known as a bookmark lookup in order to retrieve the column values that are not included in the index. It of course gets a bit more complicated if the optimiser chooses parallel indexes.

So, if your query was something like:

SELECT id, name, dob

FROM tblPerson

WHERE id = 993

You can also try execting the query with OPTION (MAXDOP 1) in order to determine if the generation of a parallel query plan is introducing unnecessary overhead.

You would create an index on the id column and list name and dob columns in the new INCLUDE clause. This would be a good starting point, but you'd need to take into account all other queries against this table in order to decide if indeed this. Indexing is a huge subject, so get googling! :)

Cheers,

Rob

|||

To be clearer :

1st case :

SELECT a FROM table WHERE b=constant AND c>constant AND d LIKE 'string%'.

c AND d are covered by an index, and the column a is included (INCLUDE keyword) in that index. b, c, and d are regulars data columns (not involved in PK). The exec plan is fine, the query is fast.

2nd case : I just add a column in the SELECT, the where clause is left untouched

SELECT a, e FROM table WHERE b=constant AND c>constant AND d LIKE 'string%'.

Here, the column e is not included in the index mentionned hereunder. The exec plan becomes complicated, involving others indexes in parallel. The query becomes slow.

3rd case : retrieving all columns, the where clause is still left untouched

SELECT * FROM table WHERE b=constant AND c>constant AND d LIKE 'string%'.

This time, the exec plan is "clustered index scan" over the PK. But the PK does not appear in the where clause ! Result is a full scan of the 17millions of rows... catastrophic !

While writing this post, I'm getting convinced that SQL Server is perturbed by the INCLUDEd columns in the indexes... What's your opinion ?

|||

Hi Mathieu,

As mentioned, if a column in the select list is not included in the index, a bookmark lookup is used. So, in the 2nd case above, you would either include column e in the index used for the operation either as a key value or in the INCLUDE list.

In the 3rd case, it would appear the optimiser has decided that rather then performing lookups for all the columns not servicable by the index (ie the SELECT *), it has chosen to perform a full scan. I'd need to see the full query plan and the schema to provide more info, but it sounds like you need to revisit your indexing strategy from the ground up.

Although INCLUDE is new to 2005, I've never had nor heard of an issue directly related to its use (yet).

Cheers,

Rob

IMMEDIATE ATTENTION PLEASE.....

hi all..
hope u guys can help me out here.....
'm new to .net so hope to get all the basic infomr that would b required...

'm on a proj..basically a data mining proj...
'm using sql 2005 enterprise edn's analysis services to perform my data minning tasks...
here is what i'd like to know....
i've been following the sql online tutorial book...
n as per the tutorial on data minning...i have created a data source ... based on the decision tree algorithm i have even obtained some results..
now.....here is the problem..

i'd like to know if i can actually get all these obtained patterns onto a webpage...
i mean can i actually use asp.net n achieve this task of migrating the patterns generated at the bids to a webpage?

please guys if i can do so...then do tell me how to do so...
my proj dline is in 2 weeks....i need desperate help....
'm waitin...

here is how i vusualize my goal..... web pages that display patterns generated after an analysis has performed......


thxxxx... a ton
hanish

AS includes a set of data mining viewer controls intended for this. You can also query the mining models from RS.

See this topics in Books Online.

Using Analysis Services DMX Query Designer

And this link to download the Data Mining controls:

http://www.microsoft.com/downloads/details.aspx?FamilyID=df0ba5aa-b4bd-4705-aa0a-b477ba72a9cb&DisplayLang=en

The mining controls are halfway down the page.

|||

...umm...alrite thanks...

but the thing is i really don't wan't to open bids n check out the report.....

i am asking if there is any way how i can view the obtained patters at a report on a webpage without having to open

BIDS ....ll explain my problem ...........

my task is to illustrate data minning using asp.net as the front end and SQL server 2005 entp.as back end.....

BIDS will take care of all the data minning operations that i need to perform...and will generate reports corresponding to various data minning models.......

now i intend to create a UI using asp.net(c# codin.) and then link these web-pages to the already obtained reports.....can i do it without having the user open BIDS?

plzzzzzz plzzzz guys help me.....

thx.....

|||

That functionality is exactly what the data mining controls provide. The user doesn't have to use BIDS to see the results. For that matter, if you develop a report in Reporting Services and deploy it, the user doesn't need BIDS.

For your task, you need to look at the data mining controls. Or you could query directly through ADOMD (an OLEDB provider), but the mining controls handle the visual display for you.

|||

hi jwelch Smile

thx for ur instructions for my problem.......

as per u instructed i d/loaded Microsoft SQL Server 2005 Analysis Services 9.0 OLE DB Provider which i suppose helps provide the data mining controls....... here is an honest appeal...after having installed it i havn't really seen any change or havn't really been able to discover the data mining controls...

i am certain that it is because i am totally new to sql server, i am getting a little nervous if i can really do this task, please would u mind helping me in achieving my task......

i've done minning on the adventure datawarehouse and now have obtained the patterns which i can view in BIDS......i would now like to know the steps i should follow to make use of the data mining controls by which i can migrate these results onto a browser.......you have told me this is possible ...please i have no other option but to take your help do consider my request ......

waiting for your reply..

|||

any body here ...

plzzzzzz help me in figurin my way out.....

mr.john u der?

|||

No, it's not the OLE DB provider. It's the data mining viewer controls. They are about 4 items below the OLE DB provider.

http://www.microsoft.com/downloads/details.aspx?FamilyID=df0ba5aa-b4bd-4705-aa0a-b477ba72a9cb&DisplayLang=en

Microsoft SQL Server 2005 Datamining Viewer Controls

The Data Mining Web Controls Library is a set of Microsoft Windows Forms controls that enable software developers to display data mining models created using Microsoft SQL Server 2005 Analysis Services in their client-side applications. The controls in this library display the patterns that are contained in Analysis Services mining models.
|||

hj wrote:

any body here ...

plzzzzzz help me in figurin my way out.....

mr.john u der?

hanish,

you really need a course on forum ettiquette: don't demand things, don't write all in capitals (your subject line), and don't expect people to do your work for you.

What exactly are you wanting? It seems to me that you want to know how to run or request reports from within a standard ASP.Net page?

|||

i do apologize ,

yup sluggy u got my prob rite......im tryin to run the results i got after the minin operation from within a std asp.net page..

hey..n thx ...mr.john....

|||

hi ...'m back again with my nt so good doubts..

;m stuck on thiz one thing mr.john...........

after havning installed the data mining viewer controls what is my next step....i mean i don't even see these contrls in my web dvlpr toolbar....

after going tro some threads here..i figured out that the nxt step is to add the viewer contrls into the toolkit of visual c# web dvplr.....

but ;m not succesful in doing so.....

jus like i told u before ...my task is to bring out these patters onto a web page.........

one more doubt......

is there any tutorial about what each of these web contrl does? whr can i learn more bout these controls......are there any sample videos i could get access to, to actually know more about how to use these controls....

please help me ....thx a lot

hanish|||

hj wrote:

hi ...'m back again with my nt so good doubts..

;m stuck on thiz one thing mr.john...........

after havning installed the data mining viewer controls what is my next step....i mean i don't even see these contrls in my web dvlpr toolbar....

after going tro some threads here..i figured out that the nxt step is to add the viewer contrls into the toolkit of visual c# web dvplr.....

but ;m not succesful in doing so.....

jus like i told u before ...my task is to bring out these patters onto a web page.........

one more doubt......

is there any tutorial about what each of these web contrl does? whr can i learn more bout these controls......are there any sample videos i could get access to, to actually know more about how to use these controls....

please help me ....thx a lot

hanish

Have you looked in your C:\Program Files\Microsoft SQL Server\90\Samples\Analysis Services\DataMining\Data Mining Web Controls folder? You may need to install the SQL Server Samples to use this.

|||

yup...dat is de exact prob....i did install dm viewer controls but den din find a samples folder under \Program Files\Microsoft SQL Server\90.......

now i did install all the samples that came with the sql cd..could u tell me whr i could download these samples from the net.....

my sincere thanks mr john..

feel like ur the only one replyin to my posts here..

thx again.......

hanish

|||one more question...'m working with sql server 2005 enterprise edn........do i hav to install sp2 for sql server to achieve my tasks...|||

hj wrote:

yup...dat is de exact prob....i did install dm viewer controls but den din find a samples folder under \Program Files\Microsoft SQL Server\90.......

now i did install all the samples that came with the sql cd..could u tell me whr i could download these samples from the net.....

my sincere thanks mr john..

feel like ur the only one replyin to my posts here..

thx again.......

hanish

This link has the lastest sample applications for SQL Server.

http://www.microsoft.com/downloads/details.aspx?FamilyId=E719ECF7-9F46-4312-AF89-6AD8702E4E6E&displaylang=en

|||

hj wrote:

one more question...'m working with sql server 2005 enterprise edn........do i hav to install sp2 for sql server to achieve my tasks...

I don't think it is required. However, the samples I referenced above have been updated for SP2.

IMMEDIATE ATTENTION PLEASE!!!

hi all..
hope u guys can help me out here.....
'm new to .net so hope to get all the basic infomr that would b required...

'm on a proj..basically a data mining proj...
'm using sql 2005 enterprise edn's analysis services to perform my data minning tasks...
here is what i'd like to know....
i've been following the sql online tutorial book...
n as per the tutorial on data minning...i have created a data source ... based on the decision tree algorithm i have even obtained some results..
now.....here is the problem..

i'd like to know if i can actually get all these obtained patterns onto a webpage...
i mean can i actually use asp.net n achieve this task of migrating the patterns generated at the bids to a webpage?

please guys if i can do so...then do tell me how to do so...
my proj dline is in 2 weeks....i need desperate help....
'm waitin...
thxxxx... a ton
hanish

i'd like to code in c#...so plzz tell me a way out of this prob.....|||

if you dump your results into a table you can report against it using .net tools like OWC (i. e. FrontPage, Excel, RS).

Also, here is the link to the article on how to build a model dynamically:

http://www.aspnetpro.com/newsletterarticle/2004/10/asp200410ri_l/asp200410ri_l.asp

|||

my task is to illustrate data minning using asp.net as the front end and SQL server 2005 entp.as back end.....

BIDS will take care of all the data minning operations that i need to perform...and will generate reports corresponding to various data minning models.......

now i intend to create a UI using asp.net(c# codin.) and then link these web-pages to the already obtained reports.....can i do it without having the user open BIDS?

plzzzzzz plzzzz guys help me.....

thx.....

|||

Included with SQL Server as a sample are the sample Data Mining web viewers - I think this should give you what you need. You can see them in action by launching the sample from here http://www.sqlserverdatamining.com/DMCommunity/LiveSamples/52.aspx

Also you can render your results as a report using the example here:

http://blogs.msdn.com/jamiemac/archive/2006/06/22/642541.aspx

|||hello Hanish,,,
i need decision tree code in c#,if u have plz help me.........
nd reply me at innocent_desire_89@.hotmail.com,waitng 4 ur reply
tcsql

Monday, March 26, 2012

Image upload problem into database

Hi guys,

I'm currently trying to insert image into my SQL db. I have tried a number of methods that were posted online, and so far with no luck.

My current code reads:


Dim conn As New Data.SqlClient.SqlConnection()
conn.ConnectionString = ConfigurationManager.ConnectionStrings("MainDBConnection").ToString
conn.Open()

Dim cmd As New Data.SqlClient.SqlCommand("SP_SAVEImage", conn)

cmd.CommandType = Data.CommandType.StoredProcedure

Dim nUserID As New Data.SqlClient.SqlParameter("@.nUserID", Data.SqlDbType.Int)
nUserID.Value = "1"

Dim nAlbumID As New Data.SqlClient.SqlParameter("@.nAlbumID", Data.SqlDbType.Int)
nAlbumID.Value = "1"

Dim sDescription As New Data.SqlClient.SqlParameter("@.sDescription", Data.SqlDbType.VarChar, 50)
sDescription.Value = "image1"

Dim sImageName As New Data.SqlClient.SqlParameter("@.sImageName", Data.SqlDbType.VarChar, 50)
sImageName.Value = sImageName

Dim sImageType As New Data.SqlClient.SqlParameter("@.sImageType", Data.SqlDbType.VarChar, 50)
sImageType.Value = fileType

Dim sImageData As New Data.SqlClient.SqlParameter("@.sImageData", Data.SqlDbType.Image, uploadedFile.Length)
sImageData.Value = uploadedFile

cmd.Parameters.Add(nUserID)
cmd.Parameters.Add(nAlbumID)
cmd.Parameters.Add(sDescription)
cmd.Parameters.Add(sImageName)
cmd.Parameters.Add(sImageType)
cmd.Parameters.Add(sImageData)

Dim reader1 As Data.SqlClient.SqlDataReader

reader1 = cmd.ExecuteReader

Running through debug, everything runs up until the last line, where an error is caught saying : Failed to convert parameter value from a SqlParameter to a String

I reckon it's to do with the input sImageData being input as a byte array - but I can't seem to find a way around it.Angry


Any help greatly appreciated!!

Dim sImageName As New Data.SqlClient.SqlParameter("@.sImageName", Data.SqlDbType.VarChar, 50)
sImageName.Value = sImageName

You are setting an SqlParameter equal to a string value. Must be a typeo. Fix and retry.

|||

THANK YOU!!!!!!

I feel such an idiot now!! I've been looking at this code for so long I couldn't see the obvious.

I had honestly just given up on the idea of saving my data this way; but decided to check the post before going to bed - I can sleep well now knowing at least some of my code works! lol.

Cheers mate

Wednesday, March 21, 2012

IMAGE FIELD & Incremental population

Hi guys,
I'm doing some experiments with the Full Text Retrieval functionalities offered
by SQL-Server. I'm going to store documents in IMAGE fields to leverage the indexing capabilities of MS-Search service and there're some point which are not clear to me.
I want to use the incremental indexing (Timestamp-based or Change tracking) but in BOL it's stated that "changes made with WRITETEXT and UPDATETEXT are not detected".
I've a table where FT is enabled on some text fields (varchar(n)) and on an IMAGE field where the document content is stored.
Change Tracking & Update Index in background are enabled on this test table.
If the IMAGE field is loaded when the indexing on the other fields has been already performed, no change is detected and the IMAGE field is not indexed (loading is perfomed using textcopy.exe which use WRITETEXT).
Forcing the insert of all FT fields at the same time (i.e. same transaction), they are all indexed.
Unfortunately there're situations in which the doc. body is updated (e.g. new doc. version). The only way I found out to obtain the re-indexing of IMAGE field is the following: after the IMAGE update, I also update one of the other text field with FT enab
led.
It's a fake update: the field is "updated" with its current content. In this way the record is "marked" as changed and MS-Search indexes the IMAGE field too.
Of couse I can start a full population but this is not an option in a production environment.
I'm wondering which is the clean way to handle this situation.
How can I be sure that all the fields of a record have been indexed ?
Can I signal to MS-Search that a record must be re-indexed ?
Many thanks
Max
I think you have the cleanest solution to this problem.
There is a way of logging every record that is indexed/reindexed, but there
is a slight performance penaly to pay for this and then figuring out which
record is being indexed is also difficult.
Hilary Cotter
Looking for a book on SQL Server replication?
http://www.nwsu.com/0974973602.html
"MadMax" <MadMax@.discussions.microsoft.com> wrote in message
news:0C589D14-E149-4F7D-BE23-779E2E1D9380@.microsoft.com...
> Hi guys,
> I'm doing some experiments with the Full Text Retrieval functionalities
offered
> by SQL-Server. I'm going to store documents in IMAGE fields to leverage
the indexing capabilities of MS-Search service and there're some point which
are not clear to me.
> I want to use the incremental indexing (Timestamp-based or Change
tracking) but in BOL it's stated that "changes made with WRITETEXT and
UPDATETEXT are not detected".
> I've a table where FT is enabled on some text fields (varchar(n)) and on
an IMAGE field where the document content is stored.
> Change Tracking & Update Index in background are enabled on this test
table.
> If the IMAGE field is loaded when the indexing on the other fields has
been already performed, no change is detected and the IMAGE field is not
indexed (loading is perfomed using textcopy.exe which use WRITETEXT).
> Forcing the insert of all FT fields at the same time (i.e. same
transaction), they are all indexed.
> Unfortunately there're situations in which the doc. body is updated (e.g.
new doc. version). The only way I found out to obtain the re-indexing of
IMAGE field is the following: after the IMAGE update, I also update one of
the other text field with FT enabled.
> It's a fake update: the field is "updated" with its current content. In
this way the record is "marked" as changed and MS-Search indexes the IMAGE
field too.
> Of couse I can start a full population but this is not an option in a
production environment.
> I'm wondering which is the clean way to handle this situation.
> How can I be sure that all the fields of a record have been indexed ?
> Can I signal to MS-Search that a record must be re-indexed ?
> Many thanks
> Max
>

Image data read from SQL Server does not show up

Hi Guys,

I've been strugling with this problem all morning today.

Basically I store images in SQL Server 2000 database and then whould like to show them with


<img src="http://pics.10026.com/?src=viewImage.aspx?image_id=10" border=1>

My table structure is setup this way


TABLE [userImages] (
[imageFilename] [nvarchar] (128) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[imageContentType] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[imageFileSize] [bigint] NULL ,
[imageFileImage] [image] NULL )

and in viewImage.aspx I have:


if (dr.Read())
{

Response.ContentType = dr.GetString(dr.GetOrdinal("imageContentType"));
Response.BinaryWrite( (byte[]) dr["imageFileImage"] );
}

I have no prolems retrieving the data from DB. But the image does not display(in IE it shows a broken link image)

What's even more puzzling is I CAN display the same image from HDD like so:


FileStream fs = File.OpenRead("D:\\my_image.png");
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
fs.Close();

Response.ContentType = "application/octet-stream";
Response.BinaryWrite(buffer);

Am I missing something very obvious. I tried playing around with different ContentType's same result.

In my case I am forced to store images in the DB.

I've seen other examples on the net and theirs work. Please help.

Sincerely,
Vlad OrlovskyI found code very similar to yours in an article written by Dave Wanta:Retrieving Images from a Database ( C# ) - Part II

I adapted the code slightly to display the logo from the pub_info table in the Pubs database, and it worked fine for me (code below).

My gut feeling is that the ContentType you are using might not be correct?


using System;
using System.Collections;
using System.Configuration;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace CSharpTest
{
public class ViewImage : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
//build our query statement
string sqlText = "SELECT logo, 'image/gif' AS contenttype FROM pub_info WHERE pub_id = @.pub_id ";
SqlConnection connection = new SqlConnection( "server=(local);database=pubs;Trusted_Connection=yes");
SqlCommand command = new SqlCommand( sqlText, connection);
command.Parameters.Add(new SqlParameter("@.pub_id", SqlDbType.Char,4)).Value=Request.QueryString["img"];

//open the database and get a datareader
connection.Open();
SqlDataReader dr = command.ExecuteReader();

if ( dr.Read()) //yup we found our image
{
Response.ContentType = dr["contenttype"].ToString();
Response.BinaryWrite( (byte[]) dr["logo"] );
}
connection.Close();

}
}
}

Terri