叶问7

《叶问》是知数堂新设计的互动栏目,不定期给大家提供技术知识小贴士,形式不限,或提问、或讨论均可,并在当天发布答案,让大家轻轻松松利用碎片时间就可以学到最实用的知识点。

 

2018年8月9日,周四

MySQL的表中有唯一索引,设置unique_checks为0时,还能否写入重复值?

首先,即便设置unique_checks=0,也无法往唯一索引中写入重复值。

其次,设置unique_checks=0的作用在于,批量导入数据(例如load data)时,在确保导入数据中无重复值时,无需再次检查其唯一性,加快导入速度。

所以,unique_checks=0并不是允许唯一约束失效,而是再批量导数据时不再逐行检查唯一性。

 

2018年8月15日,周六

某人曰,在数据检索的条件中使用!=操作符时,存储引擎会放弃使用索引。 理由:因为检索的范围不能确定,所以使用索引效率不高,会被引擎自动改为全表扫描。你认可他的说法吗?

答:通常情况下,这个说法是正确的。当然,也有特殊情况,话不能说绝对了。 

有一个测试表共80万条数据,其中type列只有1、2两个值,分别占比97%和3%。 

这种情况下,查询条件 WHERE type != 1,是有可能也可以走索引的。 

下面是两个SQL的执行计划: 

mysql> desc select * from t1 where type = 1\G 
************ 1. row ************ 
id: 1 
select_type: SIMPLE 
table: t1 
partitions: NULL 
type: ref 
possible_keys: type 
key: type 
key_len: 4 
ref: const 
rows: 399731 
filtered: 100.00 
Extra: NULL

mysql> desc select * from t1 where type != 1\G 
************ 1. row ************ 
id: 1 
select_type: SIMPLE 
table: t1 
partitions: NULL 
type: ref 
possible_keys: type 
key: type 
key_len: 4 
ref: const 
rows: 10182 
filtered: 100.00 
Extra: NULL

type数据分布 
mysql> select type, count(*) as cnt from t1 group by type order by cnt; 
+------+--------+ 
| type | cnt | 
+------+--------+ 
| 2 | 38304 | 
| 1 | 761690 | 
+------+--------+

 

2018年8月17日,周一

Redis集群的slot迁移是如何实现的? 

答:迁移源slot设置为migrating 状态,迁移目标slot设置为importing状态。

在内部用dump & restore命令,把数据迁移到目标节点,迁移结束之后,移除migrating和importing状态。

在迁移过程中如果有数据访问,如果数据没迁移到目标节点,那么直接返回结果,如果迁移到目标节点,那么给客户端返回ASK重定向。

转载于:https://www.cnblogs.com/allenhu320/p/11347118.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
import javafx.application.Application; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.ComboBox; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.GridPane; import javafx.stage.Stage; public class MovieTicketSystem extends Application { // 创建并初始化折扣对象 Discount[] discounts = { new StudentDiscount(), new ChildrenDiscount(), new VIPDiscount() }; @Override public void start(Stage primaryStage) throws Exception { // 设置窗口标题 primaryStage.setTitle("电影票销售系统"); // 创建Grid布局 GridPane gridPane = new GridPane(); gridPane.setAlignment(Pos.CENTER); gridPane.setHgap(10); gridPane.setVgap(10); // 创建UI控件 Label movieLabel = new Label("选择电影:"); ComboBox<String> movieComboBox = new ComboBox<>(); movieComboBox.getItems().addAll("功夫熊猫", "叶问", "疯狂动物城"); movieComboBox.setValue("功夫熊猫"); Label discountLabel = new Label("选择优惠方式:"); ComboBox<String> discountComboBox = new ComboBox<>(); discountComboBox.getItems().addAll("学生优惠", "儿童优惠", "VIP优惠"); discountComboBox.setValue("学生优惠"); Label priceLabel = new Label("原价:50元"); Label finalPriceLabel = new Label("最终价格:"); TextField finalPriceField = new TextField(); finalPriceField.setEditable(false); Button calculateButton = new Button("计算价格"); calculateButton.setOnAction(e -> { // 获取用户选择的电影和优惠方式 String movie = movieComboBox.getSelectionModel().getSelectedItem(); String discount = discountComboBox.getSelectionModel().getSelectedItem(); // 根据用户选择设置票价和折扣对象 MovieTicket mt = new MovieTicket(); if (movie.equals("功夫熊猫")) { mt.setPrice(60); } else if (movie.equals("叶问")) { mt.setPrice(70); } else if (movie.equals("疯狂动物城")) { mt.setPrice(80); } else { finalPriceField.setText("请选择正确的电影!"); return; } if (discount.equals("学生优惠")) { mt.setDiscount(discounts[0]); } else if (discount.equals("儿童优惠")) { mt.setDiscount(discounts[1]); } else if (discount.equals("VIP优惠")) { mt.setDiscount(discounts[2]); } double price = mt.getPrice(); finalPriceField.setText(price + "元"); }); // 添加UI控件到Grid布局中 gridPane.add(movieLabel, 0, 0); gridPane.add(movieComboBox, 1, 0); gridPane.add(discountLabel, 0, 1); gridPane.add(discountComboBox, 1, 1); gridPane.add(priceLabel, 0, 2); gridPane.add(finalPriceLabel, 0, 3); gridPane.add(finalPriceField, 1, 3); gridPane.add(calculateButton, 0, 4, 2, 1); // 创建场景并将Grid布局添加到场景中 Scene scene = new Scene(gridPane, 400, 250); primaryStage.setScene(scene); // 显示窗口 primaryStage.show(); } public static void main(String[] args) { launch(args); }把这段代码的电影票原价改成随选择的电影变化而变化
06-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值