Search Results

Search found 1215 results on 49 pages for 'robert memo'.

Page 1/49 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Why is Robert C. Martin called Uncle Bob?

    - by Lernkurve
    Is there a story behind it? I did a Google search for "Why is Robert C. Martin called Uncle Bob?" but didn't find an answer. More context There is this pretty well-know person in the software engineering world named Robert C. Martin. He speaks at conferences and has published many excellent books one of which is Clean Code (Amazon). He is the founder and CEO of Object Mentor Inc. Robert C. Martin is also called Uncle Bob. But I can't figure out why.

    Read the article

  • Tutoriel Enyo : partie 2, article de Robert Kowalski traduit par vermine

    Je vous propose une traduction de l'article Enyo Tutorial: Part 2 de Robert Kowalski qui fait suite à la partie 1 sur le framework JavaScript Enyo. Robert Kowalski se lance dans une série de tutoriels dont le but est de nous faire découvrir pas à pas le fonctionnement d'Enyo. L'objectif de ce deuxième article est de rendre réutilisable la calculatrice de pourboire et de montrer l'aspect modulaire du framework. Cet article abor...

    Read the article

  • Tutoriel Enyo : partie 1, article de Robert Kowalski traduit par vermine

    Je vous propose une traduction de l'article Enyo Tutorial: Part 1 de Robert Kowalski qui traite, vous l'aurez compris, du framework JavaScript Enyo. Ce dernier est un framework pour ordinateurs de bureau et pour mobiles qui utilise JavaScript et HTML5. Robert Kowalski se lance dans une série de tutoriels dont le but est de nous faire découvrir pas à pas le fonctionnement d'Enyo. L'objectif de ce premier article est de concevoir une calculatrice de pourboire et de découvrir les kind.

    Read the article

  • Webcast: Credit Memo Applications Via AutoInvoice

    - by Annemarie Provisero-Oracle
    Webcast: Credit Memo Applications Via AutoInvoice Date: June 18, 2014 at 11:00 am ET, 9:00 am MT, 4:00 pm GMT, 8:30 pm IST This one-hour session is part three of a three part series on AutoInvoice and is recommended for technical and functional users who would like to learn more about applying credit memos using AutoInvoice. We will look at commonly encountered issues when importing credit memos (with and without rules) via AutoInvoice, troubleshooting methods and related diagnostic tools. Topics will include: Commonly encountered issues Troubleshooting Related diagnostic tools Details & Registration: Doc ID 1671946.1

    Read the article

  • Dr. Robert Ballard: Special Guest at Java Strategy Keynote Sunday

    - by Tori Wieldt
    Dr. Robert Ballard, famed explorer who found the Titanic at its final resting place, will be at the Java Strategy Keynote on Sunday. Among the most accomplished and well known of the world's deep-sea explorers, Dr. Ballard is best known for his historic discoveries of hydrothermal vents, the sunken R.M.S. Titanic, the German battleship Bismarck, and numerous other contemporary and ancient shipwrecks around the world. During his long career he has conducted more than 120 deep-sea expeditions using the latest in exploration technology, and he is a pioneer in the early use of deep-diving submarines. You can learn more about Dr. Ballard and undersea exploration at National Geographic and TED. The first 1,000 people to arrive at the JavaOne Keynote hall on Sunday will receive a copy of Dr. Ballard's TV show "The Alien Deep" on Blu-Ray. The Alien Deep explores the sea, thousands of feet beneath the surface, far from the first crack of light, where the planet’s last and greatest secrets hide in the cold darkness of endless night. Viewers get to see underwater worlds via submersible where no one has gone before. The JavaOne Strategy Keynote is on Sunday at 4:00pm PT at Masonic Auditorium, 1111 California Street. See you there!

    Read the article

  • How do I extract data from a FoxPro memo field using .NET?

    - by Madhu kiran
    Hi, I'm writing a C# program to get FoxPro database into datatable everything works except the memo field is blank or some strange character. I'm using C# .Net 2.0. I tried the code posted by Jonathan Demarks dated Jan 12. I am able to get the index but i don't know how to use this index to fetch the data from memo file. Pleaese help me. Thanks Madhu

    Read the article

  • How to use Excel VBA to extract Memo field from Access Database?

    - by the.jxc
    I have an Excel spreadsheet. I am connecting to an Access database via ODBC. Something along then lines of: Set dbEng = CreateObject("DAO.DBEngine.40") Set oWspc = dbEng.CreateWorkspace("ODBCWspc", "", "", dbUseODBC) Set oConn = oWspc.OpenConnection("Connection", , True, "ODBC;DSN=CLIENTDB;") Then I use a query and fetch a result set to get some table data. Set oQuery = oConn.CreateQueryDef("tmpQuery") oQuery.Sql = "SELECT idField, memoField FROM myTable" Set oRs = oQuery.OpenRecordset The problem now arises. My field is a dbMemo because the maximum content length is up to a few hundred chars. It's not that long, and in fact the value I'm reading is only a dozen characters. But Excel just doesn't seem able to handle the Memo field content at all. My code... ActiveCell = oRs.Fields("memoField") ...gives error Run-time error '3146': ODBC--call failed. Any suggestions? Can Excel VBA actually get at memo field data? Or is it just completely impossible. I get exactly the same error from GetChunk as well. ActiveCell = oRs.Fields("memoField").GetChunk(0, 2) ...also gives error Run-time error '3146': ODBC--call failed. Converting to a text field makes everything work fine. However some data is truncated to 255 characters of course, which means that isn't a workable solution.

    Read the article

  • "Agile Principles, Patterns, and Practices in C#": Is this just a .NET-translation of the popular Uncle Bob book?

    - by Louis Rhys
    I found this book sold on Amazon Agile Principles, Patterns, and Practices in C#, written by Robert C Martin and Micah Martin. Is it merely a .NET port of the older, more popular Agile Software Development, Principles, Patterns, and Practices? Or is it just a new book trying to take advantage of the other book's popularity? If I am a .NET developer who hasn't read either book, which one would you recommend?

    Read the article

  • How to read FoxPro Memo with PHP?

    - by sHiRoKKo
    I have to convert .DBF and .FPT files from Visual FoxPro to MySQL. Right now my script works for .DBF files, it opens and reads them with dbase_open() and dbase_get_record_with_names() and then executes the MySQL INSERT commands. However, some fields of these .DBF files are of type MEMO and therefore stored in a separate files ending in .FPT. How do I read this file? I have found the specifications of this filetype in MSDN, but I don't know how I can read this file byte-wise with PHP (also, I would really prefer a simplier solution). Any ideas?

    Read the article

  • Sourcecode for Paymentroll example in Robert C. Martin book

    - by bitbonk
    Throughout the book "Agile Principles, Patterns, and Practices in C#" by Robert C. Martin a small Paymentroll application is build. While most of the source code is printed in place, some classes are missing and some are incomplete. The book says on the firest page: The book includes many source code examples that are also available for download from the authors' Web site. Unfortunately this seems to be a lie. Unless either this is not the author's website (the book forgets to mention the authors website adress) or I am blind. Does anyone have the comlete source code for that book preferably in form of a Visual Studio project or knows where I can find it.

    Read the article

  • Question About Example In Robert C Martin's _Clean Code_

    - by Jonah
    This is a question about the concept of a function doing only one thing. It won't make sense without some relevant passages for context, so I'll quote them here. They appear on pgs 37-38: To say this differently, we want to be able to read the program as though it were a set of TO paragraphs, each of which is describing the current level of abstraction and referencing subsequent TO paragraphs at the next level down. To include the setups and teardowns, we include setups, then we include the test page content, and then we include the teardowns. To include the setups, we include the suite setup if this is a suite, then we include the regular setup. It turns out to be very dif?cult for programmers to learn to follow this rule and write functions that stay at a single level of abstraction. But learning this trick is also very important. It is the key to keeping functions short and making sure they do “one thing.” Making the code read like a top-down set of TO paragraphs is an effective technique for keeping the abstraction level consistent. He then gives the following example of poor code: public Money calculatePay(Employee e) throws InvalidEmployeeType { switch (e.type) { case COMMISSIONED: return calculateCommissionedPay(e); case HOURLY: return calculateHourlyPay(e); case SALARIED: return calculateSalariedPay(e); default: throw new InvalidEmployeeType(e.type); } } and explains the problems with it as follows: There are several problems with this function. First, it’s large, and when new employee types are added, it will grow. Second, it very clearly does more than one thing. Third, it violates the Single Responsibility Principle7 (SRP) because there is more than one reason for it to change. Fourth, it violates the Open Closed Principle8 (OCP) because it must change whenever new types are added. Now my questions. To begin, it's clear to me how it violates the OCP, and it's clear to me that this alone makes it poor design. However, I am trying to understand each principle, and it's not clear to me how SRP applies. Specifically, the only reason I can imagine for this method to change is the addition of new employee types. There is only one "axis of change." If details of the calculation needed to change, this would only affect the submethods like "calculateHourlyPay()" Also, while in one sense it is obviously doing 3 things, those three things are all at the same level of abstraction, and can all be put into a TO paragraph no different from the example one: TO calculate pay for an employee, we calculate commissioned pay if the employee is commissioned, hourly pay if he is hourly, etc. So aside from its violation of the OCP, this code seems to conform to Martin's other requirements of clean code, even though he's arguing it does not. Can someone please explain what I am missing? Thanks.

    Read the article

  • Using scroll on one memo edit to scroll on another as well

    - by Nathan Koop
    I've got two memoedits which are similar (in order to compare two records) I would like to keep the scrolling in synch to ease comparison. I had originally thought there would be an OnScroll event, but didn't see one, nor anything similar, the closest I saw was Spin, this handles some possibilities, but not all. I also didn't see a way to navigate the rows. I did see the ScrollToCaret method, but this doesn't do what I want. Any ideas?

    Read the article

  • F# - Facebook Hacker Cup - Double Squares

    - by Jacob
    I'm working on strengthening my F#-fu and decided to tackle the Facebook Hacker Cup Double Squares problem. I'm having some problems with the run-time and was wondering if anyone could help me figure out why it is so much slower than my C# equivalent. There's a good description from another post; Source: Facebook Hacker Cup Qualification Round 2011 A double-square number is an integer X which can be expressed as the sum of two perfect squares. For example, 10 is a double-square because 10 = 3^2 + 1^2. Given X, how can we determine the number of ways in which it can be written as the sum of two squares? For example, 10 can only be written as 3^2 + 1^2 (we don't count 1^2 + 3^2 as being different). On the other hand, 25 can be written as 5^2 + 0^2 or as 4^2 + 3^2. You need to solve this problem for 0 = X = 2,147,483,647. Examples: 10 = 1 25 = 2 3 = 0 0 = 1 1 = 1 My basic strategy (which I'm open to critique on) is to; Create a dictionary (for memoize) of the input numbers initialzed to 0 Get the largest number (LN) and pass it to count/memo function Get the LN square root as int Calculate squares for all numbers 0 to LN and store in dict Sum squares for non repeat combinations of numbers from 0 to LN If sum is in memo dict, add 1 to memo Finally, output the counts of the original numbers. Here is the F# code (See code changes at bottom) I've written that I believe corresponds to this strategy (Runtime: ~8:10); open System open System.Collections.Generic open System.IO /// Get a sequence of values let rec range min max = seq { for num in [min .. max] do yield num } /// Get a sequence starting from 0 and going to max let rec zeroRange max = range 0 max /// Find the maximum number in a list with a starting accumulator (acc) let rec maxNum acc = function | [] -> acc | p::tail when p > acc -> maxNum p tail | p::tail -> maxNum acc tail /// A helper for finding max that sets the accumulator to 0 let rec findMax nums = maxNum 0 nums /// Build a collection of combinations; ie [1,2,3] = (1,1), (1,2), (1,3), (2,2), (2,3), (3,3) let rec combos range = seq { let count = ref 0 for inner in range do for outer in Seq.skip !count range do yield (inner, outer) count := !count + 1 } let rec squares nums = let dict = new Dictionary<int, int>() for s in nums do dict.[s] <- (s * s) dict /// Counts the number of possible double squares for a given number and keeps track of other counts that are provided in the memo dict. let rec countDoubleSquares (num: int) (memo: Dictionary<int, int>) = // The highest relevent square is the square root because it squared plus 0 squared is the top most possibility let maxSquare = System.Math.Sqrt((float)num) // Our relevant squares are 0 to the highest possible square; note the cast to int which shouldn't hurt. let relSquares = range 0 ((int)maxSquare) // calculate the squares up front; let calcSquares = squares relSquares // Build up our square combinations; ie [1,2,3] = (1,1), (1,2), (1,3), (2,2), (2,3), (3,3) for (sq1, sq2) in combos relSquares do let v = calcSquares.[sq1] + calcSquares.[sq2] // Memoize our relevant results if memo.ContainsKey(v) then memo.[v] <- memo.[v] + 1 // return our count for the num passed in memo.[num] // Read our numbers from file. //let lines = File.ReadAllLines("test2.txt") //let nums = [ for line in Seq.skip 1 lines -> Int32.Parse(line) ] // Optionally, read them from straight array let nums = [1740798996; 1257431873; 2147483643; 602519112; 858320077; 1048039120; 415485223; 874566596; 1022907856; 65; 421330820; 1041493518; 5; 1328649093; 1941554117; 4225; 2082925; 0; 1; 3] // Initialize our memoize dictionary let memo = new Dictionary<int, int>() for num in nums do memo.[num] <- 0 // Get the largest number in our set, all other numbers will be memoized along the way let maxN = findMax nums // Do the memoize let maxCount = countDoubleSquares maxN memo // Output our results. for num in nums do printfn "%i" memo.[num] // Have a little pause for when we debug let line = Console.Read() And here is my version in C# (Runtime: ~1:40: using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace FBHack_DoubleSquares { public class TestInput { public int NumCases { get; set; } public List<int> Nums { get; set; } public TestInput() { Nums = new List<int>(); } public int MaxNum() { return Nums.Max(); } } class Program { static void Main(string[] args) { // Read input from file. //TestInput input = ReadTestInput("live.txt"); // As example, load straight. TestInput input = new TestInput { NumCases = 20, Nums = new List<int> { 1740798996, 1257431873, 2147483643, 602519112, 858320077, 1048039120, 415485223, 874566596, 1022907856, 65, 421330820, 1041493518, 5, 1328649093, 1941554117, 4225, 2082925, 0, 1, 3, } }; var maxNum = input.MaxNum(); Dictionary<int, int> memo = new Dictionary<int, int>(); foreach (var num in input.Nums) { if (!memo.ContainsKey(num)) memo.Add(num, 0); } DoMemoize(maxNum, memo); StringBuilder sb = new StringBuilder(); foreach (var num in input.Nums) { //Console.WriteLine(memo[num]); sb.AppendLine(memo[num].ToString()); } Console.Write(sb.ToString()); var blah = Console.Read(); //File.WriteAllText("out.txt", sb.ToString()); } private static int DoMemoize(int num, Dictionary<int, int> memo) { var highSquare = (int)Math.Floor(Math.Sqrt(num)); var squares = CreateSquareLookup(highSquare); var relSquares = squares.Keys.ToList(); Debug.WriteLine("Starting - " + num.ToString()); Debug.WriteLine("RelSquares.Count = {0}", relSquares.Count); int sum = 0; var index = 0; foreach (var square in relSquares) { foreach (var inner in relSquares.Skip(index)) { sum = squares[square] + squares[inner]; if (memo.ContainsKey(sum)) memo[sum]++; } index++; } if (memo.ContainsKey(num)) return memo[num]; return 0; } private static TestInput ReadTestInput(string fileName) { var lines = File.ReadAllLines(fileName); var input = new TestInput(); input.NumCases = int.Parse(lines[0]); foreach (var lin in lines.Skip(1)) { input.Nums.Add(int.Parse(lin)); } return input; } public static Dictionary<int, int> CreateSquareLookup(int maxNum) { var dict = new Dictionary<int, int>(); int square; foreach (var num in Enumerable.Range(0, maxNum)) { square = num * num; dict[num] = square; } return dict; } } } Thanks for taking a look. UPDATE Changing the combos function slightly will result in a pretty big performance boost (from 8 min to 3:45): /// Old and Busted... let rec combosOld range = seq { let rangeCache = Seq.cache range let count = ref 0 for inner in rangeCache do for outer in Seq.skip !count rangeCache do yield (inner, outer) count := !count + 1 } /// The New Hotness... let rec combos maxNum = seq { for i in 0..maxNum do for j in i..maxNum do yield i,j }

    Read the article

  • Tulsa SharePoint Interest Group – SharePoint 2010 Mini-Launch Event - Review

    - by dmccollough
    The Tulsa SharePoint Interest Group set a record for attendance last night at our SharePoint 2010 Mini-Launch Event. Approximately 40+ people showed up to listen to SharePoint MVP Eric Shupps, The SharePoint Cowboy to discuss all of the new features for both administrators and developers. All of the Tulsa SharePoint Interest Group Officers worked very hard to ensure that this event happened. We hosted our event at our local Dave & Busters and it was a great location with good food and great service. All of the officers of the Tulsa SharePoint Interest Group would like to extend a big Thank You to all of our sponsor that helped us in making our SharePoint 2010 Mini-Launch Event a reality.

    Read the article

  • Internet Hall of Fame : les pionniers d'Internet récompensés, Richard Stallman et Robert Meltcafe reconnus à leur juste valeur

    L'internet society place dans son hall of fame les hommes et les femmes qui ont façonné Internet de ses débuts à aujourd'hui Richard Stallman et Robert Meltcafe reconnus à leur juste valeurInternet. Le réseau des réseaux par excellence. Aujourd'hui, faire ses achats en ligne, jouer à des jeux en réseaux, « tchatcher » avec ses amis sur les réseaux sociaux sont des acquis. Cependant, beaucoup ne se doutent même pas que pour en arriver là, des étapes ont été franchies, des hommes et des femmes ont du donner de leur temps, de leur énergie et même de leur personne pour qu'internet soit ce réseau qui rend service à plus d'un aujourd'hui.Beaucoup ? Mais pas tous. Le 3 août, Berlin sera le siège d'un événement ...

    Read the article

  • Why don't I have write permission to my vmware virtual network device?

    - by Robert Martin
    I want to allow my VMWare machine to force the virtual network it's on into promiscuous mode so I can play around with honeyd. I received an error message that told me to go to http://vmware.com/info?id=161 to allow this behavior. Based on their advice, I did: $ groupadd promiscuous $ cat /etc/group | grep promiscuous promiscuous:x:1002:robert $ usermod -a -G promiscuous robert $ id robert uid=1000(robert) gid=1000(robert) groups=1000(robert),....,1002(promiscuous) $ chgrp newgroup /dev/vmnet8 $ chmod g+rw /dev/vmnet8 $ ls -l /dev/vmnet8 crw-rw---- 1 root promiscuous 119, 8 2012-03-29 10:29 /dev/vmnet8 Looks like I gave RW permission to the promiscuous group, and added myself. Except that VMWare still gives me an error message that says I cannot enter promiscuous mode. To try out the group thing, I tried: $ echo "1" >/dev/vmnet8 bash: /dev/vmnet8: Permission denied That really surprised me: It makes me think that I still haven't properly given myself the correct permissions... What am I missing?

    Read the article

  • Why C/C++ have memory issue?

    - by LinuxNewbie
    I have read lots of programmers saying and writing when programming in C/C++ there are lots of issue related to memory. I am planning to learn to program in C/C++. I have beginner knowledge of C/C++ and I want to see some short sample why C/C++ can have issues with memory management. Please Provide some samples.

    Read the article

  • Use jQuery to get values of dropdownlists in an html table column for each row

    - by Arnold
    Hi All, I have a requirement to build a simple html table of memos. The table consists of n-rows each with 2 columns: (1) a dropdownlist of types of memos and (2) the text of a memo - a textbox. I have successfully implemented jQuery to allow the user to Add a new row. That entails the selecting of a type of memo and then typing something into the textbox. I've also implemented jQuery to allow the user to mark a memo row for deletion. This is a partial view and the Save is handled by a container page. Requirements stipulate that there can be only one type of memo in the table. What I would like to be able to do is this: When the user clicks the Add button to add a new row (after having selected the memo type and entered some text into the textbox) I want the code to first examine each row in the table getting the value for each memo type dropdownlist. If the newly entered dropdownlist value is the same as one previously entered, I want to abort the add row process. Requirements also stipulate that all dropdownlists remain enabled to allow the user to change the memo type at any time. Similarly, I would like to be able to scan the table checking to see if that same memo type has already been entered. What would the jQuery look like for this kind of validation? Thanks! Arnold

    Read the article

  • Javscript closure questions

    - by Shuchun Yang
    While I was reading the book Javascript: The Good Parts. I can not understand the piece of code bellow: We can generalize this by making a function that helps us make memoized functions. The memoizer function will take an initial memo array and the fundamental function. It returns a shell function that manages the memo store and that calls the fundamental function as needed. We pass the shell function and the function's parameters to the fundamental function: var memoizer = function (memo, fundamental) { var shell = function (n) { var result = memo[n]; if (typeof result !== 'number') { result = fundamental(shell, n); memo[n] = result; } return result; }; return shell; }; We can now define fibonacci with the memoizer, providing the initial memo array and fundamental function: var fibonacci = memoizer([0, 1], function (test, n) { return test(n - 1) + test(n - 2); }); My question is what is the test function? When does it get defined and invoked? It seems very confusing to me. Also I think this statement: memo[n] = result; is useless. Please correct if I am wrong.

    Read the article

  • Hello Operator, My Switch Is Bored

    - by Paul White
    This is a post for T-SQL Tuesday #43 hosted by my good friend Rob Farley. The topic this month is Plan Operators. I haven’t taken part in T-SQL Tuesday before, but I do like to write about execution plans, so this seemed like a good time to start. This post is in two parts. The first part is primarily an excuse to use a pretty bad play on words in the title of this blog post (if you’re too young to know what a telephone operator or a switchboard is, I hate you). The second part of the post looks at an invisible query plan operator (so to speak). 1. My Switch Is Bored Allow me to present the rare and interesting execution plan operator, Switch: Books Online has this to say about Switch: Following that description, I had a go at producing a Fast Forward Cursor plan that used the TOP operator, but had no luck. That may be due to my lack of skill with cursors, I’m not too sure. The only application of Switch in SQL Server 2012 that I am familiar with requires a local partitioned view: CREATE TABLE dbo.T1 (c1 int NOT NULL CHECK (c1 BETWEEN 00 AND 24)); CREATE TABLE dbo.T2 (c1 int NOT NULL CHECK (c1 BETWEEN 25 AND 49)); CREATE TABLE dbo.T3 (c1 int NOT NULL CHECK (c1 BETWEEN 50 AND 74)); CREATE TABLE dbo.T4 (c1 int NOT NULL CHECK (c1 BETWEEN 75 AND 99)); GO CREATE VIEW V1 AS SELECT c1 FROM dbo.T1 UNION ALL SELECT c1 FROM dbo.T2 UNION ALL SELECT c1 FROM dbo.T3 UNION ALL SELECT c1 FROM dbo.T4; Not only that, but it needs an updatable local partitioned view. We’ll need some primary keys to meet that requirement: ALTER TABLE dbo.T1 ADD CONSTRAINT PK_T1 PRIMARY KEY (c1);   ALTER TABLE dbo.T2 ADD CONSTRAINT PK_T2 PRIMARY KEY (c1);   ALTER TABLE dbo.T3 ADD CONSTRAINT PK_T3 PRIMARY KEY (c1);   ALTER TABLE dbo.T4 ADD CONSTRAINT PK_T4 PRIMARY KEY (c1); We also need an INSERT statement that references the view. Even more specifically, to see a Switch operator, we need to perform a single-row insert (multi-row inserts use a different plan shape): INSERT dbo.V1 (c1) VALUES (1); And now…the execution plan: The Constant Scan manufactures a single row with no columns. The Compute Scalar works out which partition of the view the new value should go in. The Assert checks that the computed partition number is not null (if it is, an error is returned). The Nested Loops Join executes exactly once, with the partition id as an outer reference (correlated parameter). The Switch operator checks the value of the parameter and executes the corresponding input only. If the partition id is 0, the uppermost Clustered Index Insert is executed, adding a row to table T1. If the partition id is 1, the next lower Clustered Index Insert is executed, adding a row to table T2…and so on. In case you were wondering, here’s a query and execution plan for a multi-row insert to the view: INSERT dbo.V1 (c1) VALUES (1), (2); Yuck! An Eager Table Spool and four Filters! I prefer the Switch plan. My guess is that almost all the old strategies that used a Switch operator have been replaced over time, using things like a regular Concatenation Union All combined with Start-Up Filters on its inputs. Other new (relative to the Switch operator) features like table partitioning have specific execution plan support that doesn’t need the Switch operator either. This feels like a bit of a shame, but perhaps it is just nostalgia on my part, it’s hard to know. Please do let me know if you encounter a query that can still use the Switch operator in 2012 – it must be very bored if this is the only possible modern usage! 2. Invisible Plan Operators The second part of this post uses an example based on a question Dave Ballantyne asked using the SQL Sentry Plan Explorer plan upload facility. If you haven’t tried that yet, make sure you’re on the latest version of the (free) Plan Explorer software, and then click the Post to SQLPerformance.com button. That will create a site question with the query plan attached (which can be anonymized if the plan contains sensitive information). Aaron Bertrand and I keep a close eye on questions there, so if you have ever wanted to ask a query plan question of either of us, that’s a good way to do it. The problem The issue I want to talk about revolves around a query issued against a calendar table. The script below creates a simplified version and adds 100 years of per-day information to it: USE tempdb; GO CREATE TABLE dbo.Calendar ( dt date NOT NULL, isWeekday bit NOT NULL, theYear smallint NOT NULL,   CONSTRAINT PK__dbo_Calendar_dt PRIMARY KEY CLUSTERED (dt) ); GO -- Monday is the first day of the week for me SET DATEFIRST 1;   -- Add 100 years of data INSERT dbo.Calendar WITH (TABLOCKX) (dt, isWeekday, theYear) SELECT CA.dt, isWeekday = CASE WHEN DATEPART(WEEKDAY, CA.dt) IN (6, 7) THEN 0 ELSE 1 END, theYear = YEAR(CA.dt) FROM Sandpit.dbo.Numbers AS N CROSS APPLY ( VALUES (DATEADD(DAY, N.n - 1, CONVERT(date, '01 Jan 2000', 113))) ) AS CA (dt) WHERE N.n BETWEEN 1 AND 36525; The following query counts the number of weekend days in 2013: SELECT Days = COUNT_BIG(*) FROM dbo.Calendar AS C WHERE theYear = 2013 AND isWeekday = 0; It returns the correct result (104) using the following execution plan: The query optimizer has managed to estimate the number of rows returned from the table exactly, based purely on the default statistics created separately on the two columns referenced in the query’s WHERE clause. (Well, almost exactly, the unrounded estimate is 104.289 rows.) There is already an invisible operator in this query plan – a Filter operator used to apply the WHERE clause predicates. We can see it by re-running the query with the enormously useful (but undocumented) trace flag 9130 enabled: Now we can see the full picture. The whole table is scanned, returning all 36,525 rows, before the Filter narrows that down to just the 104 we want. Without the trace flag, the Filter is incorporated in the Clustered Index Scan as a residual predicate. It is a little bit more efficient than using a separate operator, but residual predicates are still something you will want to avoid where possible. The estimates are still spot on though: Anyway, looking to improve the performance of this query, Dave added the following filtered index to the Calendar table: CREATE NONCLUSTERED INDEX Weekends ON dbo.Calendar(theYear) WHERE isWeekday = 0; The original query now produces a much more efficient plan: Unfortunately, the estimated number of rows produced by the seek is now wrong (365 instead of 104): What’s going on? The estimate was spot on before we added the index! Explanation You might want to grab a coffee for this bit. Using another trace flag or two (8606 and 8612) we can see that the cardinality estimates were exactly right initially: The highlighted information shows the initial cardinality estimates for the base table (36,525 rows), the result of applying the two relational selects in our WHERE clause (104 rows), and after performing the COUNT_BIG(*) group by aggregate (1 row). All of these are correct, but that was before cost-based optimization got involved :) Cost-based optimization When cost-based optimization starts up, the logical tree above is copied into a structure (the ‘memo’) that has one group per logical operation (roughly speaking). The logical read of the base table (LogOp_Get) ends up in group 7; the two predicates (LogOp_Select) end up in group 8 (with the details of the selections in subgroups 0-6). These two groups still have the correct cardinalities as trace flag 8608 output (initial memo contents) shows: During cost-based optimization, a rule called SelToIdxStrategy runs on group 8. It’s job is to match logical selections to indexable expressions (SARGs). It successfully matches the selections (theYear = 2013, is Weekday = 0) to the filtered index, and writes a new alternative into the memo structure. The new alternative is entered into group 8 as option 1 (option 0 was the original LogOp_Select): The new alternative is to do nothing (PhyOp_NOP = no operation), but to instead follow the new logical instructions listed below the NOP. The LogOp_GetIdx (full read of an index) goes into group 21, and the LogOp_SelectIdx (selection on an index) is placed in group 22, operating on the result of group 21. The definition of the comparison ‘the Year = 2013’ (ScaOp_Comp downwards) was already present in the memo starting at group 2, so no new memo groups are created for that. New Cardinality Estimates The new memo groups require two new cardinality estimates to be derived. First, LogOp_Idx (full read of the index) gets a predicted cardinality of 10,436. This number comes from the filtered index statistics: DBCC SHOW_STATISTICS (Calendar, Weekends) WITH STAT_HEADER; The second new cardinality derivation is for the LogOp_SelectIdx applying the predicate (theYear = 2013). To get a number for this, the cardinality estimator uses statistics for the column ‘theYear’, producing an estimate of 365 rows (there are 365 days in 2013!): DBCC SHOW_STATISTICS (Calendar, theYear) WITH HISTOGRAM; This is where the mistake happens. Cardinality estimation should have used the filtered index statistics here, to get an estimate of 104 rows: DBCC SHOW_STATISTICS (Calendar, Weekends) WITH HISTOGRAM; Unfortunately, the logic has lost sight of the link between the read of the filtered index (LogOp_GetIdx) in group 22, and the selection on that index (LogOp_SelectIdx) that it is deriving a cardinality estimate for, in group 21. The correct cardinality estimate (104 rows) is still present in the memo, attached to group 8, but that group now has a PhyOp_NOP implementation. Skipping over the rest of cost-based optimization (in a belated attempt at brevity) we can see the optimizer’s final output using trace flag 8607: This output shows the (incorrect, but understandable) 365 row estimate for the index range operation, and the correct 104 estimate still attached to its PhyOp_NOP. This tree still has to go through a few post-optimizer rewrites and ‘copy out’ from the memo structure into a tree suitable for the execution engine. One step in this process removes PhyOp_NOP, discarding its 104-row cardinality estimate as it does so. To finish this section on a more positive note, consider what happens if we add an OVER clause to the query aggregate. This isn’t intended to be a ‘fix’ of any sort, I just want to show you that the 104 estimate can survive and be used if later cardinality estimation needs it: SELECT Days = COUNT_BIG(*) OVER () FROM dbo.Calendar AS C WHERE theYear = 2013 AND isWeekday = 0; The estimated execution plan is: Note the 365 estimate at the Index Seek, but the 104 lives again at the Segment! We can imagine the lost predicate ‘isWeekday = 0’ as sitting between the seek and the segment in an invisible Filter operator that drops the estimate from 365 to 104. Even though the NOP group is removed after optimization (so we don’t see it in the execution plan) bear in mind that all cost-based choices were made with the 104-row memo group present, so although things look a bit odd, it shouldn’t affect the optimizer’s plan selection. I should also mention that we can work around the estimation issue by including the index’s filtering columns in the index key: CREATE NONCLUSTERED INDEX Weekends ON dbo.Calendar(theYear, isWeekday) WHERE isWeekday = 0 WITH (DROP_EXISTING = ON); There are some downsides to doing this, including that changes to the isWeekday column may now require Halloween Protection, but that is unlikely to be a big problem for a static calendar table ;)  With the updated index in place, the original query produces an execution plan with the correct cardinality estimation showing at the Index Seek: That’s all for today, remember to let me know about any Switch plans you come across on a modern instance of SQL Server! Finally, here are some other posts of mine that cover other plan operators: Segment and Sequence Project Common Subexpression Spools Why Plan Operators Run Backwards Row Goals and the Top Operator Hash Match Flow Distinct Top N Sort Index Spools and Page Splits Singleton and Range Seeks Bitmaps Hash Join Performance Compute Scalar © 2013 Paul White – All Rights Reserved Twitter: @SQL_Kiwi

    Read the article

  • Macports sudo expands ~ to /var/root in python

    - by calavera
    This might be a bit dev-heavy for the site... but here goes. I installed the macports version of sudo. All is well, except for one thing. Using python 2.6 to expand ~ to the user's home directory results in a different output than the version of sudo that comes with Snow Leopard. For example consider the following python code: #expand_home_dir.py import os os.path.expanduser('~') Below are 3 different calls of the code listed above. The first call using sudo is using the Macports version because my $PATH begins with /opt/local/bin: robert$ python2.6 expand_home_dir.py /Users/robert robert$ sudo python2.6 expand_home_dir.py /var/root robert$ /usr/bin/sudo python2.6 expand_home_dir.py /Users/robert Any idea why this is happening?

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >