Transact SQL :: Returning Non Indexed Records From Sorted Table - Speed Same As Indexed?

Dec 1, 2015

I have created a table from another table where I specified that one of the fields, an number field,  is sorted in ascending order and have NOT specified that it is to be an indexed field and there are 10 million records, from 1 to 10,000,000 exactly.

Now, if I query that table, asking to return records 1-1,000 from that non indexed number field that I sorted in ascending order (where number field <= 1,000) , will it run as fast as if it were indexed?

In other words, does SQL know somehow that these records are sorted in ascending order and so will not do a full table scan, stopping at 1,000 to return my data set?

Or is there no way for SQL to know this and only specifying an indexed field allows SQL to know that its in some order and so it doesn't have to do the full scan?

View 15 Replies


ADVERTISEMENT

Transact SQL :: How To Optimize A View That Can't Be Indexed

Jul 17, 2015

I have a view that takes 14 mins to return 3000 rows.  At some points in the execution plan, there are over 4 million rows.  The query for the View has a Distinct, a couple columns are populated by functions, there is a cross join, there is a join on a table with no keys or index, joins on non-key varchar columns and so forth.  It looks a bit like this:

SELECT DISTINCT
TOP 100 PERCENT N.Id, N.CountyName, N.OperationName,
N_LO.Name, N_LO.LastName,N_LO.Address1,
N_TO.Name, N_TO.LastName,
dbo.fn_Sections(N.Shape, s.Points) AS Sections

[code]...

The DISTINCT is in there to get rid of the extra Bob rows, because Bob has many sizes.  I need to keep the multiple sizes on Bob's row, but I don't want multiple rows of Bob.  Is there a more efficient way to do that other than using DISTINCT?

Second, word on the street is that functions are best avoided if you are going for speed.  I don't see a way to use "FOR XML PATH" outside the function, because I can't get it to work on just one column.  So I am looking for a way to produce the multiple values on one row.

View 12 Replies View Related

Insert Into Big Indexed Table

Mar 12, 2002

Hello!

I need to insert 30 times daily 50000 rows into 13-month invoice big table tb_Invoce

The table has 15 columns.
4 of them are indexed (1 clustered)
The table is heavily queried.
I want to minimize insertion time and minimize time of table locked.
What is the best algorithm for inserting?


Thanks a lot

View 1 Replies View Related

Insert Into Indexed Table

Jul 20, 2005

Hi I have a huge table with over 100million records and on regularbasis ineed to delete nearly a million records and insert a millionrecords.Currently I delete indexes before going through the process andrecreate the indexes which takes a very very long time.IS there a way to disable indexes and re enable them after doinginsert and delete by reindexing or anything of that sort?ORIs there an approach to append two tables with similar indexes?Please air you opinior, will mean a lot to me.Thnaks

View 1 Replies View Related

Truncate On An Indexed Table

Apr 1, 2008

Hi All,

I had a situation today where I needed to truncate a table. It has an index on it.
When I truncate it directly, it takes hardly a minute but when I drop the existing index on that table and then truncate, it takes ages. I am not able to comprehend the exact reason. Can anybody explain?

Thanks in advance.

View 2 Replies View Related

SOS - Table Partitions Or Indexed Views.

Feb 26, 2008

Hi Experts,

We have a very huge database that stores 12 years of data(120 Million records). But our application mainly accesses past 3 years data i.e , the queries would scan the 120 million records even when it actually has to scan 30 million records alone (for 3 years).

Since few other important applications needs access to all the 12 years data, we are in a position to have 12 years data in the same database.

Right now we are looking for an approach that would help us to efficiently access the 3 years data alone and boost the performance.

1. Will SQL server table paritioning help in this scenario ?

Or

2. Indexed views would help us ? Is it possible to create indexed views based on year range and access the views in the stored procedures ?

Any help would be greatly appreciated.

Thanks in advance,

Hariarul

View 4 Replies View Related

Create An Indexed View And Replicate To Table

Mar 20, 2008

All,

I have a huge problem to solve.

1) Need to create an Indexed View that joins multiple tables.I know how to create a regular View, but How do I create an Indexed View ?

2)Need be able to replicate the Indexed View [above] across to another server B into a table.

I have to get this done and seriously don't know where to start.

Do HELP me out .Thank You.

View 2 Replies View Related

Can I Add A Foriegn Key On A Indexed View To Reference Other Table

Nov 8, 2006

Is there anybody familiar with indexed view here?

