What is Heisenbug?

As a QA, Heisenbug has been a trouble for me. In response to a reported crash, the developer would say that he can’t reproduce the bug. The software is working fine at developers’ machines. But same bug is appearing at QAs’ machine regularly. These are real testing times for a QA. If the steps to reproduce etc are mentioned accurately, then most probably the bug is Heisenbug.

Now the question is : What is Heisenbug? The Heisenbug falls under a class of software bugs that are considered exceptionally difficult to understand and repair.

A heisenbug (named after the Heisenberg Uncertainty Principle) is a software bug that disappears or alters its characteristics when an attempt is made to study it. Heisenberg’s Uncertainty Principle states, “it is fundamentally impossible to predict the position and momentum of a particle at the same time”.

One common example is a bug that occurs in a program that was compiled with an optimizing compiler, but not in the same program when compiled without optimization (e.g., for generating a debug-mode version). Another example is a bug caused by a race condition. A heisenbug may also appear in a system that does not conform to the command-query separation design guideline, since a routine called more than once could return different values each time, generating hard-to-reproduce bugs in a race condition scenario.

One common reason for heisenbug-like behaviour is that executing a program in debug mode often cleans memory before the program starts, and forces variables onto stack locations, instead of keeping them in registers. These differences in execution can alter the effect of bugs involving out-of-bounds member access or incorrect assumptions about the initial contents of memory. Another reason is that debuggers commonly provide watches or other user interfaces that cause additional code (such as property accessors) to be executed, which can, in turn, change the state of the program. Yet another reason is a fandango on core, the effect of a pointer running out of bounds. In C++, many heisenbugs are caused by uninitialized variables.

So if something is working on developer’s machine but not at staging/QA environment/server, then look around carefully, it might be a heisenbug.

Difference between ID and Class – CSS

Yesterday one of my colleagues(a fresher) asked me difference between ID and class – CSS selectors. I explained him basic difference but he was still curious so I googled a bit about this. Believe me, I didn’t know all the differences between ID and Class. So I tried to sum up the difference between CSS ID and Class. I hope these will be helpful to you.

  1. Id begin with “#” and Class begin with “.”
    For example ID is #newID
    {width:100px;}
    Class is .newClass
    {width:200px;}
  2. ID is unique but Class is not
    This is known to most of as a hard coded rule but few of us know the exact meaning of this. It simply implies that in case of ID ‘Each element can have only one ID’ and ‘Each page can have only one element with that ID’ where in case of Class ‘You can use the same class on multiple elements’ and ‘You can use multiple classes on the same element’.
    For example ID < div ID=”newID”> </div>
    Class < div ID=”newClass”> </div>
    < div ID=”newClass”> </div>
    < div ID=”newClass”> </div>
  3. Browsers are equally compatible with ID and Class
    At times, we have a project working perfectly OK by using IDs where as same functionality don’t works on some other project where we used classes. As a fresher, my first thought on these scenarios was that class is causing problem and I would convert all the classes to ID. But, over the years, I learned that replacing ID with class(and vice versa) don’t helps, provided you were earlier using these correctly.
  4.  An element can have both: ID and Class
    An element can have both ID and Class but ID have higher preference over class.
    For example < div class=”redBackgroundColor” id=”grayBackgroundColor”> </div>
    In this case the background color of div will be gray

A commonly asked question is ‘What if I used an ID twice on a page. Will application crash or something’. The answer is that the application don’t behaves abnormally but it won’t pass the CSS Validation which is a must for all the websites for good ranking on search engines
Also if we have to use JavaScript for any element, then we have to enforce unique ID for element otherwise typescript won’t work as JavaScript methods(e.g. getElementById) won’t be picking up the correct element.

Now the real question, Should one use ID or Class ? . The answer to this question is simple, for the information that will be reused on should use class and for the information that is unique(and will not be reused) use an ID
For example, class should be used for tablerows, table cells etc. ID should be used for header, footer etc and for elements that are to be accessed in JavaScript.

UNION Vs UNION ALL – Sql Server

The difference between Union and Union All if one of the things which not only confuse amateurs but also veterans.Although they both appears to be similar as both are used to club together the data from different sets but hey are quite dissimilar based on result and the performance.

UNION: UNION returns the unique data from different sets joined using the UNION. It removes duplicate rows.

UNION ALL: UNION ALL returns whole data from different sets . It don’t removes duplicates

Example: Create two tables CSS and JavaScript by using the sql server queries listed below

CREATE TABLE CSS
(ID INT,
firstName VARCHAR(50)
)

CREATE TABLE JavaScript
(ID INT,
firstName VARCHAR(50)
)

INSERT INTO CSS(ID, firstName) VALUES(1,’Bob’)
INSERT INTO CSS(ID, firstName) VALUES(2,’Smith’)
INSERT INTO CSS(ID, firstName) VALUES(3,’Randy’)
INSERT INTO CSS(ID, firstName) VALUES(4,’Nate’)
INSERT INTO JavaScript(ID, firstName) VALUES(1,’Bob’)
INSERT INTO JavaScript(ID, firstName) VALUES(2,’Patrice’)
INSERT INTO JavaScript(ID, firstName) VALUES(3,’Nate’)
INSERT INTO JavaScript(ID, firstName) VALUES(4,’Alex’)
INSERT INTO JavaScript(ID, firstName) VALUES(5,’Rammy’)

UNION:
SELECT * FROM CSS
UNION
SELECT * FROM JavaScript

