1
00:00:04,337 --> 00:00:05,088
The most common

2
00:00:05,088 --> 00:00:06,297
database performance mistake

3
00:00:06,297 --> 00:00:07,048
I see teams make

4
00:00:07,173 --> 00:00:07,757
usually

5
00:00:07,757 --> 00:00:09,592
Is using the ORMs

6
00:00:09,592 --> 00:00:11,011
In incorrect way

7
00:00:11,094 --> 00:00:12,178
and the other one for sure

8
00:00:12,178 --> 00:00:14,764
Is the not applying enough indexes

9
00:00:14,973 --> 00:00:17,267
or applying too much indexes
to their databases

10
00:00:17,517 --> 00:00:19,894
So the EXPLAIN command
would basically tell you

11
00:00:20,061 --> 00:00:22,063
what your query is really doing

12
00:00:22,272 --> 00:00:25,316
and how much time each
part of it is taking to execute

13
00:00:25,525 --> 00:00:26,860
So for example you have a query

14
00:00:26,860 --> 00:00:28,695
that is looking for all the customers

15
00:00:28,820 --> 00:00:33,324
where the credited date is
between today and next month

16
00:00:33,533 --> 00:00:35,827
This is a column that is present
in your workloads

17
00:00:35,952 --> 00:00:37,620
You might need to create
an index for that

18
00:00:37,829 --> 00:00:40,081
We have a lot of different
types of indexes

19
00:00:40,081 --> 00:00:43,877
but the main two that are used
in the most part of the scenarios

20
00:00:44,127 --> 00:00:46,379
are definitely B-tree and
Hash indexes

21
00:00:46,629 --> 00:00:47,964
B-tree indexes uses

22
00:00:48,089 --> 00:00:49,799
basically a binary tree

23
00:00:49,799 --> 00:00:51,009
a balance a tree structure

24
00:00:51,134 --> 00:00:54,387
which means that you have
numbers that are split it nodes

25
00:00:54,721 --> 00:00:56,431
And this tree is balanced

26
00:00:56,598 --> 00:00:57,891
And the Hash indexes

27
00:00:58,266 --> 00:01:00,101
they use something
called hash tables

28
00:01:00,226 --> 00:01:01,978
So hash tables are different

29
00:01:01,978 --> 00:01:04,814
They use basically a
list of numbers

30
00:01:04,814 --> 00:01:08,359
And each position in this list
is referenced by a number

31
00:01:08,485 --> 00:01:09,027
a specific one

32
00:01:09,152 --> 00:01:12,989
And you can only access this
specific row based on a value

33
00:01:12,989 --> 00:01:16,284
And this value is based on the
division of two numbers

34
00:01:16,367 --> 00:01:18,870
And usually when we are
dealing with database queries

35
00:01:18,870 --> 00:01:19,913
when we're searching for data

36
00:01:20,038 --> 00:01:21,706
we don't want equal comparisons

37
00:01:21,706 --> 00:01:22,999
We want to do range conversions

38
00:01:22,999 --> 00:01:24,042
We want to look for

39
00:01:24,250 --> 00:01:26,419
data that is greater or equal
than something

40
00:01:26,419 --> 00:01:27,837
or less or equal than something

41
00:01:27,921 --> 00:01:29,047
or between something

42
00:01:29,380 --> 00:01:31,174
Even though hash
indexes are faster

43
00:01:31,382 --> 00:01:32,759
we don't only use them

44
00:01:32,967 --> 00:01:33,802
and this is why

45
00:01:33,802 --> 00:01:35,178
B-tree indexes are really good

46
00:01:35,261 --> 00:01:37,138
because we can do
range comparisons

47
00:01:37,597 --> 00:01:39,933
Hash indexes wouldn't
work a lot here

48
00:01:40,100 --> 00:01:40,767
because as I said

49
00:01:40,767 --> 00:01:41,518
we are working with

50
00:01:41,893 --> 00:01:43,019
equal comparisons

51
00:01:43,186 --> 00:01:45,939
Database indexation is
really important

52
00:01:45,939 --> 00:01:49,818
because it basically helps you
to reduce time of queries

53
00:01:50,151 --> 00:01:51,736
which means that your
customers will be happier

54
00:01:51,736 --> 00:01:54,114
because they will have a more
fluid experience with you

55
00:01:54,239 --> 00:01:55,824
They won't leave you
because of

56
00:01:56,116 --> 00:01:57,283
poor execution times

57
00:01:57,492 --> 00:01:59,869
And as they are not
really hard to apply

58
00:01:59,953 --> 00:02:01,579
I think that is a great
technique to

59
00:02:01,996 --> 00:02:02,914
be used in your project

60
00:02:03,039 --> 00:02:04,332
In your applications because

61
00:02:04,582 --> 00:02:05,166
It's something

62
00:02:05,166 --> 00:02:06,751
that will not cost you
a lot of time to apply

63
00:02:07,001 --> 00:02:09,546
and that will save a lot of money
and bring a lot of clients

64
00:02:09,671 --> 00:02:11,256
and keep the clients you
already have with you
