Re: T-SQL is not quite there yet

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



DWalker07 (none@xxxxxxxx) writes:
Thanks for the reply. Please see below.

Well, whereelse would I look? Above? :-)

My assumption is that they piggyback on the output buffer, and it is
a trick that can only be performed once.

So? That can be overcome.

Maybe. But then it would call for a completely different architecture,
which reqiure a lot more work to do. Keep in mind if my assumption is
right, the choice is not really between INSERT-EXEC being possible in
multiple levels or only one; no, the choice is between INSERT-EXEC
being available in one level only, or not at all.

I like to stress that this is quite a lot of speculation on my part.

What is not speculation, however, is that INSERT-EXEC from a program-
mabiliy point of view is a fragile feature. Input-output table-valued
parameters would be the real solution.

In the programming world, entities that take parameters and return
results ought to be called functions, not "stored procedures". Stored
procedures that return data seem to be weird, in my mind. Stored
procedures "feel" like they ought to be limited to macros that do admin-
type stuff, rather than returning results. Of course, I know that's not
how SQL works.

Don't confuse T-SQL with client-side languages. SQL Server is a server-
side application, and needs to return data to the client to be useful.
Returning a result set from a stored procedure is a natural thing to do.
(Yes, I could think of differnt paradigms using TVPs, but we are not
quite there.)

But I have seen huge speedups with temp tables when I have added indexes
to them. Sometimes, even, if logically the indexes can't be unique and
so I had to remove the index and then I cried because I couldn't use the
performance speedup.

I don't dispute that you have seen performance benefits by indexing
temp tables. More than once I have been able to achieve huge performance
gains only by putting keys on temp tables that had none.

But here is a tip: also for temp tables it's better to add indexes up
front. SQL Server 2005 and later, cache temp table definitions, which
is good for performance in a high-load scenario. However, if you add
indexes with CREATE INDEX, this precludes caching.

Why does inserting into a table variable preclude parallelism if the same
is not true of inserting data into a temp table? Or is that also true of
inserting data in to a temporary table?

That's some internal thing that I don't really remember. But it has to
do with that table variables lives in another part the engine than
regular tables.

Many, many Internet blogs (which we all know are not the source of truth)
claim that table variables perform better than temp tables.

Microsoft has touted this as well. But I have been able to make huge
performance gains by replacing a table variable with a temp table. And
vice versa.

And, table variables COULD have statistics if Microsoft wished for it to
be so! If a proc creates a temp table, populates it, uses it, and then
drops it, does it have time to get statistics?

The cheif reason I've gotten performance benefits with table variables
over temp tables is precisely the lack of statistics. No statistics, no
recompiles.

Overall, there are a lot of restrictions with linked servers. For
instance, neither you cannot pass XML over linked servers.

Which is another annoying restriction!

But as I said there is good reason for it. There simply is no infra-
structure available.

I assume a lot of this has to do with that the linked server may not
support these features.

But it MIGHT support these features! And I thought that there were ways
that the local server can ASK the remote server what features it
supports.

There is indeed ways in OLE DB to inquire what the provider supports.
Still I suspect that it is not entirely unproblematic.

Keep in mind that from SQL Server's
perspective, the linked server may be Oracle, MySQL or a home-grown
data source. In fact, I don't think there is any support in OLE DB at
all for table- valued functions, and OLE DB is what SQL Server uses
the access the linked server.

I know that, but I'm not using Oracle, etc.

I got bad news for you: SQL Server is not written for you only.


--
Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

.



Relevant Pages

  • How to find query plan for a stored procedure using temporary tables
    ... This post is related to SQL server 2000 and SQL Server 2005 all ... Many of my stored procedures create temporary tables in the code. ... Invalid object name '#Temp2'. ... My real production procs are hundreds of lines with many temp tables ...
    (comp.databases.ms-sqlserver)
  • Re: Temp files in Stored Procedures
    ... you do need to use SELECT INTO, try to schedule it when your SQL Server is ... server to its knees. ... >> The ideal method is to avoid using temp tables within stored procedures. ...
    (microsoft.public.sqlserver.programming)
  • Re: UDF/SP Editor
    ... I am coming over here to SQL Server from the Oracle world and ... > capabilities, or lack there of, of the editor that is used in SS2K's ... > enterprise manager to construct stored procedures and UDF's. ... CREATE TABLE #temp (orderid int NOT NULL, ...
    (microsoft.public.sqlserver.programming)
  • Row by Row Operations Help req
    ... Create temp table 1 ... Nigel,The cursor question is the SQL equivalent of the GOTOs / NO GOTOs ... question about whether the familiarity of procedural code is worth the ... leverages the strengths of SQL Server and is usually faster since it uses ...
    (microsoft.public.sqlserver.programming)
  • Re: SYS.SQL_DEPENDENCIES, Refresh Dependencies
    ... because you cannot have temp tables in user-defined functions. ... If you are using dependencies to see what you need to migrate from test ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)