TECH

December 5, 2023

Some tips to improve SQL query performance

Improving SQL query performance is important in applications or systems. Improving SQL query performance helps execute queries faster, leading to faster data access. Applications with optimized SQL queries provide a better user experience.

Many solutions can improve SQL query performance such as: adding an index, avoiding using subqueries, using a partition, avoiding query in a loop, selecting fields instead of selecting *, using a matching join instead of a subqueries, etc. In this article, I will introduce some tips to improve SQL performance in SELECT and INSERT queries. It may be helpful for newbies.

  1. Use SELECT fields instead of SELECT *
    Retrieving all columns with SELECT * may result in unnecessary data transfer between the database and the application. This can lead to increased network traffic and slower query performance, especially when dealing with large datasets. So, we should only select the necessary fields.



  2. Use Join instead of subquery

    Using subqueries in SQL is not inherently bad, and they can be one of the best ways to express complex logic in queries. However, there are situations where using a subquery can impact performance, and developers should be cautious in these situations.

    In many cases, JOINs can be more efficient than subqueries, especially when dealing with large datasets. In such cases, alternatives like JOINs can often lead to better performance.



  3. Avoid query in a loop

    Executing frequent queries in a loop can place a significant load on the database server. This loading can lead to performance degradation, slow response times, etc. In a loop, if a query is performed repeatedly to retrieve from the database, consider fetching all necessary data in a query before entering the loop, which reduces the number of interactions with the database.

    Avoiding queries in loops is one of the best ways that improve the efficiency and performance of your application.

  4. Insert multiple rows using a query statement

    Improving the performance of SQL INSERT operations is important for efficient data loading, especially in situations where large amounts of data need to be inserted.

    Instead of performing individual INSERT statements for each record, consider using batch inserts. Batch inserts allow you to insert multiple records with a single SQL statement, reducing the number of round-trips to the database and improving overall performance.

    Batch inserts can lead to improved performance, especially when inserting a large volume of data. The overhead associated with processing each INSERT statement is minimized, resulting in faster data insertion.



    Note: There are several important considerations and notes when using batch insert with large amounts of data. That is out of memory in the server.

    Example:  When inserting 20 thousands data from csv file, the memory problem will occur if the configuration memory setting in your server is low. The problem is as below.

    To resolve this issue, you can review and adjust the memory configuration settings for your server or divide the data into smaller parts.

    Now I will introduce the solution of dividing the data into smaller parts.

    The data is stored in the csv file as below:


    I will divide the data in the file into 3 parts, and in each part I will insert 2 records into the database:

    Loop1 (part1): Read file from line 2 to line 3 -> insert into database

    Loop2 (part2): Read file from line 4 to line 5 -> insert into database

    Loop3 (part3): Read file from line 6 to line 7 -> insert into database

    The code I have implemented is as below:

    When you need to insert large amounts of data, Instead of inserting all the data into one transaction, split the data into smaller batches. This helps manage memory usage more effectively.

    In summary, optimizing SQL queries can significantly improve query performance and enhance the overall efficiency of the database. It directly impacts user satisfaction. Regular performance tuning and optimization are essential components to maintaining a high-performance system.

    [Reference]
    https://www.techagilist.com/mainframe/db2/sql-query-optimization-tips-tricks/

View More
TECH

December 3, 2023

How to use 2D Graphics in .NET MAUI app

.NET Multi-platform App UI (.NET MAUI) is a framework for building modern, multi-platform, natively compiled iOS, Android, macOS, and Windows apps using C# and XAML in a single codebase [3]. This blog show how to use draw a graphical object in .NET MAUI app.

View More
TECH

December 3, 2023

5 things awesome Google Sheets you can do at work

I usually use Google Sheets at work. It has a clean interface. it’s easy to collaborate with other people in projects. In few case, it's save me more time than other ticket management software. I'm going to show you some tips that will help you save time and do some useful things, Let’s get started!

View More
TECH

December 1, 2023

What does Critical Thinking mean to Developers?

Critical thinking is a valuable skill for developers, as it helps them approach programming challenges, design decisions, and problem-solving tasks in a thoughtful and systematic way.

View More
TECH

November 30, 2023

Flux Architecture with QML

 
In 2014, during the Hacker Way conference, Facebook introduced Flux architecture as an alternative to MVC.
Flux architecture is a software design pattern that helps manage the flow of data in complex applications.
It provides s unidirectional data flow, which makes it easier to understand, maintain, and debug applications.
 

