Archive for January, 2010

[PL] SQLDay 2009 – wspomnień czar

VN:F [1.7.9_1023]
Rating: 5.0/5 (1 vote cast)

Pamiętacie jeszcze konferencję SQLDay 2009? Wrocławski oddział Polskiej Grupy Użytkowników SQL Server (PLSSUG) zorganizował wspaniałą imprezę, na której udało mi się wystąpić w roli prelegenta (wspólnie z Markiem Adamczukiem przedstawiłem prezentację na temat najlepszych praktyk w pracy z procedurami składowanymi).

Poniżej prezentuję film nagrany podczas konferencji (zmontowany oczywiście przez wrocławskich pasjonatów SQL Servera). Ech, to był dzień, jakich mało!

A już niebawem szykujcie się na serię wydarzeń poświęconych SQL Server 2008 R2 w całej Polsce. Startujemy już w marcu!

[PL] Chcesz zobaczyć świetną sesję z TechEd Europe 2009 (i to po polsku!)?

VN:F [1.7.9_1023]
Rating: 0.0/5 (0 votes cast)

Jeżeli na pytanie z tytułu tej notki odpowiesz sobie TAK, to koniecznie odwiedź portal VirtualStudy.pl. Już dziś wystartowała tam rejestracja na sesję online (w technologii Live Meeting), którą poprowadzi Paula Januszkiewicz, a która będzie zatytułowana Techniki hakerskie użyteczne dla administratora IT (oryginalny tytuł w języku angielskim: Useful Hacker Techniques: Which Part of HackersKnowledge Will Help You in Efficient IT Administration). Sesja ta cieszyła się ogromną popularnością podczas konferencji TechEd Europe 2009 w Berlinie. Dość rzec, że dwukrotnie zabrakło wówczas dla mnie miejsca w sali na około 300 osób…

Kilka informacji o Pauli: ekspert w dziedzinie bezpieczeństwa systemów, niedawno wyróżniona przez firmę Microsoft tytułem Most Valuable Professional (MVP) w kategorii Enterprise Security, założycielka grupy Women in Technology dla kobiet z branży IT i nie tylko, poczytna blogerka, prywatnie przemiła kobieta.