Can I add a foriegn key on a indexed view to reference other table?

Thanks!

View 1 Replies View Related

SQL Server 2012 :: Query To Search Full-text Indexed Table And Return Results

Apr 19, 2014

I have written this sample query to search a full-text indexed table and return the results. If the word occurs more than once I want it to return as a new record and the results show a short summary of the location. I was using 'like', but the full table scans were really slowing it down. Can performance be improved for the following (The results returned by my query are accurate)

Query

DECLARE @searchString nvarchar(255);
DECLARE @searchStringWild nvarchar(275);

SET @searchString = 'first';
SET @searchStringWild = UPPER('"' +@searchString+ '*"');

SELECT id, '...' + SUBSTRING(searchResults.MatchedCell, searchResults.StartPosition, searchResults.EndPosition - searchResults.StartPosition) + '...' as Result

[Code] ....

View 2 Replies View Related

Error (8626) While Inserting Record Into Table With Text Field And Which Is The Base For Indexed View

Mar 14, 2006

I have a problem with inserting records into table when an indexed viewis based on it.Table has text field (without it there is no problem, but I need it).Here is a sample code:USE testGOCREATE TABLE dbo.aTable ([id] INT NOT NULL, [text] TEXT NOT NULL)GOCREATE VIEW dbo.aViewWITH SCHEMABINDING ASSELECT [id], CAST([text] AS VARCHAR(8000)) [text]FROM dbo.aTableGOCREATE TRIGGER dbo.aTrigger ON dbo.aView INSTEAD OF INSERTASBEGININSERT INTO aTableSELECT [id], [text]FROM insertedENDGODo the insert into aTable (also through aView).INSERT INTO dbo.aTable VALUES (1, 'a')INSERT INTO dbo.aView VALUES (2, 'b')Still do not have any problem. But when I need index on viewCREATE UNIQUE CLUSTERED INDEX [id] ON dbo.aView ([id])GOI get following error while inserting record into aTable:-- Server: Msg 8626, Level 16, State 1, Procedure aTrigger, Line 4-- Only text pointers are allowed in work tables, never text, ntext, orimage columns. The query processor produced a query plan that requireda text, ntext, or image column in a work table.Does anyone know what causes the error?

View 1 Replies View Related

Over Indexed?

Apr 24, 2008

what do u think about a table that has 19 indexes and some of them are covering index?

View 3 Replies View Related

INDEXED

Jan 5, 2006

hi all,

In the properties of the table in the MS Access there is an Indexed column. If someone would had set that to "Yes (Duplicates Ok)" how can one implement this to MSSQL???

View 7 Replies View Related

Indexed Fields

Jun 22, 2000

I have a table with three fields that are marked as indexed fields with unique keys. I want
to remove one of the fields. When I do this and hit the rebuild button -- I get an error, that
there is a duplicate field, so it will not just let me remove the one field and leave the other
two?? How can I get around this?

View 2 Replies View Related

Indexed View

Jan 10, 2002

Hi All,

I have over 100 views in a database. How can I check which view we used indexed view?

Thanks.

View 2 Replies View Related

Indexed View

Jan 11, 2002

Hi All,

I have over 100 views in a database. I created non-clustered index on views. Now I need to check out which views have index.

How can I check which views we created as indexed views?

Thank you very much.

View 2 Replies View Related

Indexed View

Oct 19, 2004

Hi

I am trying toe create an indexed view but cannot seem to get it right.

CREATE VIEW dbo.D_Policy_View with schemabinding
AS
SELECT Policy_ID, Environment_Code, CoB, Sub_CoB, Policy_No, Version_No
FROM dbo.D_Policy
WHERE (Policy_ID IN
(SELECT MAX(Policy_ID)
FROM dbo.d_Policy
GROUP BY Environment_Code, COB, Policy_No, SUB_COB))

I have read on BoL that MAX is not allowed but don't know of any other way to get the latest record??

please help :confused: :mad: :eek:

View 4 Replies View Related

Indexed Views

Jan 28, 2005

Hello,
I'm currently performance tuning a table with 100 million rows in it
(about 18 GB of data) and would like to know if -

1. Is the table too large to be performance tuned. Is it better to just
redesign the schema ?
2. Can using techniques as indexed views really help me with tuning such a table.
3. How long would it take to create a clustered, non clustered index on
a varchar column (for instance) on a table with 100 million rows ?
(i know this is a function of hardware as well - let's assume i'm using
afairly maxed out DL 360 - i.e. dual processor with 4 GB of memory)