1. What is Flux architecture

Flux is an architectural pattern proposed by Facebook.
These are four parts: Actions, Dispatcher , Stores, Views

 

Actions:  Contains all information necessary to do some action
 
Dispatcher: Is a Single Object that broadcast (actions) to all stores
 
Stores:  Manages the state ( data  ), the store is an event emitter
 
Views: Is the user interface component, Views listen for store changes
 

2. Flux architecture with QML

 

 

Views:  Are QML files
 
Actions: Is a Data type that include event name and data
 
Dispatcher: Is Singleton design pattern that is control center forward actions to all stores
 
Stores:  Use C++ models with QML
 
The following application creates a Data Object class with Q_PROPERTY values that will be accessible as named roles when a QList<DataObject*> is exposed to QML
 
 
3. Why do we should use Flux architecture
 
Today, there are two popular architectures : MV*( Model-View-Control, Model-View-Presenter, …) and  flux
Comparison table between  MVC and Flux architecture
 
 
Merit & Demerit
 
 
4. Demo source

You can refer the below Demo source code.

DemoFluxSrc

 

[Reference Source]

  • https://doc.qt.io/qt-5/qtquick-modelviewsdata-modelview.html
  • https://www.infoq.com/news/2014/05/facebook-mvc-flux/
  • https://www.voidcanvas.com/flux-vs-mvc/
View More
TECH

November 29, 2023

Let's learn VBA together

   VBA stands for Visual Basic Application, which is a basic programming application in Microsoft Office. For someone who doesn't know about programming or IT, we will be a little confused when hearing about the concept of of VBA, right? However, it's actually more accessible than you think.

View More
TECH

November 29, 2023

Laravel - Some tips to optimize Laravel's performance

Laravel has been a famous framework since 2011. This framework can help us develop a project faster than it did with a lower effort. But one of the most important things when we use a framework is performance.

Luckily, Laravel has supported many helpful features to optimize performance (Redis, Memcache, DB support, etc).

There are many factors that can negatively affect your web application, including poor code quality, inefficient server configurations, and insufficient resources.

However, we can use some tips to improve your website.

1. Update to the latest version of PHP and Laravel

It seems quite obvious but it is the simple way to improve your web application. This may be a challenge with a large legacy application while updating the version. But using the latest version can help us with numerous benefits: new features, bug fixes, and security.

2. Using the Artisan Command

One of the best features in Laravel is called Artisan. Artisan is a command-line tool. It will improve your web performance if you use it in the right way. The easy way is that you can cache the route as well as config with a command line.

php artisan config: cache

php artisan route: cache

Route Caching: This is a critical tool, especially for applications that have a large number of routes. With caching, Laravel only refers to the file where the cached routes are stored (bootstrap/cache/routes.php) instead of rendering all the routes in your website (This will cause slow performance).

Config Caching: Similar to route caching, it will find all data of the config file and variables of .env file then store it in bootstrap/cache/config.php

Remember that you need to run the command above if you have changed any in the config file or route file. To clear the cache, you can run these commands:

php artisan config: clear

php artisan route: clear

3. Remove unused service

The key goal of Laravel is to bring an easy development process to the developers.

When launching Laravel, it will auto-load many service providers listed within the config/app.php file to help you get started with your project.

In addition, many developers don’t want to follow the default framework settings. So it’s necessary to delete unused services to improve your project performance.

4. Eager Loading

All of the queries in Laravel are lazy queries when you execute. It only fetches the required data. Sometimes, this will increase the number of queries and cause low performance for your website. You will run up to N+1 queries to find your response.

To resolve the N+1 queries problem, Laravel provides us with a feature that can use eager loading to load the data to help us improve performance.

Let's compare the source code of two loading modes:

Lazy Loading: You will need to execute multiple queries to find the response you need.

$books = Book::all(); // Get all books

foreach($books as $book) {

echo $book->author->name // Executing query to find author link with book

}

Eager Loading: You only need to execute once.

$books = Book::with('author')->get(); // Get all books link with author

foreach ($books as $book) {

echo $book->author->name // Not execute query again to find

}

Conclusion

Laravel is a fast-growing PHP framework, that has many useful features to support users to improve the performance of their websites.

Hopefully, some tips that I introduced above can help you somewhat in optimizing your website performance.

 

Reference:

  1. Ultimate Laravel Performance Optimization Guide (cloudways.com)
  2. 17 Methods to Optimize Laravel Performance (kinsta.com)
View More
TECH

