Posts

SQL Server Paging - The Holy Grail

More info on the above see SqlServerCentral Another version:

Interpreting the query plan and speeding it up

Image
Bookmark Lookup - An index was used but as the index does not 'cover' the query the query processor must use the ROWID from the index to 'lookup' the actual data row. Unless the index can be alter to ‘cover’ the columns of the query this cannot be optimised further. Clustered Index Scan - Similar to a table scan (its just that the table has a clustered index) and similarly undesirable, particularly for large tables. If you see these then the columns in the query are either not indexed or the distribution statistics have led the query optimiser to decide the scan is more/ as efficient. Restructuring the query can sometimes eliminate these operations; or add an index. Clustered Index Seek - The clustered index is used to find matching rows. This is optimal behaviour. Compute Scalar - As it says – a scalar is being computed. Unless this is not really needed it can't be optimised. It its not needed, remove it! Constant Scan - The query requires a constan...

MSMQ Best Practices

Performance recommendations Avoid unnecessary database lookups before deciding if a message can be dropped. Prioritization should be given in code for dropping the message as quickly and efficiently as possible. If database lookups are required in deciding if a message can be dropped, can these be cached (with a refresh timeout)? If you are dropping messages, is there a better way to only receive the correct messages? If you are subscribed to an event processor publisher, does that publisher provide any kind of subscription filtering? Filtering can be achieved via database event subscription tables, (a list of subscribers with their input queues, and a list of events each input queue is interested in). Separate event types Publishers should translate event types into separate System.Types, with hierarchies to support grouping. For example, with some kind of  delivery event data, these could be group interfaces such as ProofOfDeliveryGroup, ProofOfCollectionGroup, e...

Stock prediction using Azure Machine Learning

Image
I like dabbling in the stock market, and wondered if artificial intelligence could help predict when I should buy/sell stock. Using one of the FANG stocks (Facebook, Amazon, Netflix, Google) I'll choose Netflix for the purposes of this blog post. Here is what Netflix has done in the last 3 months: The top graph is Fast Stochastics (12,26) As you can see, predicting the future is not easy. So my first step was to not use AI at all, but to write a program to help me decide which values of %K and %D I should use for the Fast Stochastics graph, using the last 5 years of stock history for Netflix. Historical data This can be obtained from Yahoo finance . Change the Time period to 5Y and press Apply. Then click the download data link to obtain your CSV file. Best %K %D Fast Stochastics values for Netflix The program I wrote takes into account that buying stock and selling stock incur a fee, and that the buy and sell values are not the same (bid/ask difference). The...

Calling SQL Server stored procedures from Entity Framework

Using the methods below, you can obtain the stored procedure return value , along with your data, which I've not seen in other blogs. A stored proc should return 0 for success, and any other value for a failure. Here is an example table, filled with data: CREATE TABLE DemoData ( id INT NOT NULL PRIMARY key, someValue DECIMAL(4,4) NOT NULL ) GO INSERT INTO DemoData(id, someValue) VALUES (1, 1.23), (2, 2.34), (3, 3.45), (4, 4.56) Here are our example stored procedures: CREATE PROCEDURE GetDemoData(@maxId INT) AS BEGIN SET NOCOUNT ON; SELECT id, someValue FROM DemoData WHERE id <= @maxId END GO CREATE PROCEDURE AddTwoValues(@a INT, @b INT) AS BEGIN SET NOCOUNT ON; RETURN @a + @b -- Don't do this. Stored procs should return -- 0 for success, and any other value for failure. END GO CREATE PROCEDURE AddTwoValuesWithResult(@a INT, @b INT, @result INT OUTPUT, @result2 INT OUTPUT) AS BEGIN SET NOCOUNT ON; SET @result = @a +...

Pregenerated Views for Entity Framework 6

When Entity Framework starts, it first builds a set of internal views that describes the database in an agnostic way. All further processing (queries, updates etc.) EF does, is performed against these views. Generating views however can be costly and will impact start up time of the application. The startup time for a 1000 table context can be in excess of minutes. However, this can be worked around by generating views at design time by using EFInteractiveViews Nuget Package. It allows you to pre-generate and save the generated views to a file. Neat! Install the Nuget package: https://www.nuget.org/packages/EFInteractiveViews Source code and documentation: https://github.com/moozzyk/EFInteractiveViews

I'm in MSDN Magazine this month :-)

I am in the August 2014 edition of MSDN Magasine, Data Points section. The article is written by Julie Lerman on the EntityFramework Reverse POCO Generator I created. MSDN link: http://msdn.microsoft.com/en-us/magazine/dn759438.aspx