After a wave of baptism, let me have to sum up my scars and pain. As expected or too shallow qualification!!

1. How do Hash indexes in MySQL resolve conflicts

To be honest, all I can think about is how indexes in HashMap can resolve conflicts (using zipper method to resolve conflicts and using hash function to reduce hash conflicts). For the technical stack, I only use the B+ tree in MySQL innoDB. For the non-hash index, I can only say I don’t know. It should be resolved in the same way as a HashMap by looking it up later. If a conflict occurs, the elements of the conflict are put into the Hash list of the conflict.

2. How to determine class uniqueness

This is a bad question, and there are already some pre-questions (classloaders) that have answers to this question. But when it comes to this question, I don’t think about it. The class loader + classpath uniquely identifies a Java class. If only the package path is the same, it is not certain that this is a unique class.

MySQL > alter table select * from index

For the current technology stack using hibernate framework, SQL I really write very little. And then all I know so far is that the leftmost match will go, so the fuzzy query on the other indexes won’t go. The rest I don’t know!!

1. Where num/2=100 or subString(a,1,3)='ab' 3. In associated query, the primary key type is inconsistent with the foreign key type. 4.OR Column 5 does not have an index. The amount of data is too smallCopy the code

This is my simple query and summary of the situation without taking the index (the situation may not be comprehensive for the time being, I will continue to add later). Of course, go index, which is to pay attention to the overwrite index this case. And (5.7?) Version of the index push down, etc.

4. Several ways of full cloning in JAVA

  1. Implement clone interface and override clone () method
  2. Object implements serialization, using deserialization.

I remember there were more than two ways… I haven’t thought of it yet (I thought of adding it later)

5. Why is MySQL the leftmost match

Mysql > create a composite index by sorting the leftmost column in the index, and then sorting the second column. This is equivalent to implementing a sort rule like the first field order by and the second field.

This kind of problem has not been considered in the previous learning process. Usually just know which conditions will go index, and to which fields are suitable to add index, of course, I am ignorant. This above is also the answer that oneself feel comes out, have big guy’s words can give me point reply again.

6. What are the attributes and Type values of each column in Explain

There are a lot of these things on the Internet, but in the face of the fact that we rarely write SQL by hand, I only know some of the data, and I don’t know much about most of them.

Table: Shows which table this row is about

Type: This is the important column that shows what type the connection is using. The connection types from best to worst are const, eq_reg, ref, range, index, and ALL

Possible_keys: Displays possible indexes that can be applied to this table. If empty, there is no possible index. You can select an appropriate statement from the WHERE statement for the relevant domain. This list is created early in the optimization process, so some of the listed indexes may not be useful for subsequent optimization.

Key: indicates the actual index. If NULL, no index is used. In rare cases, MYSQL will select an index that is underoptimized. In this case, USE INDEX (indexName) in the SELECT statement to force the USE of an INDEX or IGNORE INDEX (indexName) to force MYSQL to IGNORE the INDEX

If possible_keys doesn’t appear in possible_keys, mysql chose possible_keys for another reason — for example, it might have chosen an overwrite index without the WHERE clause. In other words, possible_keys reveals which index can help improve query efficiency. The key shows which index to optimize to minimize the query cost.

Key_len: the length of the index used. With no loss of accuracy, the shorter the length, the better

Ref: Shows which column of the index is used, if possible, as a constant

Rows: The number of rows that MYSQL deems necessary to check to return the request data

Extra: Additional information about how MYSQL parses queries

The Type column mainly tells us the access method used for the table, mainly contains the following types:

All: indicates full table scanning.

Const: Reads a constant. At most one record matches. Since it is a constant, it really only needs to be read once.

Eq_ref: There is at most one match, usually accessed by primary key or unique key index.

Fulltext: Performs full-text index retrieval.

Index: full index scan.

Index_merge: Use two (or more) indexes together in a query, then merge the index results and read the table data.

Index_subquery: The return result field combination in a subquery is an index (or combination of indexes), but not a primary key or unique index.

Rang: Index range scan.

Ref: The query referenced by the driven table index in the Join statement.

Ref_or_null: The only difference from ref is that a null value is added to a query that uses an index reference.

System: indicates a system table that contains only one row of data.

Unique_subquery: The return result field combination in a subquery is a primary key or unique constraint.

7.Spring Bean lifecycle

  1. Instantiate a Bean– also known as new;

  2. Configure the instantiated Bean according to the Spring context — that is, IOC injection;

  3. If the Bean already implements the BeanNameAware interface, its implemented setBeanName(String) method is called, passing in the Bean ID value from the Spring configuration file

  4. If the Bean already implements the BeanFactoryAware interface, its implementation’s setBeanFactory is called (setBeanFactory(BeanFactory) passes the Spring factory itself (you can use this method to get other beans, Simply configure a normal Bean in the Spring configuration file);

  5. If the Bean already implements the ApplicationContextAware interface, the setApplicationContext(ApplicationContext) method is called, passing in the Spring context (this also implements step 4, But it is better than 4 because ApplicationContext is a subinterface of the BeanFactory and has more implementation methods);

  6. If the Bean associated the BeanPostProcessor interface, will call postProcessBeforeInitialization (Object obj, String s) method, BeanPostProcessor is often used as a change to the Bean content, and since this is a method that calls that at the end of Bean initialization, it can also be applied to memory or caching techniques;

  7. If a Bean has the init-method property configured in its Spring configuration file, its configured initialization method is automatically called.

  8. If the Bean associated the BeanPostProcessor interface, will call postProcessAfterInitialization (Object obj, String s) method.

Note: After the above work is done, we can apply the Bean, which is a Singleton, so normally we will call the Bean with the same ID on the instance with the same content address. Of course, we can also configure the non-Singleton in the Spring configuration file, so we won’t go into details here.

  1. When the Bean is no longer needed, it passes through the DisposableBean stage. If the Bean implements the DisposableBean interface, its implementation destroy() method is called;

  2. Finally, if the Bean has the destroy-method property configured in its Spring configuration, its configured destruction method is automatically called.

This describes the Bean cycle in the Spring context, except for the fifth step if it is a factory Bean.

8. Advantages of B+ trees

  1. In terms of storage, the B+ tree design allows batch loading of data in the case of large data volumes. In terms of queries, hash is faster if only for a single query, but most of our business scenarios have multiple queries and are returned by sorting. At this point, range lookup is faster (since nodes are sorted, local middle-order traversal is performed, perhaps across layers. The data query can be returned.

  2. Since it is a B+ tree, multiple branches can reduce the height of the tree, improve query efficiency, and reduce disk I/O times.

  3. Its leaf nodes store the corresponding cluster index address and the data itself. When you query, if you use the primary key, you do not need to go back to the table operation, you can directly query back.

These are some of the questions that impressed me most, and of course there are some other questions. For example, how to design a distributed lock, thread pool correlation (I didn’t answer that well, it feels like there are a lot of questions to consider, not just the code in the source code), how to hash the key in the Map and how to reduce hash collisions (scrambled functions), etc. These issues feel the most important or database and multi-threading, there is a long way to learn.

The big guy in the comments gave itIS NOT NULLAs well as! =andIS NULLFor an explanation of the situation, friends can see the link posted