November 29, 2023

Introduction: Extensions for Laravel framework

If you’re coding Laravel with VS Code, extensions are the most important factor that we need to install before starting the project.

Following are some of the best VS Code extensions for Laravel developers. These extensions will help you boost your productivity and ease your development.

1. Laravel Blade Snippet

This extension adds the syntax highlight which supports your VS Code.

Some key features of the extension:

  • Blade syntax highlight.
  • Blade snippets.
  • Blade formatting.
  • Emmet works in blade template.

To change the setting of Laravel Blade Snippet, go to Preferences and select Settings, then config in JSON file like the following 

"emmet.triggerExpansionOnTab": true,

"blade.format.enable": true,

There are some syntaxes that Laravel Blade Snippet supports:

Trigger Snippet
b:php

@php

// code

@endphp

b:section

@section

// code

@endsection

b:include @include(...)
b:if

@if (condition)

// code

@endif

b:if-else

@if (condition)

// code

@else

// code

@endif

b:for

@for (...)

// code

@endfor

b:foreach

@foreach (...)

// code

@endforeach

2. Laravel Extra Intellisense

This extension supports autocomplete these features:

  • Route names and route parameters.
  • Views and variables.
  • Configs.
  • Translations and translation parameters.
  • Laravel mix function.
  • Validations rules.
  • View sections and stacks.
  • Env.
  • Route Middlewares.
  • Asset.
  • Blade directive.

It helps us find the name of that config easily so that we don’t need to search in the directory tree. We only enter the key that we remember and this extension will remind us of another.

3. Laravel goto view

This is a simple extension. It can help you quickly jump to another file view, no matter where you are.

If you want to jump to another, we use the keystrokes “Ctrl + Click” or “Alt + Click”. Besides that, in case you want to customize more extensions, you can go to Preferences > Settings > Extensions/Laravel goto view configuration, and then add the extension that you want to customize. Here is the configuration JSON:

"laravel_goto_view.extensions": [
  ".blade.php",
  ".vue",
]

4. Laravel goto Controller

Finding a controller can be difficult when your application grows with a number of different controllers. Then, using this extension will help you reduce the time spent searching, you can quickly jump to the controller from the route config file without having to find the exact controller name. 

The usage is the same as keystrokes in the Laravel goto view to jump to the respective controller file from the routes file.

Conclusion

These extensions will help you to boost productivity. It helps us save a lot of time and make the development project easier. Thus, using extensions in a project is always useful.

If you are excited about all the mentioned extensions above, you can take a look at the Laravel Extension Pack for Visual Studio Code. If you are interested in more extensions, I suggest you try these extensions: Laravel Blade Spacer, Laravel Artisan, Laravel Model Snippets, PHP Intelephense, PHP Constructor, etc.

 

Reference:

10+ Best VS Code Laravel Extensions For Developers - ThemeSelection

Image source:

Laravel Extra Intellisense - Visual Studio Marketplace

 

View More
TECH

November 24, 2023

Why Testers and Developers Have Different Mindsets

Testers and developers play crucial roles in software development, but their mindsets differ significantly. Developers focus on creating and building the software, while testers focus on detecting issues. This difference in focus leads to distinct mindsets that influence their approach to work.

Developer Mindset:

  • Creativity and Problem-Solving: Developers are creative problem-solvers who enjoy tackling complex challenges. They approach programming with an analytical mindset, devising smart solutions to technical problems. They enjoy the challenge of transforming ideas into working software.

  • Attention to Detail and Precision: Developers meticulously craft code, ensuring accuracy and consistency. They strive for high-quality code that is efficient, reliable, and maintainable. Attention to detail is essential to prevent bugs and maintain software integrity.

  • Focus on Functionality and Features: Developers prioritize creating software that meets the specified requirements and delivers the desired features. They typically work closely with the requirements provided by business analysts or product owners. 

Tester Mindset:

  • Critical Thinking and Suspicion: Testers adopt a critical mindset, questioning assumptions and challenging the status quo. They approach testing with a healthy dose of skepticism, seeking out potential defects and inconsistencies. This mindset is essential to uncover hidden issues and ensure software quality.

  • Attention to Edge Cases and Unexpected Behavior: Testers excel at identifying edge cases and challenging the boundaries of the software. They meticulously explore various scenarios and inputs, anticipating potential issues that might arise under unusual conditions. This approach ensures that the software can handle real-world usage scenarios effectively.

  • Emphasis on Usability and User Experience: Testers not only evaluate the functional aspects but also consider the software from the user's perspective, ensuring that it is easy to use, intuitive, and user-friendly. They focus on identifying usability issues, such as confusing interfaces or lack of clarity, to enhance the overall user experience.

 