Thank you very much
Alan

View 14 Replies View Related

Indexed Views

Mar 9, 2005

I am looking for a little insight. I am using an SQL Server database created by a third party vendor. There are certain columns in a given table that I query for quite often. To speed things up, I created an indexed view.

Now I can no longer insert into the base table. Attempting an insert causes a SQL error stating that the system properties ARITHABORT and NUMERIC_ROUNDABORT are incorrect. If I remove the index from my view, the inserts work just fine.

Can somebody provide some insight as to why this happens and how I might be able to correct it (keep in mind that the DB was setup by a third party, so I cannot change too much of the underlying setup without possibly compromising their functionality).

View 7 Replies View Related

Indexed View???

Mar 9, 2004

Hi,

I have a problem trying to create an indexed view on SQL Server 2000. There are multiple databases, one of which stores system wide data. I would like to create an indexed view on the system wide data for each of the site databases.

Is it possible to create an indexed view on data in another database?

Cheers

View 1 Replies View Related

Indexed Views

Apr 3, 2008

Hi,

I am trying to create an indexed view, but because I am using a MAX function, I get the error

Cannot create index on view "dbo.View" because it uses aggregate "MAX". Consider eliminating the aggregate, not indexing the view, or using alternate aggregates. For example, for AVG substitute SUM and COUNT_BIG, or for COUNT, substitute COUNT_BIG.

Am totally stuck on how I can replace the MAX function.

Any help would be appreciated.


SET ANSI_NULLS ON
GO
SET ANSI_PADDING ON
GO
SET ANSI_WARNINGS ON
GO
SET CONCAT_NULL_YIELDS_NULL ON
GO
SET NUMERIC_ROUNDABORT OFF
GO
SET QUOTED_IDENTIFIER ON
GO
SET ARITHABORT ON
GO

CREATE VIEW [dbo].[View]
WITH SCHEMABINDING
AS

SELECT TOP 100 PERCENT MAX(js_id) AS job_event, job_id
FROM dbo.JobEvent
GROUP BY job_id
ORDER BY job_event
GO

CREATE UNIQUE CLUSTERED INDEX IX_VMaxJobEvent ON View (job_id)



Thanks

View 2 Replies View Related

Indexed View

Jan 11, 2007

snehalata writes "i create view as follows
CREATE VIEW Data
WITH SCHEMABINDING
AS
SELECT A.PartitionID,FundID,ReportDate,ForeignTaxWithheld,DomDividendIncome,RGainShortTerm,RGainLongTerm,NewIssueRGainShortTerm,
NewIssueRGainLongTerm,ChgUnrealizedGain,ReplaceTax,TotIncomeBefFee,TotalIncome,EndingNetCapital,EndingRedemptionUnits,
BeginRedemptionAmount,EndingRedemptionAmount,EndingUnits,InterestOverseas,ExpenseOverseas,OrdIncome,
ReallocationExpense,BeginRedemptionFee,EndingRedFee,BeginGrossCapital,EndingGrossCapital,GPFees,FixedExpense,MergerCost,
SellingCommission,GrossRoR,NAV,GAV,GPMgmtFee,IMMgmtFee,GPIncentivefee,IMIncentivefee,NetRoR,MonthCounter,
BegUnits,BegAddUnits,BegAddAmount,EndAddAmount,GrossRealizedGain,BrokerCommission,
NetRealizedGain,OperatingExpense,OffsellExp,OrgExp,USObligationIncome,FixIncomeIntrIncome,
CapitalGain,SellingFee,SellingMgmtFeeMidQtr,SyndicateCost,BeginNetCapital,DomesticDividendExp,FixedIncomeIntrExp
FROMdbo.vPart1A
LEFT JOIN dbo.vPart2B
ON A.PartitionID= B.PartitionID

then if i creat index as follows

SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
SET ARITHABORT ON
SET CONCAT_NULL_YIELDS_NULL ON
SET QUOTED_IDENTIFIER ON
SET NUMERIC_ROUNDABORT OFF

create unique clustered index ind1 on Data(FundID,ReportDate)
it gives me following error
Cannot index the view 'MonthliesTest2.4.dbo.Data'. It contains one or more disallowed constructs.

why so?"

View 1 Replies View Related

Regarding Indexed Views

Aug 6, 2007

Dear experts,
I've been working for an ERP solutions, company, as a DBA....

