1.进程死锁的条件?
//互斥条件(Mutual exclusion):
资源不能被共享,只能由一个进程使用。
//请求与保持条件(Hold and wait):
已经得到资源的进程可以再次申请新的资源。
//非剥夺条件(No pre-emption):
已经分配的资源不能从相应的进程中被强制地剥夺。
//循环等待条件(Circular wait ):
系统中若干进程组成环路,该环路中每个进程都在等待相邻进程正占用的资源。
2.线程的创建函数是什么?
1)学会使用函数创建多线程
//利用函数创建多线程
import threading
import time
def main(name='python'):
for i in range(2):
print('hellow',name)
time.sleep(1)
// 创建线程1,不指定参数
thread_01 = threading.Thread(target=main)
// 启动线程1
thread_01.start()
// 创建线程2,指定参数
thread_02 = threading.Thread(target=main,args=('wwww',))
// 启动线程2
thread_02.start()
2)学会使用类创建多线程
// 利用类函数创建多线程
//我们要自定义一个类,对于这个类有两点要求,
//必须继承 threading.Thread 这个父类;
//必须覆写 run 方法。
from threading import Thread
class mythread(Thread):
def __init__(self,name = 'python'):
super().__init__() // 继承父类的init方法,一定要写在最前面
self.name = name
def run(self):
for i in range(2):
print('hellow', self.name)
time.sleep(1)
thread_01 = mythread()
thread_01.start()
// 创建线程02,指定参数
thread_02 = mythread("MING")
thread_02.start()
结果:
hello Python
hello MING
hello Python
hello MING
3.索引及其作用?
概念:
物理的对数据库表中一列或者多列的值进行排序的一种存储结构。相当于图书的目录,可以根据目录中的页码快速找到需要的内容。
作用:
1.快速读取数据
2.保证数据记录的唯一性
3.实现表与表之间的参照完整性
4.在使用orderby ,group by子句进行检索时,索引可以减少排序和分组的时间。
4.列举创建索引但是无法命中索引的8种情况?
1)、查询条件中有or、not in、not exist等
2)、小表查询 3)、like查询是以%开头
4)、如果列类型是字符串,那一定要在条件中将数据使用引号引用起来,否则不使用索引
5)、没有使用索引字段查询
6)、对索引列进行运算,需要建立函数索引
7)、单独引用联合索引中的非第一位置的索引
8)、没有查询条件
5.什么是事务?
数据库事务是构成单一逻辑工作单元的操作集合。
举例:转账是生活中常见的操作,比如从A账户转账100元到B账号。站在用户角度而言,这是一个逻辑上的单一操作,然而在数据库系统中,至少会分成两个步骤来完成:
1)、将A账户的金额减少100元
2)、将B账户的金额增加100元。
与程序的区别:一个程序中包含多个事务。在关系数据库中,一个事务可以是一条SQL语句,一组SQL语句或整个程序。