Seamus  Quitzon

Seamus Quitzon

1602828300

Estimate time complexity of Java and SQL query.

Java and SQL samples of hard choice between performance and complexity.

Image for post

Big O notation looks at the upper bound of the performance of an algorithm to define its worst-case behavior. It looks at algorithms asymptotic behavior and describe the size of the input as represented by n.

I like to work with T-SQL, so I combined together different time complexities.

Certainly, we can use indexes of SQL tables to achieve more speed.

Clustered indexes are physically sorted on the disk, you can have only one per table. Simple indexes are logically sorted and a table can have many of those (for significant fields).

Theory logic of this notation is simple:

Image for post

Let’s say for the beginning, that we have 2 SQL tables: User and Post.

Constant time complexity O(1)

SELECT TOP 1 u.Name FROM User u

If the time taken by the algorithm does not change and remains constant as the input size is increased, then the algorithm has the complexity of O(1) performance. The algorithm doesn’t depend on the size of the input.

SELECT COUNT(*) FROM User

a) it has O(1) based on the count statistics

b) but it will be O(log(n)) complexity in case of using a primary key

c) or O(n) complexity without a primary key

or Java implementation of O(1):

public class MyClass {
	    public static void main(String args[]) {

	       ConstantTimeComplexity(10);
	    }
	    static void ConstantTimeComplexity(int n) {
	       int x=10;
	       int y=25;      
	       int sum = x + n;
	       int multiply = y * n;
	       System.out.println("Sum of x+y = " + sum + ", Multiply: " + multiply);
	    }
	}

#java #performanc #big-o #sql #complexity

What is GEEK

Buddha Community

Estimate time complexity of Java and SQL query.
Cayla  Erdman

Cayla Erdman

1594369800

Introduction to Structured Query Language SQL pdf

SQL stands for Structured Query Language. SQL is a scripting language expected to store, control, and inquiry information put away in social databases. The main manifestation of SQL showed up in 1974, when a gathering in IBM built up the principal model of a social database. The primary business social database was discharged by Relational Software later turning out to be Oracle.

Models for SQL exist. In any case, the SQL that can be utilized on every last one of the major RDBMS today is in various flavors. This is because of two reasons:

1. The SQL order standard is genuinely intricate, and it isn’t handy to actualize the whole standard.

2. Every database seller needs an approach to separate its item from others.

Right now, contrasts are noted where fitting.

#programming books #beginning sql pdf #commands sql #download free sql full book pdf #introduction to sql pdf #introduction to sql ppt #introduction to sql #practical sql pdf #sql commands pdf with examples free download #sql commands #sql free bool download #sql guide #sql language #sql pdf #sql ppt #sql programming language #sql tutorial for beginners #sql tutorial pdf #sql #structured query language pdf #structured query language ppt #structured query language

Tyrique  Littel

Tyrique Littel

1600135200

How to Install OpenJDK 11 on CentOS 8

What is OpenJDK?

OpenJDk or Open Java Development Kit is a free, open-source framework of the Java Platform, Standard Edition (or Java SE). It contains the virtual machine, the Java Class Library, and the Java compiler. The difference between the Oracle OpenJDK and Oracle JDK is that OpenJDK is a source code reference point for the open-source model. Simultaneously, the Oracle JDK is a continuation or advanced model of the OpenJDK, which is not open source and requires a license to use.

In this article, we will be installing OpenJDK on Centos 8.

#tutorials #alternatives #centos #centos 8 #configuration #dnf #frameworks #java #java development kit #java ee #java environment variables #java framework #java jdk #java jre #java platform #java sdk #java se #jdk #jre #open java development kit #open source #openjdk #openjdk 11 #openjdk 8 #openjdk runtime environment

Seamus  Quitzon

Seamus Quitzon

1602828300

Estimate time complexity of Java and SQL query.

Java and SQL samples of hard choice between performance and complexity.

Image for post

Big O notation looks at the upper bound of the performance of an algorithm to define its worst-case behavior. It looks at algorithms asymptotic behavior and describe the size of the input as represented by n.

I like to work with T-SQL, so I combined together different time complexities.

Certainly, we can use indexes of SQL tables to achieve more speed.

Clustered indexes are physically sorted on the disk, you can have only one per table. Simple indexes are logically sorted and a table can have many of those (for significant fields).

Theory logic of this notation is simple:

Image for post

Let’s say for the beginning, that we have 2 SQL tables: User and Post.