Myślę, że warto zarezerwować sobie poniedziałkowy (1 lutego 2010) wieczór od godziny 20:00 do późnych godzin nocnych (po sesji przewidziana jest debata na tematy: “Czy Administrator powinien mieć pojęcie o bezpieczeństwie?” oraz “Social Networking – dlaczego udostępniamy swoją tożsamość w sieci i co się z tym wiąże?”. Zapowiada się bardzo ciekawie.

Kliknij, by zarejestrować się na spotkanie (trzeba założyć konto na portalu VirtualStudy.pl)

*** Aby uczestniczyć w sesji, należy wcześniej pobrać i zainstalować klienta Live Meeting ***

[EN] SQL Server – An index on a computed column does not prevent computations

VN:F [1.7.9_1023]
Rating: 4.5/5 (2 votes cast)

Last month I observed an interesting behavior of the query optimizer in SQL Server 2008 (this probably can be observed on the previous versions too). The example runs on the AdventureWorks2008 sample database. Consider the following query:

USE AdventureWorks2008;

GO

SELECT

  h.SalesOrderID,

  h.OrderDate,

  c.CustomerID,

  c.AccountNumber

FROM Sales.Customer AS c

INNER JOIN Sales.SalesOrderHeader AS h

ON c.CustomerID = h.CustomerID;

GO

If you look at the execution plan it looks like this:

image 

Well, at first it may seem to be not very interesting. But if you look at the name of the nonclustered index scanned (IX_Customer_TerritoryID index from Sales.Customer table) you may start to wonder: why this individual index was used here? The index has the TerritoryID column as a key, and of course it also contains the CusomerID column since this is a clustered index key. Now, if you notice that the AccountNumber column is computed from CustomerID, then it’s easy to justify the optimizer’s choice (probably IX_Customer_TerritoryID is the smallest index that can be scanned to get all the necessary data from Sales.Customer table in this particular query). But wait! There is an index on the AccountNumber computed column! Why the hell it was not used in this case? Well, let’s try some hint here:

USE AdventureWorks2008;

GO

SET STATISTICS IO ON;

GO

SELECT

  h.SalesOrderID,

  h.OrderDate,

  c.CustomerID,

  c.AccountNumber

FROM Sales.Customer AS c

INNER JOIN Sales.SalesOrderHeader AS h

ON c.CustomerID = h.CustomerID;

GO

SELECT

  h.SalesOrderID,

  h.OrderDate,

  c.CustomerID,

  c.AccountNumber

FROM Sales.Customer AS c WITH (INDEX(AK_Customer_AccountNumber))

INNER JOIN Sales.SalesOrderHeader AS h

ON c.CustomerID = h.CustomerID;

GO

SET STATISTICS IO OFF;

GO

According to the I/O statistics the second query (the one with INDEX hint) reads more pages from the Sales.Customer table than the first query. The cost of both queries is 50% (see below).

image

Looks like a nice sample of the cost-based optimization, doesn’t it? So, even when your computed column is indexed, you can expect the computations to be made anyway in some cases.

[EN] Code Library

VN:F [1.7.9_1023]
Rating: 4.0/5 (1 vote cast)

I’ve just added the Code Library page to my blog. I will put some scripts that I think are useful and/or interesting. The first script you can find there already is a piece of T-SQL code to retrieve some information about database files.

I hope some of the source codes will fit your needs.

[EN] Call for voting – ALTER TYPE in SQL Server

VN:F [1.7.9_1023]
Rating: 0.0/5 (0 votes cast)

Have you ever used an alias type in SQL Server? I bet you have. It’s really cool that you can create your own alias type with CREATE TYPE statement in your database and then use it in your database objects. What drives people to using the alias types is a thought that these types can be easily changed by a single operation which does not require looking into every individual database object and checking whether the alias type is used or not. Well, is this really the way it is? Unfortunately not.

There is no ALTER TYPE statement in SQL Server. So whenever you want to change your own alias type (for example to make it longer in case of variable length character types) you have to perform quite a lot of operations, like:

  • script and drop (or alter to make independent of the “altered” alias type) all procedural objects that use the “altered” alias type,
  • script and drop all constraints on columns of the “altered” alias type,
  • script and drop all foreign key referencing the columns mentioned above,
  • rename the “altered” alias type,
  • create the new alias type with the new definition and the old name of the “altered” alias type,
  • alter all columns of the “old type” to make them using the new alias type,
  • recreate all dropped objects and constraints,
  • refresh just recreated procedural objects.

That doesn’t look simple, does it? The bad news is that this is not all – you should perform all those operations in a single transaction… The reason is quite obvious – you are going to do some nasty things with the database objects (drops, alters, recreates). It would be bad if the process stopped somewhere in the middle (leaving some objects not restored to their original definitions). So, there is plenty of T-SQL code to write, all with transaction and error handling, dynamic T-SQL, lurking into metadata and so forth.

Unfortunately, there is a bug making all the operation practically impossible to perform in a single transaction in certain scenarios (when you use a table variable with a column of the “altered” alias type). See this item for details:
Deadlock occurs when creating user-defined data type and objects that use it

They promised to fix it in SQL Server 2008 R2. Just can’t wait to check it out (for now it’s not fixed in CTP).

My final point is to encourage you to voting for the item: MSFT-MSO: Support ALTER TYPE. This (ALTER TYPE statement) is something that I really wish to see in the next release of SQL Server. So please, vote for this item to be fixed/implemented. Let me know if you vote. Thanks in advance!

[PL] Styczniowe nominacje MVP

VN:F [1.7.9_1023]
Rating: 0.0/5 (0 votes cast)

MVP Początek roku to nie tylko koniec imprezy sylwestrowej. To także czas nominacji do tytułu Microsoft MVP. Raz na trzy miesiące oczy ludzi mających cokolwiek wspólnego ze społecznościami technologicznymi Microsoft są skierowane na program MVP. Tym razem nominację otrzymały dwie osoby: Grzegorz Stolecki w kategorii SQL Server oraz Marcin Książek w kategorii Team System. Gratulacje dla Grzegorza i Marcina, jak również dla wszystkich renominowanych MVP (cykl nominacji trwa rok, po którym można otrzymać ponowną nominację). Słowa uznania należą się też tym, którzy tym razem nie otrzymali renominacji (szczególnie Michałowi Grzegorzewskiemu). Kto choć raz został nagrodzony tytułem MVP, ten wie, że to wspaniała przygoda i duże wyróżnienie.

Co mogę powiedzieć o nowych MVP? Na pewno niebawem na stronie MVP.pl pojawi się informacja o ich działalności. Ze swojej strony znam bardzo dobrze Grzegorza Stoleckiego. Grzegorz, świeżo upieczony prezes Polskiej Grupy Użytkowników SQL Server (PLSSUG), jest świetnym prelegentem, którego w latach 2008/2009 można było spotkać praktycznie na każdej imprezie społecznościowej, gdzie tylko pojawiała się tematyka związana z systemem MS SQL Server. Prezentacje Grzegorza stoją zawsze na bardzo wysokim poziomie. A co najważniejsze, temu facetowi naprawdę się chce pokazywać ludziom własne doświadczenia w tematyce Business Intelligence. Śmiem twierdzić, że to jeden z największych speców od BI w Polsce (jeśli nie największy). Nie ukrywam, że bardzo się cieszę z nominacji Grzegorza. To kolejna osoba aktywna w ramach grupy PLSSUG, która została MVP. Przy okazji – osobne gratulacje dla renominowanych SQL Server MVP – Marcina Goła, Maćka Pileckiego i Damiana Widery! Mamy już siedmiu SQL Server MVP w Polsce! A zatem poniższe zdjęcie jest już nieaktualne.

Polscy MVP na SQL Day 2009

Polscy SQL Server MVP podczas SQL Day 2009 we Wrocławiu (od góry od lewej):
Maciek Pilecki, Damian Widera, Marcin Szeliga, Paweł Potasiński, Marcin Goł i Marek Adamczuk

Jeżeli znasz kogoś, kto według Ciebie zasługuje na tytuł Microsoft MVP, nie wahaj się zgłosić jego kandydatury. Wyślij maila do Alessandro Teglia (na jego blogu znajduje się formularz kontaktowy) z firmy Microsoft.

Więcej o programie MVP oraz o polskich MVP znajdziesz na stronie www.mvp.pl.