The result would be:

Union in SQL Server - As I Had It

Union in SQL Server


The result returned has 8 rows and none of the rows is duplicate

UNION ALL:
SELECT * FROM CSS
UNION ALL
SELECT * FROM JavaScript

The result would be:

The result returned has rows and it has duplicate row(row with firstName as Bob)

Union All in SQL Server - As I Had It

Union All in SQL Server


Notes:
1. For Union or Union All, it is mandatory that all the involved tables have exactly same number of columns. The tables CSS and JavaScript used above have 2 columns each.
2. The datatypes of the columns of involved tables should be same(in the order of the columns), otherwise the implicit data type conversions will cause queries to return error. To handle the error, we will have to do explicit data type conversions

SELECT COL1, CONVERT(VARCHAR(23), COL2, 121) AS COL2 FROM T1
UNION ALL
SELECT COL1, CAST(COL2 AS VARCHAR(10)) FROM T2

From performance viewpoint, UNION ALL is superior to UNION. It is because UNION has to remove the duplicate rows. So one should use UNION only at places where input tables contain duplicate rows and the programmer is not supposed to display duplicate data. It is used by programmers because they do not understand the difference between these two operators

The difference in performance can be seen by having at look at the sql server execution plan of the queries used above(for tables named CSS and JavaScript):

SQL Server execution plan Union Vs Union All

Union Vs Union All execution plan


Here we see that UNION is quite costly as compared to UNION ALL because UNION has taken up 73% cost where as UNION ALL consumed only 23% cost. The extra burden in case of UNION is due to sorting the data and removing duplicates from the result set.
So we should always try that we use UNION only when its absolutely required. Otherwise UNION ALL is a better option, it gives faster results.

Inner Join VS Intersect in SQL Server

Last week I was working on reporting. QA team logged a bug that was not getting reproduced on development environment. First I reviewed the code at development, but was unable to figure the reason of count mismatch with details. Then I got the code reviewed by one of my seniors. He suggested me to replace inner join with intersect in a couple of conditions. I, till that day, used to this consider inner join and intersect as similar. But to my amazement both are completely different. So sharing my findings about difference between inner join and intersect:

Let’s have 2 different tables and we want the distinct rows which are common in both the tables what will we do to get them? Most of us will answer that they will use INNER JOIN to get the common rows of two tables, right? Wrong!!!!!!

This is a big misconception that INNER JOIN will always return all the common rows between two tables. In reality, INNER JOIN treats two NULLS as two different values rather than a same value so if you are joining a row based on a NULLable column there is a chance that if both tables have NULLs in that column then INNER JOIN will ignore those rows because

Two NULLs are not same in TSQL

To correctly retrieve all common rows between two tables, SQL Server 2005 has introduced the INTERSECT keyword. INTERSECT treats two NULLs as a same value and it returns all rows which are common in both the tables.
Additionally INNER JOIN retrieves all the records from the left table and all the records from the right table. Carefully observing we can notice many of the records as duplicate records. When INNER JOIN is used it gives us duplicate records, but that is not in the case of INTERSECT operator.
The duplicate records in UNION can be removed by using DISTINCT clause in SELECT statement. DISTINCT removes the duplicate rows and final result is exactly same in INTERSECT. In this way, INNER JOIN can simulate with INTERSECT when used with DISTINCT.

The results of an UPDATE statement are undefined if the statement includes a FROM clause that is not specified in such a way that only one value is available for each column occurrence that is updated (in other words, if the UPDATE statement is not deterministic). For example, given the UPDATE statement in the following script, both rows in table s meet the qualifications of the FROM clause in the UPDATE statement, but it is undefined which row from s is used to update the row in table t.

There aren’t many articles comparing performance between the two (UNION and INTERSECT) because they’re meant to substitute one for the other. INTERSECT is meant to find the distinct values combining two queries. That’s a very different goal than the INNER JOIN which is not finding distinct values, but values that simply match between two tables, derived or otherwise.

As a matter of fact, it’s worse than that since the INTERSECT operation requires that the values returned by both queries match in data type, so you couldn’t even do a normal INNER JOIN operation between disparate tables using INTERSECT.

But with similar data intersect takes a little less effort

How many pages/posts can a WordPress handle?

So you are starting a new blog and just like every new blogger you are damn sure that you are gonna hit 1 million posts quickly. The first question that pops up in your mind is – How many pages/posts can a WordPress handle? Will WordPress be able to handle millions of posts or pages without any impact on page load speed / performance?
And the answer is – Theoretically, the WordPress can hold the forte and won’t slow down even with infinite number of pages/posts. WordPress is a simple and very efficient CMS. The problem could actually lie with the hardware on which you have installed your WordPress blog. WordPress can hold unlimited number of posts/pages provided the hardware supports it with sufficient processing speed and memory allocation.

The other player is this is MySQL. MySQL is designed to handle tons of data. So it never slows down wordpress after just a million posts unless and until MySQL is mis-configured(or the sql queries are not optimized)

The typical hardware recommended for efficient wordpress based blog is :
for smaller/newer WordPress with hundreds of visitors monthly …. shared hosting
for medium sized WordPress with thousands of visitors monthly …. VPS hosting
for large sized WordPress with thousands of visitors daily …. dedicated hosting

So the conclusion is, WordPress is a awesome Content Management System(CMS) and there is no need to doubt it for performance. Just make sure that MySQL is properly configured and hardware components are in line with the WordPress traffic requirements.