<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Gonçalo Melo, Author at Blog IT</title>
	<atom:link href="https://blogit.create.pt/author/goncalomelo/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>Create IT blogger community</description>
	<lastBuildDate>Thu, 13 May 2021 18:32:23 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>
	<item>
		<title>Collaborative work, why and how?</title>
		<link>https://blogit.create.pt/goncalomelo/2021/05/10/collaborative-work-why-and-how/</link>
					<comments>https://blogit.create.pt/goncalomelo/2021/05/10/collaborative-work-why-and-how/#respond</comments>
		
		<dc:creator><![CDATA[Gonçalo Melo]]></dc:creator>
		<pubDate>Mon, 10 May 2021 16:00:32 +0000</pubDate>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Agile]]></category>
		<category><![CDATA[Coollaboration]]></category>
		<category><![CDATA[Ideas]]></category>
		<guid isPermaLink="false">https://blogit.create.pt/?p=12273</guid>

					<description><![CDATA[<p>The work of a collaborative team allows to produce work that is more than the sum of the individual contributions of the team members. Yes, it is important!</p>
<p>The post <a href="https://blogit.create.pt/goncalomelo/2021/05/10/collaborative-work-why-and-how/">Collaborative work, why and how?</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>The work of a collaborative team allows to produce work that is more than the sum of the individual contributions of the team members. Yes, it is important!</p>



<h2 class="wp-block-heading" id="b89a"><strong>How do we know collaboration is happening?</strong></h2>



<p id="83a4">My reflection results from one recent team experience, in a software development context. We worked collaboratively to implement a new feature and after a work session two things about the final result called my attention:</p>



<p id="15b4">1. It was not possible to identify the “owner” of the idea. Everyone said something that contributed to the work produced. It truly belonged to everyone.</p>



<p id="59c9">2. The result we found was better than something I was aware of being able to find.</p>



<p id="2644">It is something I read, heard, and even talked about often. But for me it was good to be able to experience and learn in practice. There are few things that replace practice.</p>



<p id="d9ac">This is basic, it is. I knew that. But for me it was a special moment to be able to feel this energy. At the same time, I look at this and think “how come we don’t always do this?”.</p>



<h2 class="wp-block-heading" id="4332">How collaboration happens?</h2>



<p id="856b">Some simple and practical actions to improve collaborative work.</p>



<h3 class="wp-block-heading" id="4b84"><strong>Accept all contributions</strong></h3>



<p id="f60f">The brain is very quick to identify reasons for not doing anything. Perhaps it is a hidden survival mechanism. As a result, idle is safer than boiling. This is a common place, on the other hand it is differentiating. The process of building on each other’s ideas is one of the critical factors to generate energy that will keep the work session active.</p>



<h3 class="wp-block-heading" id="8b9d"><strong>Feed the ideas that come up</strong></h3>



<p id="dcf4">Initially denying an idea because we see a point we disagree with inhibits collaboration. In other words, the team must be comfortable sharing. A flow of new ideas when each team member builds and contributes on top of each other’s ideas is fantastic. At the end it is not even possible to identify whose final idea is. There is only “us” in the result.</p>



<h3 class="wp-block-heading" id="46a2"><strong>Desire to discover something new</strong></h3>



<p id="bad3">When we restrict ourselves only to what we know, what we can discover will be limited. Dismantle pre-conceived ideas, especially our own. Being open minded to different points of view allows more contributions. It is easy and safe to say no. Take a chance and say why not? Or even better how can we achieve this?</p>



<h2 class="wp-block-heading" id="2ef2">Try It Out</h2>



<p id="55aa">Offer someone the opportunity to share their ideas. These are small but extremely important things, and they are also actionable. They are within everyone&#8217;s reach.</p>
<p>The post <a href="https://blogit.create.pt/goncalomelo/2021/05/10/collaborative-work-why-and-how/">Collaborative work, why and how?</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/goncalomelo/2021/05/10/collaborative-work-why-and-how/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>NoSQL First Act &#8211; a historical introduction</title>
		<link>https://blogit.create.pt/goncalomelo/2019/08/13/nosql-first-act-a-historical-introduction/</link>
					<comments>https://blogit.create.pt/goncalomelo/2019/08/13/nosql-first-act-a-historical-introduction/#respond</comments>
		
		<dc:creator><![CDATA[Gonçalo Melo]]></dc:creator>
		<pubDate>Tue, 13 Aug 2019 17:57:42 +0000</pubDate>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Sql]]></category>
		<category><![CDATA[Cluster]]></category>
		<category><![CDATA[Database history]]></category>
		<category><![CDATA[Database model]]></category>
		<category><![CDATA[Horizontal scale]]></category>
		<category><![CDATA[impedance mismatch]]></category>
		<category><![CDATA[NoSQL]]></category>
		<category><![CDATA[Relational database]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Vertical scale]]></category>
		<guid isPermaLink="false">https://blogit.create.pt/?p=9739</guid>

					<description><![CDATA[<p>NoSQL databases introduction and dominant features. A historical perspective to their appearance in a world dominated by relational model databases.</p>
<p>The post <a href="https://blogit.create.pt/goncalomelo/2019/08/13/nosql-first-act-a-historical-introduction/">NoSQL First Act &#8211; a historical introduction</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>NoSQL gets a lot of &#8220;heat&#8221; about not having a good direct definition. And the term NoSQL only gives somes clues of what this is not. </p>



<p>NoSQL is like a new definition of something that is a database but is different than the usual relational model. Likewise, making a parallel by going back 30 years ago. Back then probably no one knew what a relational database was also. Let&#8217;s use this and start with a small historical and motivational point of view for NoSQL. PS: I was not a developer back then.</p>



<p>This article will be a first part of a series of articles. The goal will be to unite some knowledge about this topic. </p>



<h2 class="wp-block-heading">Starting in the 1980&#8217;s</h2>



<p>Relational databases emerged bringing ACID properties &#8211; Atomicity, Consistency, Isolation and Persistency. Properties taken for granted nowadays. Also, they also brought the SQL language. SQL is common enough across different systems for one to use. Although there are different flavors, can almost be considered a standard.</p>



<p>Relation databases also allowed for a simple and very common integration mechanism between 2 or more systems. Data can be easily shared by reading or writing data in a table on a shared relational database. This is today still a very common integration pattern.</p>



<h2 class="wp-block-heading">In the 1990&#8217;s</h2>



<p>Object database&#8217;s started to appear with more strength. They had been around for some time. Most important, they implement a different database paradigm model. This new paradigm tried to solve the impedance mismatch problem. The impedance mismatch was caused by relational databases. It emerges from the need to map objects used in memory in our application model to tables in a relational database. This page <a href="https://en.wikipedia.org/wiki/Object-relational_impedance_mismatch">https://en.wikipedia.org/wiki/Object-relational_impedance_mismatch</a> is a good reference for this issue.</p>



<p>Saving an application object into these database model should be a direct operation. Conceptually no mapping would be necessary when an object database type was used. Albeit, these gains, object databases were not able to substitute relational databases. </p>



<h2 class="wp-block-heading">In the 2000&#8217;s</h2>



<p>As internet availability grows 2 things started to have a big impact:</p>



<ul class="wp-block-list"><li>Generation of enormous amount of data that had to be stored and processed;</li><li>Accesses from anywhere in the globe became more and more frequent. Therefore latency was an issue to consider. And even speed of light limitation can contribute significantly to this. Data can now be stored far from where we are. For example, a distance of 10.000 km will add about 100 ms on each round trip. Therefore, data needs to spread around the globe to provide a quick access.</li></ul>



<p>In this environment,
relational databases do not always solve customer needs, either because of
flexibility, price or performance issues:</p>



<ul class="wp-block-list"><li>Relational databases enforces a ridged set of rules in the relational model. These will impact the flexibility of the application development;</li><li>Price because of the need for more powerful machines and also the software licenses that go with this;</li><li>Performance, because relational databases do not naturally meet the increasing workload. Huge CPU, memory, storage and throughput is needed to be perform in this environment. And for relational model, vertical scaling can only get you so far.</li></ul>



<h2 class="wp-block-heading">Scaling Vertically versus Horizontally</h2>



<p>Relational databases usual scaling method is a vertical one. As a result whenever the workload incresses we will use a bigger machine with more hardware resources. </p>



<p>On the other hand, the big internet companies adopted an horizontal scaling paradigm. This is a cluster type environment with lots and lots of machines. In other words, this means that more machines will be used to handle bigger workloads.</p>



<p>Relational databases do not thrive very well in this paradigm. They hardly take any benefit of using more machines. Hence, NoSQL like databases arises to take advantage of the horizontal scale paradigm. Also companies like Google and Amazon started researching in this area. As a result, Google created BigTable and Amazon DynamoDB.</p>



<h2 class="wp-block-heading">Relational databases dominated the market, why are NoSQL databases being used now?</h2>



<p>I think this is important. Dominance and usage factors are usually a combination of several aspects. What has been changing:</p>



<ul class="wp-block-list"><li>Developers hide databases behind integration layers. This makes it simpler to use. And in addition, easier to replace one database or persistence method per other; </li><li>Cloud growth in some cases means we can try different approaches with less effort regarding infrastructure;</li><li>Handling big quantities of data introduced new needs. NoSQL provides a good development flexibility. And in addition can also take advantage of cluster solutions.</li></ul>



<p>Finally, what is NoSQL?</p>



<h2 class="wp-block-heading">Common NoSQL databases characteristics</h2>



<p>NoSQL doesn’t have a clear direct meaning. The term alludes to something like &#8220;Not Only SQL&#8221;. A more exact explanation should be &#8220;Non Relational database&#8221;. This would reinforce the new model paradigm and not the SQL language itself. The fact that some NoSQL databases actually supports some form of SQL language adds even more to the confusion.</p>



<p>But, the name is catchy and so common that will probably stay. The point is: defining NoSQL is hard. Therefore, we will do the next best thing. Introduce the dominant traits of these database systems:</p>



<ul class="wp-block-list"><li>Non relational;</li><li>Usually (not all) cluster-friendly;</li><li>Most of them are open source;</li><li>No-schema / schema-less;</li><li>Have a big internet drive (cluster and bigdata friendly).</li></ul>



<p>By these common traits, almost any non relational database can be a NoSQL database! Also, there are probably published studies in all these areas dating back 30 or 40 year ago. Out of curiosity, the name NoSQL itself is referred to being born by the end of 2009. The term emerged as a twitter hashtag for a meetup were people talked about these subjects. Even though some of these traits were not new at the time.</p>



<h2 class="wp-block-heading">Next steps</h2>



<p>NoSQL has a lot to explore. It will provide a more direct paradigm that will make simpler specific needs like this ones to <a href="https://blogit.create.pt////diogoguiomar/2018/02/26/query-a-json-array-column-in-sql/">query Json objects inside Sql Server</a> and <a href="https://blogit.create.pt////goncalomelo/2018/12/20/query-performance-for-json-objects-inside-sql-server/">performance considerations</a>.</p>



<p>My plan for the next article(s) will be to:</p>



<ul class="wp-block-list"><li>Present some of the NoSQL data models; </li><li>Talk about the no schema or the schema less feature;</li><li>Discuss the aggregate concept. And how this relates to the CAP theorem.</li></ul>



<h2 class="wp-block-heading">Further reads</h2>



<p>There is a lot of information online. For me, I like Martin Fowler approach. Some of these information&#8217;s are from his content. You can check his website here: <a href="https://martinfowler.com/nosql.html">https://martinfowler.com/nosql.html</a>. He also has a book: <a href="https://martinfowler.com/books/nosql.html">https://martinfowler.com/books/nosql.html</a>.</p>



<p></p>
<p>The post <a href="https://blogit.create.pt/goncalomelo/2019/08/13/nosql-first-act-a-historical-introduction/">NoSQL First Act &#8211; a historical introduction</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/goncalomelo/2019/08/13/nosql-first-act-a-historical-introduction/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Query performance for JSON objects inside SQL Server using JSON_VALUE function</title>
		<link>https://blogit.create.pt/goncalomelo/2018/12/20/query-performance-for-json-objects-inside-sql-server/</link>
					<comments>https://blogit.create.pt/goncalomelo/2018/12/20/query-performance-for-json-objects-inside-sql-server/#comments</comments>
		
		<dc:creator><![CDATA[Gonçalo Melo]]></dc:creator>
		<pubDate>Thu, 20 Dec 2018 09:39:12 +0000</pubDate>
				<category><![CDATA[Sql Server]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[SQL]]></category>
		<guid isPermaLink="false">https://blogit.create.pt/?p=8077</guid>

					<description><![CDATA[<p>Following up on this article about querying JSON Data I would like to talk about how to improve searches on JSON data inside SQL Server. Starting SQL Server 2016 Microsoft deployed a set of functions that allow us to work with JSON data in a structured way inside SQL Server. I will introduce a small [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/goncalomelo/2018/12/20/query-performance-for-json-objects-inside-sql-server/">Query performance for JSON objects inside SQL Server using JSON_VALUE function</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Following up on <a href="https://blogit.create.pt////diogoguiomar/2018/02/26/query-a-json-array-column-in-sql/">this article about querying JSON Data</a> I would like to talk about how to improve searches on JSON data inside SQL Server. Starting SQL Server 2016 Microsoft deployed a set of functions that allow us to work with JSON data in a structured way inside SQL Server.</p>



<p>I will introduce a small usage sample for the <strong>JSON_VALUE </strong>function in combination with indexes to improve information retrieval from a table containing one JSON object. For our testes, we have a <strong>UserDetailTest </strong>table that has more than 500k rows with 2 columns: an UserId and a nvarchar(max) to hold a small JSON details string like the following:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: sql; title: ; notranslate">
SELECT *, LEN(DetailsJSON) AS &#x5B;Len(DetailsJSON)] FROM UserDetailTest
</pre></div>


<figure class="wp-block-image"><img fetchpriority="high" decoding="async" width="937" height="188" src="https://blogit.create.pt////wp-content/uploads/2018/12/sampleTable.png" alt="" class="wp-image-8153" srcset="https://blogit.create.pt/wp-content/uploads/2018/12/sampleTable.png 937w, https://blogit.create.pt/wp-content/uploads/2018/12/sampleTable-300x60.png 300w, https://blogit.create.pt/wp-content/uploads/2018/12/sampleTable-768x154.png 768w, https://blogit.create.pt/wp-content/uploads/2018/12/sampleTable-696x140.png 696w" sizes="(max-width: 937px) 100vw, 937px" /></figure>



<p>I will activate time statistics and clean SQL Server cache between each query to have some consistency across the execution times using the following SQL statements:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: sql; title: ; notranslate">
CHECKPOINT
DBCC DROPCLEANBUFFERS
SET STATISTICS TIME ON
</pre></div>


<h2 class="wp-block-heading">JSON_VALUE Function intro</h2>



<p>The JSON_VALUE function extracts a value from a JSON string. This functions receives 2 arguments, the first being an expression for the JSON value and the second a path for the value we want to obtain. A simple sample with an inline JSON object would be the following:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: sql; title: ; notranslate">
SELECT JSON_VALUE('{"PostalCode":"376-3765","PhoneNumber":"351003765718"}', '$.PhoneNumber')
</pre></div>


<figure class="wp-block-image"><img decoding="async" width="1245" height="123" src="https://i1.wp.com/blogit.create.pt/wp-content/uploads/2018/12/selectResult0.png?fit=696%2C69&amp;ssl=1" alt="" class="wp-image-8182" srcset="https://blogit.create.pt/wp-content/uploads/2018/12/selectResult0.png 1245w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult0-300x30.png 300w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult0-768x76.png 768w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult0-1024x101.png 1024w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult0-696x69.png 696w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult0-1068x106.png 1068w" sizes="(max-width: 1245px) 100vw, 1245px" /></figure>



<p>The return is a scalar value (nvarchar(4000)) for the PhoneNumber element.</p>



<h2 class="wp-block-heading">Query scenarios</h2>



<p>Starting with one of the <strong>really&nbsp;worst </strong>case scenario (yes, this can happen&#8230;):</p>



<figure class="wp-block-image"><img decoding="async" width="1024" height="240" src="https://blogit.create.pt////wp-content/uploads/2018/12/selectResult20-1024x240.png" alt="" class="wp-image-8197" srcset="https://blogit.create.pt/wp-content/uploads/2018/12/selectResult20-1024x240.png 1024w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult20-300x70.png 300w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult20-768x180.png 768w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult20-696x163.png 696w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult20-1068x250.png 1068w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult20.png 1275w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>More than 17 seconds really seems like a worst scenario! Next, we will use the JSON_VALUE function to get the PhoneNumber from the JSON string and use it in our where clause:</p>



<figure class="wp-block-image"><img decoding="async" width="1266" height="301" src="https://i1.wp.com/blogit.create.pt/wp-content/uploads/2018/12/selectResult22.png?fit=696%2C165&amp;ssl=1" alt="" class="wp-image-8198" srcset="https://blogit.create.pt/wp-content/uploads/2018/12/selectResult22.png 1266w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult22-300x71.png 300w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult22-768x183.png 768w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult22-1024x243.png 1024w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult22-696x165.png 696w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult22-1068x254.png 1068w" sizes="(max-width: 1266px) 100vw, 1266px" /></figure>



<p>This still takes more than 3 seconds. A good improvement, but yet a high cost if we need to search information in this way.</p>



<h2 class="wp-block-heading" id="mce_9">Index creation</h2>



<p>Let&#8217;s add a new virtual column to table that displays the result from the JSON_VALUE function &#8211; this will allow us to create an index and simplify the SELECT queries.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: sql; title: ; notranslate">
ALTER TABLE UserDetailTest 
	ADD vPhoneNumber AS 
	CAST(JSON_VALUE(DetailsJSON, '$.PhoneNumber') AS NVARCHAR(255));
</pre></div>


<p>The cast truncates the output from the JSON_VALUE&nbsp;to ensure that it does not exceed the maximum lenght for the index key. Now, if we search using the column, the result is still more or less the same 3 seconds has before:</p>



<ul class="wp-block-gallery columns-1 is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex"><li class="blocks-gallery-item"><figure><img decoding="async" width="1274" height="311" src="https://i1.wp.com/blogit.create.pt/wp-content/uploads/2018/12/selectResult23.png?fit=696%2C170&amp;ssl=1" alt="" data-id="8199" data-link="https://blogit.create.pt////?attachment_id=8199" class="wp-image-8199" srcset="https://blogit.create.pt/wp-content/uploads/2018/12/selectResult23.png 1274w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult23-300x73.png 300w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult23-768x187.png 768w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult23-1024x250.png 1024w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult23-696x170.png 696w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult23-1068x261.png 1068w" sizes="(max-width: 1274px) 100vw, 1274px" /></figure></li></ul>



<p>Let&#8217;s create an index and perform the search again:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: sql; title: ; notranslate">
CREATE INDEX idx_vPhoneNumber ON &#x5B;UserDetailTest] (vPhoneNumber);

</pre></div>


<ul class="wp-block-gallery columns-1 is-cropped wp-block-gallery-2 is-layout-flex wp-block-gallery-is-layout-flex"><li class="blocks-gallery-item"><figure><img decoding="async" width="1270" height="316" src="https://i1.wp.com/blogit.create.pt/wp-content/uploads/2018/12/selectResult24.png?fit=696%2C173&amp;ssl=1" alt="" data-id="8201" data-link="https://blogit.create.pt////?attachment_id=8201" class="wp-image-8201" srcset="https://blogit.create.pt/wp-content/uploads/2018/12/selectResult24.png 1270w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult24-300x75.png 300w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult24-768x191.png 768w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult24-1024x255.png 1024w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult24-696x173.png 696w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult24-1068x266.png 1068w" sizes="(max-width: 1270px) 100vw, 1270px" /></figure></li></ul>



<p>Consequently the improvement is huge, 13 miliseconds is more interesting! But what&#8217;s the cost?</p>



<h2 class="wp-block-heading">The cost</h2>



<p>When we create an index, we&#8217;re basically trading space for time &#8211; more occupied space versus faster operations. Therefore let&#8217;s see what the increase is using&nbsp;<strong>sp_spaceused</strong> function before and after index creation:</p>



<table class="wp-block-table is-style-regular"><tbody><tr><td></td><td><strong>rows</strong></td><td><strong>reserved</strong></td><td><strong>data</strong></td><td><strong>index_size</strong></td><td><strong>unused</strong></td></tr><tr><td><strong>Initial</strong></td><td>557801              </td><td>1120904 KB</td><td>1115584 KB</td><td>5224 KB</td><td>96 KB</td></tr><tr><td><strong>After Index</strong></td><td>557801</td><td>1148752 KB</td><td>1115584 KB</td><td>32992 KB</td><td>176 KB</td></tr></tbody></table>



<p>Probably, an interesting comparison would be if the PhoneNumber column was an explicit column in that table containing the value. Let&#8217;s do that!</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: sql; title: ; notranslate">
ALTER TABLE UserDetailTest  
	ADD PhoneNumberCopy NVARCHAR(255)

UPDATE UserDetailTest
	SET PhoneNumberCopy = vPhoneNumber
</pre></div>


<p>The sp_spaceused remained the same &#8211; SQL Server internal black magic regarding space allocation (for another time!). But performance wise, for this approach in my machine this query still took more than 2 seconds to complete:</p>



<figure class="wp-block-image"><img decoding="async" width="1269" height="362" src="https://i2.wp.com/blogit.create.pt/wp-content/uploads/2018/12/selectResult26.png?fit=696%2C198&amp;ssl=1" alt="" class="wp-image-8203" srcset="https://blogit.create.pt/wp-content/uploads/2018/12/selectResult26.png 1269w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult26-300x86.png 300w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult26-768x219.png 768w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult26-1024x292.png 1024w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult26-696x199.png 696w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult26-1068x305.png 1068w" sizes="(max-width: 1269px) 100vw, 1269px" /></figure>



<p>Slightly better than the query with the JSON function but the advantage is that in this scenario SQL can better optimize the searches. The following runs of the same query without clearing the cache returns results much faster &#8211; each took around 220 miliseconds to complete:</p>



<figure class="wp-block-image"><img decoding="async" width="1263" height="343" src="https://i2.wp.com/blogit.create.pt/wp-content/uploads/2018/12/selectResult27.png?fit=696%2C189&amp;ssl=1" alt="" class="wp-image-8204" srcset="https://blogit.create.pt/wp-content/uploads/2018/12/selectResult27.png 1263w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult27-300x81.png 300w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult27-768x209.png 768w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult27-1024x278.png 1024w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult27-696x189.png 696w, https://blogit.create.pt/wp-content/uploads/2018/12/selectResult27-1068x290.png 1068w" sizes="(max-width: 1263px) 100vw, 1263px" /></figure>



<h2 class="wp-block-heading">Summary Results</h2>



<p>Just to sum up all the results for the different types of searches comparing the first execution after cache clean up and the following runs.&nbsp;I did several iterations for each step just to make sure the results were consistent&nbsp;although the goal was just to have a baseline. Certanly, the use of this will depend on each case.</p>



<table class="wp-block-table"><tbody><tr><td><strong>WHERE clausule type</strong></td><td><strong>First run</strong></td><td><strong>Following runs</strong></td></tr><tr><td><pre class="brush: sql; gutter: false; title: ; notranslate">WHERE DetailsJson LIKE '%PhoneNumber&quot;:&quot;351003765718&quot;%'</pre></td><td>17754 ms</td><td>around the same</td></tr><tr><td><pre class="brush: sql; gutter: false; title: ; notranslate">WHERE JSON_VALUE(DetailsJson, '$.PhoneNumber') = '351003765718'</pre></td><td>3375 ms</td><td>1958 ms</td></tr><tr><td><pre class="brush: sql; gutter: false; title: ; notranslate">WHERE vPhoneNumber = '351003765718'</pre>vPhoneNumber is not indexed&nbsp;</td><td>3339 ms</td><td>1332 ms</td></tr><tr><td><pre class="brush: sql; gutter: false; title: ; notranslate">WHERE vPhoneNumber = '351003765718'</pre> vPhoneNumber is indexed</td><td>13 ms</td><td>0 ms</td></tr><tr><td><pre class="brush: sql; gutter: false; title: ; notranslate">WHERE PhoneNumberCopy  = '351003765718'</pre>PhoneNumberCopy&nbsp; is of type nvarchar(255) and explicitly contains all values</td><td>2309 ms</td><td>222 ms</td></tr></tbody></table>



<p></p>
<p>The post <a href="https://blogit.create.pt/goncalomelo/2018/12/20/query-performance-for-json-objects-inside-sql-server/">Query performance for JSON objects inside SQL Server using JSON_VALUE function</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/goncalomelo/2018/12/20/query-performance-for-json-objects-inside-sql-server/feed/</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
	</channel>
</rss>
