Conclusion: Tuning a SQL query can be made within different way : modify the physical design for a table indexes, partitioning , influence the optimizer Hints to force an execution plan, modify oracle optimizer database parameters. Leave a Reply Cancel Reply My comment is.. Lazhar Felahi Consultant. This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.
Accept Reject Read More. Close Privacy Overview This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent.
You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience. Necessary Necessary. Necessary cookies are absolutely essential for the website to function properly. If, later on, there is another case to be distinguished e. There are different ways to do this, depending on the programming language we use. In order to differentiate the cases, we define a parent type AllergyTestResult , as well as three sub-types that represent the three cases NotDone , Pending , and Done :.
Note: If you think that the above code is quite verbose and a bit hard to write, then you are not alone. Some modern languages allow us to write conceptually similar code much more succinctly. And null-safe languages distinguish between nullable and non-nullable values in a reliable way at compile-time — there is no need to comment the nullability of a reference or to check whether a reference declared to be non-null has accidentally been set to null.
If we need to know why there is no value associated with a reference, then additional data must be provided to differentiate the possible cases. The first instruction declares a String variable s1 and assigns it the value "foo". The more interesting instruction is the last one. No value is explicitly assigned to s3.
Hence, it is reasonable to ask: What is the state of s3 after its declaration? What will happen if we write s3 to the OS output device? It turns out that the state of a variable or class field declared without assigning a value depends on the programming language. Moreover, each programming language might have specific rules for different cases. For example, different rules apply for reference types and value types, static and non-static members of a class, global and local variables, and so on.
The best option is the last one. As an example, Java applies the last option for local variables. Hence, the following code results in a compile-time error at the second line:. The basic rule is simple: null should only be allowed when it makes sense for an object reference to have 'no value associated with it'.
For example, suppose type person with fields name and dateOfFirstMarriage :. Every person has a name. Field name is non-nullable. It is illegal to assign null to it. On the other hand, field dateOfFirstMarriage doesn't represent a required value. Not everyone is married. Hence it makes sense for dateOfFirstMarriage to have 'no value associated with it'. Therefore dateOfFirstMarriage is a nullable field. If a person's dateOfFirstMarriage field points to null then it simply means that this person has never been married.
There is no way to reliably state that null can never be assigned to a given object reference. In some languages it is possible to use annotations, such as the non-standard annotations Nullable and NonNullable in Java. Here is an example:. However, such annotations are not used by the compiler to ensure null-safety.
Still, they are useful for the human reader, and they can be used by IDEs and tools such as static code analyzers. Consider a function that reads configuration data from a file.
Many languages C , Java, etc. Instead, the function's signature should be changed in order to make it clear that the function might fail:. Allow null only if it makes sense for an object reference to have 'no value associated with it'.
At run-time, the above code results in the infamous null pointer error , because we try to execute a method of a reference that points to null. It is the most frequent bug in many software applications, and has been the cause for countless troubles in the history of software development.
Tony Hoare, the inventor of null , calls it the 'billion-dollar mistake'. But Tony Hoare Turing Award winner in and inventor of the Quicksort algorithm , also gives a hint to a solution in his speech :.
Contrary to some common belief, the culprit is not null per se. The problem is the lack of support for null handling in many programming languages. For example, at the time of writing May , none of the top ten languages in the Tiobe index natively differentiates between nullable and non-nullable types.
Therefore, some new languages provide compile-time null-safety and specific syntax for conveniently handling null in source code. In these languages, the above code would result in a compile-time error. Software quality and reliability increases considerably, because the null pointer error delightfully disappears.
Hence, null pointer errors cannot occur. If this article was helpful, tweet it. Learn to code for free.
Get started. Forum Donate. Introduction null is a fundamental concept in many programming languages. Run-time Implementation Before discussing the meaning of null , we need to understand how null is implemented in memory at run-time. To keep things simple, we will make the following assumptions: The above instruction is executed on a bits CPU with a bits address space.
Strings are encoded as UTF The following picture shows an excerpt of the memory after executing the above instruction: Figure 1: Variable name points to "Bob" The memory addresses in the above picture are chosen arbitrarily and are irrelevant for our discussion. So far so good. And this is the new state in memory: Figure 2: Variable name points to null We can see that nothing has changed for the string "Bob" which is still stored in memory. Remember: If a reference points to null , it simply means that there is no value associated with it.
Performance As we learned in the previous section, operations involving null are extremely fast and easy to perform at run-time. There are only two kinds of operations: Initialize or set a reference to null e.
Check if a reference points to null e. Remember: Operations on null are exceedingly fast and cheap. Reference vs Value Types So far we assumed working with reference types. Remember: The concept of null exists only for reference types. Meaning Suppose we have a type person with a field emailAddress. Not necessarily. Or… Alice has an email address, but: it has not yet been entered in the database it is secret unrevealed for security reasons there is a bug in a routine that creates a person object without setting field emailAddress and so on.
Remember: If a reference points to null then it always means that there is no value associated with it. Why is it null? Sometimes it is important to know why a reference points to null. This is bad data design for multiple reasons. So the function needs to return more information than just a list. Remember: If we need to know why there is no value associated with a reference, then additional data must be provided to differentiate the possible cases. The second instruction assigns null to s2.
As far as I know, the following rules are typical variations encountered: It is illegal to declare a variable without also assigning a value There is an arbitrary value stored in s3 , depending on the memory content at the time of execution - there is no default value A default value is automatically assigned to s3.
In case of a reference type, the default value is null. For example 0 for integer numbers, false for a boolean, and so on. Hence, the following code results in a compile-time error at the second line: String s3;System. In some languages, null is the default value for reference types.
When to Use null And When Not to Use It The basic rule is simple: null should only be allowed when it makes sense for an object reference to have 'no value associated with it'. It is important to note that null should not be used to denote error conditions.
Simply return null? Instead, the function's signature should be changed in order to make it clear that the function might fail: public Config readConfigFromFile File file throws IOException Remember: Allow null only if it makes sense for an object reference to have 'no value associated with it'. The null pointer error is nasty. But Tony Hoare Turing Award winner in and inventor of the Quicksort algorithm , also gives a hint to a solution in his speech : More recent programming languages … have introduced declarations for non-null references.
This is the solution, which I rejected in Null-safety is a fascinating topic that deserves its own article. Remember: Whenever possible, use a language that supports compile-time null-safety.
0コメント