we have around 1200 tables as wellas 650 views.....

we are not using clustered index on views.....
using the clustered index will boost the performance? and the ERP is web based application. so that modifications will be done on a regular basis....
is it good thing to implement clustered indexes on these views....

please guide me in this regard


thank you verymuch

Vinod
Even you learn 1%, Learn it with 100% confidence.

View 3 Replies View Related

Some PDF Files Not Indexed

Dec 14, 2006

I am trying to index a large number of PDF files using SQL Server Full Text indexing, and am running into an issue where about 1% of the documents are not being indexed. I looked in the SQL Full Text logs and the following error appears thousands of times:
Error '0x80043651: msftesql should reprocess this document in an isolated fashion to confirm the error.' occurred during full-text index population for table or indexed view '[DocumentWarehouse].[dbo].[Document2006_tbl]' (table or indexed view ID '485576768', database ID '5'), full-text key value 0x00E32429. Attempt will be made to reindex it.

The component 'MSFTE.DLL' reported error while indexing. Component path 'Y:Program FilesMicrosoft SQL ServerMSSQL.1MSSQLBinnMSFTE.DLL'.
Occasionally this warning appears:
Warning: No appropriate filter was found during full-text index population for table or indexed view '[DocumentWarehouse].[dbo].[Document2006_tbl]' (table or indexed view ID '5', database ID '485576768'), full-text key value 0x00FE8A91. Some columns of the row were not indexed.
The problem isn€™t because certain PDF documents can€™t be indexed, because when you reinsert a doc that wasn€™t indexed, it does get indexed.
My version of SQL Server is 9.00.2153.00 running on Windows Server 2003.

View 2 Replies View Related

What Is Indexed View ?

Mar 11, 2008

what does it mean ? Why it is necessary to create/put it ? How do you use it in SQL 2005 or 2000 ?

View 5 Replies View Related

IS Full-text Indexed

Dec 28, 2007

How can (is full-text indexed) property TRUE in column properties in moment create table with right-click on tables and select NEW TABLE?

View 1 Replies View Related

Indexed Views Can Not Have Self-join !!!

Feb 10, 2006

is there any work around this?

View 1 Replies View Related

Update On Indexed Column

Apr 6, 2001

Hi,
I have large table rrsn_security_t - more than half a million rows. I do a complete update on all the rows of the table using the following query.

UPDATE rrsn_security_t
set
cusip = b.fmr_cusip,
master_issuer_num = b.mstr_isr_cusip,
ticker = b.fmr_symb,
description = b.fmr_name,
prim_exchange_code = c.exchange_key,
shares_otstndng = d.amount,
iv_type = b.iv_typ,
active = case when b.deact_date is null then 'Y' else 'N' end
FROM rrsn_security_t a INNER JOIN
ref_security_t b ON
a.security_id = b.fmr_cusip LEFT OUTER JOIN
shares_outstanding_feed_t d ON
b.fmr_cusip = substring(d.fmr_cusip,1,9) AND
d.fmr_type = 'OUTS' LEFT OUTER JOIN
rrs_exchange_t c ON
b.dft_exch_cd = c.exchange_id
where b.fmr_cusip not in (select security_id from rrsn_scrty_ovrrd_in_effect_t)


This is a part of a daily batch load and a DTS package. The table has one clustered index and three non clustered indexes. Two of them are covering indexes. The update is on all the columns that have the non clustered indexes.

The problem is that when I run the update the transaction log runs to more than a GB of memory and alomost takes an hour to do so. Without the index it takes around 300 MB and 7 mins.

I am not confortable with the idea of dropping and recreating the index since it is not necessary in SQL Server 7.0, though it was the case in the previous versions of SQL Server.

Also the query plan with the indexes on shows that Table spool/Eager spool to optimize rewinds takes 50% of the query cost.

Could any one help me with how I should deal with this situation.


Thanks in advance
GV

View 3 Replies View Related

Indexed Views Tbl Requirements

Jan 17, 2003

I had some issues yesterday with the fact that some of the tables I had indexed views for did not have a unique/clustered index. The tables had unique indexes and clustered indexes but not a unique/clustered index. What I was seeing were rows that should have been in the view, not showing up in a regular select but they would showup in a with noexpand hint.

To fix the problem I created a unique/clustered index on each of the underlying table but cannot find that requirement anywhere, is this a requirement and if so can someone tell me where to find it.

Thanks

View 2 Replies View Related