Constant time complexity O(1)

SELECT TOP 1 u.Name FROM User u

If the time taken by the algorithm does not change and remains constant as the input size is increased, then the algorithm has the complexity of O(1) performance. The algorithm doesn’t depend on the size of the input.

SELECT COUNT(*) FROM User

a) it has O(1) based on the count statistics

b) but it will be O(log(n)) complexity in case of using a primary key

c) or O(n) complexity without a primary key

or Java implementation of O(1):

public class MyClass {
	    public static void main(String args[]) {

	       ConstantTimeComplexity(10);
	    }
	    static void ConstantTimeComplexity(int n) {
	       int x=10;
	       int y=25;      
	       int sum = x + n;
	       int multiply = y * n;
	       System.out.println("Sum of x+y = " + sum + ", Multiply: " + multiply);
	    }
	}

#java #performanc #big-o #sql #complexity

Introduction to Recursive CTE

This article will introduce the concept of SQL recursive. Recursive CTE is a really cool. We will see that it can often simplify our code, and avoid a cascade of SQL queries!

Why use a recursive CTE ?

The recursive queries are used to query hierarchical data. It avoids a cascade of SQL queries, you can only do one query to retrieve the hierarchical data.

What is recursive CTE ?

First, what is a CTE? A CTE (Common Table Expression) is a temporary named result set that you can reference within a SELECT, INSERT, UPDATE, or DELETE statement. For example, you can use CTE when, in a query, you will use the same subquery more than once.

A recursive CTE is one having a subquery that refers to its own name!

Recursive CTE is defined in the SQL standard.

How to make a recursive CTE?

A recursive CTE has this structure:

  • The WITH clause must begin with “WITH RECURSIVE”
  • The recursive CTE subquery has two parts, separated by “UNION [ALL]” or “UNION DISTINCT”:
  • The first part produces the initial row(s) for the CTE. This SELECT does not refer to the CTE name.
  • The second part recurses by referring to the CTE name in its FROM clause.

Practice / Example

In this example, we use hierarchical data. Each row can have zero or one parent. And it parent can also have a parent etc.

Create table test (id integer, parent_id integer);

insert into test (id, parent_id) values (1, null);

insert into test (id, parent_id) values (11, 1);
insert into test (id, parent_id) values (111, 11);

insert into test (id, parent_id) values (112, 11);

insert into test (id, parent_id) values (12, 1);

insert into test (id, parent_id) values (121, 12);

For example, the row with id 111 has as ancestors: 11 and 1.

Before knowing the recursive CTE, I was doing several queries to get all the ancestors of a row.

For example, to retrieve all the ancestors of the row with id 111.

While (has parent)

	Select id, parent_id from test where id = X

With recursive CTE, we can retrieve all ancestors of a row with only one SQL query :)

WITH RECURSIVE cte_test AS (
	SELECT id, parent_id FROM test WHERE id = 111
	UNION 
	SELECT test.id, test.parent_id FROM test JOIN cte_test ON cte_test.id = test.parent_id

) SELECT * FROM cte_test

Explanations:

  • “WITH RECURSIVE”:

It indicates we will make recursive

  • “SELECT id, parent_id FROM test WHERE id = 111”:

It is the initial query.

  • “UNION … JOIN cte_test” :

It is the recursive expression! We make a jointure with the current CTE!

Replay this example here

#sql #database #sql-server #sql-injection #writing-sql-queries #sql-beginner-tips #better-sql-querying-tips #sql-top-story

Samanta  Moore

Samanta Moore

1620458875

Going Beyond Java 8: Local Variable Type Inference (var) - DZone Java

According to some surveys, such as JetBrains’s great survey, Java 8 is currently the most used version of Java, despite being a 2014 release.

What you are reading is one in a series of articles titled ‘Going beyond Java 8,’ inspired by the contents of my book, Java for Aliens. These articles will guide you step-by-step through the most important features introduced to the language, starting from version 9. The aim is to make you aware of how important it is to move forward from Java 8, explaining the enormous advantages that the latest versions of the language offer.

In this article, we will talk about the most important new feature introduced with Java 10. Officially called local variable type inference, this feature is better known as the **introduction of the word **var. Despite the complicated name, it is actually quite a simple feature to use. However, some observations need to be made before we can see the impact that the introduction of the word var has on other pre-existing characteristics.

#java #java 11 #java 10 #java 12 #var #java 14 #java 13 #java 15 #verbosity