In summary, the differing mindsets of testers and developers reflect their distinct roles in the software development process. Developers are driven by creativity, problem-solving, and attention to detail, while testers prioritize critical thinking, edge case analysis, and usability considerations. Combining the strengths of both roles helps create a more comprehensive and reliable end product.

Image source

https://www.bing.com/images/create/the-difference-in-perspective-of-e2809ctesterse2809d-and-e2809cde/1-65606aac4f7145e6aa9867dbe9a439fe?id=MzU0R9ZOuNXAolSI9PuZZA%3d%3d&view=detailv2&idpp=genimg&FORM=GCRIDP

View More
TECH

November 24, 2023

Some useful extensions in Visual Studio Code

Visual Studio Code is a useful programming tool, it supports almost all popular programming languages: Python, JavaScript, HTML, CSS, TypeScript, C++, Java, PHP, Go, SQL, Ruby, ...

 

Another thing regarding language support is that documentation for popular programming languages in homepage. Shows that the development direction of this editor is aimed at all programmers, regardless of what programming language or field they use in the programming industry.

It can be said that it is one of the software with the richest extension store with thousands of extensions of all types such as programming languages, themes, services,...

VS Code extensions let you add languages, debuggers, and tools to your installation to support your development workflow.

 

In my work,  I have found some extensions to be particularly useful, so I would like to share them with everyone below.

The first:  I will introduce about install 
+ Find and install an extension:
In the Extensions, input 'code' the search box to filter the Marketplace offerings to extensions with 'code' in the title or metadata.
You can see this extension and choose what you want use.

    


Some useful application for developers:

 

1.Git Graph

- Introduce: 

View a Git Graph of your repository, and easily perform Git actions from the graph.

Normally we will use some tools like Tortoise Git, Source Tree, Git Base to manage our git,
track commits, merge requests, see git branches, people committing code,...

The purpose is to know where the information about these branches will come from, when they committed, and who committed them in a clear diagram with easy-to-see colors.

To meet this need, we will have an extension called Git Graph, we can use the extension to review all necessary information without using other external tools.


- Install: Menu Extensions-> Search Git Graph -> Click Install Button

2.GitLens — Supercharge

- Introduce: 

If Git Graph helps us review all the information through the commit schedule.

But it has a limitation: to view information, we need to click on the menu of this extensions , and only view each file.

On the contrary, GitLens can help us see information about each line of code: who wrote this line of code, what date it was committed, branch name, version ,...

We just need to click the cursor directly on that line of code to see the information


- Install: Menu Extensions-> Search GitLens -> Click Install Button

3. Rainbow Tags
- Introduce:

Rainbow Tags are extremely useful Extensions, especially for web programmers, for pages with too much html code.

It is difficult for us to check the opening and closing of tags, parent tags, and child tags.

Rainbow Tags will help us review code easily, the tags are colored differently for each level, there will be no color overlap if the same type of tag

Then we will easily see the opening and closing of this tab. Color will make us feel more interested in programming


- Install: Menu Extensions-> Search Rainbow -> Click Install Button


4. Lines of Code (LOC)

- Introduce:

At the end of the project, we will have an extremely important job: to summarize the number of lines of code of that project.

This is for the purpose of accurately evaluating and making statistics about our projects to report to superiors, customers, to evaluate KPIs, Sales,...

And Lines of Code will support us very well in this.

Lines of Code can be listed by file or by entire project: total number  files, number code, number of comment lines, number of blank lines

The results are exported as json files and txt files


- Install: Menu Extensions -> Search Lines of Code -> Click Install Button

[Reference Source]

https://code.visualstudio.com/

https://miro.medium.com/v2/resize:fit:720/format:webp/0*vz3WV7ng_xjlY06r

https://marketplace.visualstudio.com/VSCode

https://github.com/mhutchie/vscode-git-graph/raw/master/resources/demo.gif

https://raw.githubusercontent.com/gitkraken/vscode-gitlens/main/images/docs/current-line-blame.png

https://gitlab.com/voldemortensen/rainbow-tags/-/raw/main/example_color.png

https://miro.medium.com/v2/resize:fit:720/format:webp/1*P7lknJxmmKQc6b_VkCATtQ.jpeg

 

View More
1 17 18 19 20 21 22