Defrag Indexed Views?

Jul 7, 2004

How do we defrag indexed views? Can any one give me a query to loop thru all the indexed views in the database and find out the fragmentation levels and also defrag them?
Thanks in advance!

View 1 Replies View Related

Indexed Views Error

Oct 17, 2001

I have an indexed view with a clustered index on my database........when I try to run and update statement agaisnt the table that is referenced in the view, I get one of the following errors:

Server: Msg 3624, Level 20, State 1, Line 1

Location: q:SPHINXNTDBMSstorengdrsinclude
ecord.inl:1447
Expression: m_SizeRec > 0 && m_SizeRec <= MAXDATAROW
SPID: 52
Process ID: 414

Connection Broken


Server: Msg 3624, Level 20, State 1, Line 1

Location: recbase.cpp:1371
Expression: m_nVars > 0
SPID: 52
Process ID: 414

Connection Broken


any ideas?

View 2 Replies View Related

Heavily Indexed Databases

Mar 7, 2005

Hi all,
i have a very general question about databases. What is the advantage and disadvantage of using a heavily indexed database?

The advantage i could think is that search operations will be fast. The disadvantage (according to me who is a newbie) is that the size of the database will increase.

My teacher however is not very happy with this answer and wants me to research more. Any help will be greatly appreciated.

Thanks

View 1 Replies View Related

Indexed View Utilization

Aug 1, 2006

I created an indexed view in SQL 2000, and I expected to see the index created on the view referenced in the execution plan when I query the view. Instead, I see the index for the base table referenced in the execution plan. Why?

There are 6,000,000+ records in the base table, and the view only references 256 of these rows.

Here is some of the DDL if you need it:

CREATE TABLE [alarm_t] (
[ct_dtm] [datetime] NOT NULL ,
[dst_flg] [char] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[stn_nm] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[alarm_txt] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[utc_dtm] [datetime] NOT NULL ,
[create_utc_dtm] [datetime] NOT NULL
) ON [PRIMARY]
GO

CREATE CLUSTERED INDEX [alarm_idx2] ON [dbo].[alarm_t]([ct_dtm], [stn_nm], [dst_flg]) ON [PRIMARY]
GO

create view dbo.alarm_Mapbd_v with schemabinding
as
SELECT
[ct_dtm],
[dst_flg],
[stn_nm],
[alarm_txt],
[utc_dtm],
[create_utc_dtm]
FROM [dbo].[alarm_t]
WHERE[stn_nm]= 'Mapbd'
GO

create unique clustered index alarm_Mapbd_idx1 on dbo.alarm_Mapbd_v
( stn_nm, ct_dtm, dst_flg )
go

update statistics alarm_t
go
update statistics alarm_Mapbd_v
go

The following 2 queries have the exact same execution plan, both showing a cost of 50%. I expected to see the index created on the view referenced in the execution plan for the first query. Is the index created on the view being used?

selectstn_nm, ct_dtm, dst_flg
fromalarm_Mapbd_v
go
SELECT
[ct_dtm],
[dst_flg],
[stn_nm],
[alarm_txt],
[utc_dtm],
[create_utc_dtm]
FROM [dbo].[alarm_t]
WHERE[stn_nm]= 'Mapbd'
go

Thanks for your assistance.

Tom

View 1 Replies View Related

Help: Indexed View Question

Dec 11, 2006

I have created a unique clustered index on a view.
The view does a GROUP BY on 3 of the columns and
uses the COUNT_BIG aggregate function.
I used the following SET commands before creating the view and the index:

SET ARITHABORTON
SET CONCAT_NULL_YIELDS_NULL ON
SET QUOTED_IDENTIFIER ON
SET ANSI_NULLSON
SET ANSI_PADDINGON
SET ANSI_WARNINGSON
SET NUMERIC_ROUNDABORTOFF

I can insert and delete rows from the base table, and the indexed view is updated fine.

However, when a scheduled job does effectively the same thing (delete some rows, and insert some new rows) I get the following error:

Executed as user: NT AUTHORITYSYSTEM. DELETE failed because the following SET options have incorrect settings: 'ARITHABORT'. Verify that SET options are correct for use with indexed views and/or indexes on computed columns and/or query notifications and/or xml data type methods. [SQLSTATE 42000] (Error 1934). The step failed.

Why am I getting this error?

The same SET commands above are in the Transact-SQL code for the job before the delete and before the insert statements.

Thanks,
Tom

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved