exists

sql: check if entry in table A exists in table B

泪湿孤枕 提交于 2019-11-27 00:12:01
问题 I have a definition table that I know is not being maintained very well, lets call this table A . I have another table (call it table B ) that is much smaller and ideally should be a subset of table A but I know that table A is somewhat stale and does not contain new entries that are in Table B . Note, that tables A and B have different columns. Table A: ID, Name, blah, blah, blah, blah Table B: ID, Name I want all rows in Table B such that the ID in Table B does NOT exist in Table A. This

【MySQL】查询语句优化 -- 2019-08-11 19:07:47

二次信任 提交于 2019-11-27 00:11:43
原文: http://106.13.73.98/__/189/ MySQL的性能优化包罗甚广:索引优化、查询优化、查询缓存、服务器设置优化、操作系统及硬件优化、应用层优化(web服务器、缓存)等等。本文提到的优化技巧更适用于开发人员,都是从网络上收集和自己整理的,主要是查询语句上面的优化,其它层面的优化技巧在此不做记录。 整理如下 合理创建索引 count 的优化 避免使用不兼容的数据类型 索引字段上进行运算会使索引失效 尽量避免使用 != 、 is null 、 is not null 、 in 、 not in 这样的操作符 尽量使用数字型字段 合理使用 exists 、 not exists 子句 能够用 between 的就不要用 in 能够用 distinct 的就不要用 group by 尽量不要使用 select info 语句,它会导致表锁,阻止其它用户访问该表 必要时强制查询优化器使用某个索引 消除对大型表行数据的顺序存取 程序中如果需要一次性对同一个表插入多条数据,应写成一条语句 查询的开销指标 执行时间 检查的行数 返回的行数 建立索引的几个准则 合理的建立索引能够加快数据读取效率,不合理的建立索引反而会拖慢数据的响应速度。 索引越多,更新数据的速度越慢。 尽量在采用 MyISAM 作为存储引擎的时候使用索引(因为MySQL以Btree存储索引),而不是

Oracle 建立索引及SQL优化

你离开我真会死。 提交于 2019-11-27 00:05:22
如何某表的某个字段有主键约束和唯一性约束,则Oracle 则会自动在相应的约束列上建议唯一索引。数据库索引主要进行提高访问速度。 建设原则:  1、索引应该经常建在Where 子句经常用到的列上。如果某个大表经常使用某个字段进行查询,并且检索行数小于总表行数的5%。则应该考虑。  2、对于两表连接的字段,应该建立索引。如果经常在某表的一个字段进行Order By 则也经过进行索引。  3、不应该在小表上建设索引。 优缺点:  1、索引主要进行提高数据的查询速度。 当进行DML时,会更新索引。因此索引越多,则DML越慢,其需要维护索引。 因此在创建索引及DML需要权衡。 创建索引:  单一索引:Create Index <Index-Name> On <Table_Name>(Column_Name);  复合索引: Create Index i_deptno_job on emp(deptno,job); —>在emp表的deptno、job列建立索引。   select * from emp where deptno=66 and job='sals' ->走索引。   select * from emp where deptno=66 OR job='sals' ->将进行全表扫描。不走索引   select * from emp where deptno=66 ->走索引。

zookeeper

不打扰是莪最后的温柔 提交于 2019-11-27 00:01:34
ZooKeeper是什么? 高可用的高性能的分布式系统协调服务。局部不可用是分布式系统的固有特征,ZooKeeper可以很好的地处理这种情况。 下面从三个方面来理解ZooKeeper服务:数据模型、操作、实现 数据模型 可以把zookper看成一个文件系统,文件系统中的所有文件形成一个数状结构,zookeeper维护着这样的树形层次结构,树中的节点称为znode。每个znode有一个与之相关联的ACL(Access Control List)。这种数据模型示意图如下: znode通过路径被引用,而且要采用绝对路径,即必须以/开头。znode存储的数据要<1m。 znode类型   短暂znode:回话结束,zookeeper就会把短暂znode删除,短暂znode不可以有子节点。   持久znode:回话结束也不会被删除,除非客户端明确要删除此znode,持久znode可以有子节点。 对于在特定时刻需要知道有哪些分布式资源可用的应用来说,使用短暂znode比较合适。 znode的观察机制 znode以某种方式发生变化时,“观察”(watch)机制可以让客户端得到通知。可以针对ZooKeeper服务的“操作”来设置观察,该服务的其他操作可以触发观察。比如,客户端可以对某个客户端调用exists操作,同时在它上面设置一个观察,如果此时这个znode不存在,则exists返回false

【MySQL】多表查询 -- 2019-08-11 18:12:40

跟風遠走 提交于 2019-11-27 00:00:26
原文: http://106.13.73.98/__/26/ 目录 多表链接查询 笛卡尔积 内链接 inner join 外链接之左链接 left join 外链接之右链接 right join 全外链接 符合条件链接查询 子查询 先准备两张表:部门表(department)、员工表(employee) # 部门表create table department( id int primary key auto_increment, name varchar(20) not null ); # 员工表create table employee( id int primary key auto_increment, name varchar(20) not null, sex enum('male', 'female') not null default 'male', age int not null, dep_id int not null ); # 插入数据insert into department values(200, "技术"),(201, "人力资源"),(202, "销售"),(203, "运营"); insert into employee(name, sex, age, dep_id) values('egon', 'male', 18, 200),('alex'

Oracle Sql考核

▼魔方 西西 提交于 2019-11-26 23:50:20
一.数据库初始化脚本: Create TABLE HAND_CUSTOMERS ( CUSTOMERS_NO Varchar2(10), CUSTOMERS_NAME Varchar2(30), CUSTOMERS_GENDER Varchar2(3), CUSTOMERS_BIRTH_DATE Date ); comment on TABLE HAND_CUSTOMERS is '顾客表'; comment on COLUMN HAND_CUSTOMERS.CUSTOMERS_NO is '客户编号'; comment on COLUMN HAND_CUSTOMERS.CUSTOMERS_NAME is '客户名称'; comment on COLUMN HAND_CUSTOMERS.CUSTOMERS_GENDER is '客户性别'; comment on COLUMN HAND_CUSTOMERS.CUSTOMERS_BIRTH_DATE is '客户出生日期'; Create TABLE HAND_SELLERS ( SELLER_NO Varchar2(10), SELLER_NAME Varchar2(30), MANAGER_NO Varchar2(10) ); comment on TABLE HAND_SELLERS is '销售员表'; comment on

how to prevent “directory already exists error” in a makefile when using mkdir

荒凉一梦 提交于 2019-11-26 22:29:51
问题 I need to generate a directory in my makefile and I would like to not get the "directory already exists error" over and over even though I can easily ignore it. I mainly use mingw/msys but would like something that works across other shells/systems too. I tried this but it didn't work, any ideas? ifeq (,$(findstring $(OBJDIR),$(wildcard $(OBJDIR) ))) -mkdir $(OBJDIR) endif 回答1: On UNIX Just use this: mkdir -p $(OBJDIR) The -p option to mkdir prevents the error message if the directory exists.

oracel SQL多表查询优化

ぃ、小莉子 提交于 2019-11-26 21:48:23
SQL优化 1.执行路径:ORACLE的这个功能大大地提高了SQL的执行性能并节省了内存的使用:我们发现,单表数据的统计比多表统计的速度完全是两个概念.单表统计可能只要0.02秒,但是2张表联合统计就 可能要几十秒了.这是因为ORACLE只对简单的表提供高速缓冲(cache buffering) ,这个功能并不适用于多表连接查询..数据库管理员必须在init.ora中为这个区域设置合适的参数,当这个内存 区域越大,就可以保留更多的语句,当然被共享的可能性也就越大了. 2.选择最有效率的表名顺序(记录少的放在后面) ORACLE的解析器按照从右到左的顺序处理FROM子句中的表名,因此FROM子句中写在最后的表(基础表 driving table)将被最先处理. 在FROM子句中包含多个表的情况下,你必须选择记录条数最 少的表作为基础表.当ORACLE处理多个表时, 会运用排序及合并的方式连接它们.首先,扫描第一个表(FROM子句中最后的那个表)并对记录进行派序,然后扫描第二个表(FROM子句中最后第二个表 ),最后将所有从第二个表中检索出的记录与第一个表中合适记录进行合并. 例如: 表 TAB1 16,384 条记录 表 TAB2 1 条记录 选择TAB2作为基础表 (最好的方法) select count(*) from tab1,tab2 执行时间0.96秒

Linq select objects in list where exists IN (A,B,C)

[亡魂溺海] 提交于 2019-11-26 21:42:44
I have a list of orders . I want to select orders based on a set of order statuses. So essentially select orders where order.StatusCode in ("A", "B", "C") // Filter the orders based on the order status var filteredOrders = from order in orders.Order where order.StatusCode.????????("A", "B", "C") select order; Your status-codes are also a collection, so use Contains : var allowedStatus = new[]{ "A", "B", "C" }; var filteredOrders = orders.Order.Where(o => allowedStatus.Contains(o.StatusCode)); or in query syntax: var filteredOrders = from order in orders.Order where allowedStatus.Contains(order

PL/pgSQL checking if a row exists

折月煮酒 提交于 2019-11-26 20:33:54
I'm writing a function in PL/pgSQL, and I'm looking for the simplest way to check if a row exists. Right now I'm SELECTing an integer into a boolean , which doesn't really work. I'm not experienced with PL/pgSQL enough yet to know the best way of doing this. Here's part of my function: DECLARE person_exists boolean; BEGIN person_exists := FALSE; SELECT "person_id" INTO person_exists FROM "people" p WHERE p.person_id = my_person_id LIMIT 1; IF person_exists THEN -- Do something END IF; END; $$ LANGUAGE plpgsql; Update - I'm doing something like this for now: DECLARE person_exists integer; BEGIN