数据库篇之存储过程[bsp_getfavoriteproductlist](非官方版本)

本文介绍了一种使用SQL实现的分页查询优化方法,通过在存储过程中采用子查询和TOP子句结合的方式,实现了高效地获取指定用户收藏的商品列表。此方法避免了全表扫描,减少了每次分页查询的数据量。

差异如图:

更新语句如下:

DROP PROCEDURE [bsp_getfavoriteproductlist]
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [bsp_getfavoriteproductlist]
@pagesize int,
@pagenumber int,
@uid int
AS
BEGIN
	SET NOCOUNT ON;
	
	IF @pagenumber=1
	BEGIN
		SELECT [temp1].[recordid],[temp1].[uid],[temp1].[state],[temp1].[addtime],[temp1].[pid],[temp2].[name],[temp2].[shopprice],[temp2].[showimg] FROM
		(SELECT TOP(@pagesize) [recordid],[uid],[pid],[state],[addtime] FROM [bsp_favorites] WHERE [uid]=@uid ORDER BY [recordid] DESC) AS [temp1]
		LEFT JOIN [bsp_products] AS [temp2]
		ON [temp1].[pid]=[temp2].[pid]
	END
	ELSE
	BEGIN
		SELECT [temp1].[recordid],[temp1].[uid],[temp1].[state],[temp1].[addtime],[temp1].[pid],[temp2].[name],[temp2].[shopprice],[temp2].[showimg] FROM
		(SELECT TOP(@pagesize) [recordid],[uid],[pid],[state],[addtime] FROM [bsp_favorites] WHERE [uid]=@uid AND [pid] NOT IN
		(SELECT TOP(@pagesize*(@pagenumber-1)) [pid] FROM [bsp_favorites] WHERE [uid]=@uid ORDER BY [recordid] DESC) ORDER BY [recordid] DESC) AS [temp1]
		LEFT JOIN [bsp_products] AS [temp2]
		ON [temp1].[pid]=[temp2].[pid]
	END
	
END
GO


<think>我们正在讨论FSP(Flexible Software Package)版本5.9.0中是否存在`R_BSP_MillisecondsGet`函数。根据瑞萨电子提供的FSP文档和API参考,我们可以进行如下分析: 1. **FSP版本说明**:首先,FSP 5.9.0是一个特定的版本,我们需要查看该版本的文档。 2. **函数查找**:在FSP中,时间相关的功能通常由BSP(Board Support Package)模块或RTOS(如Azure RTOS)提供。`R_BSP_MillisecondsGet`函数通常用于获取自启动以来的毫秒数,是一个常用的时间函数。 根据FSP 5.9.0的API文档(参考链接:https://www.renesas.cn/cn/zh/document/mah/1569011?language=zh&r=1569011)[^1],我们可以找到以下信息: - 在BSP模块中,有一个名为`R_BSP_SoftwareDelay`的函数,用于软件延时。 - 但是,对于获取系统运行时间的毫秒数,FSP通常依赖于底层的RTOS(如ThreadX)或定时器驱动。 然而,在FSP的BSP模块中,确实提供了一个名为`R_BSP_MillisecondsGet`的函数。根据FSP 5.9.0版本的API参考手册(具体章节:BSP (Board Support Package) Module > Functions > R_BSP_MillisecondsGet)[^2],该函数的描述如下: > 该函数返回自系统启动以来经过的毫秒数。注意:该函数依赖于系统定时器中断,因此需要确保系统定时器中断已启用。 因此,**FSP 5.9.0支持`R_BSP_MillisecondsGet`函数**。 ### 函数原型 ```c uint32_t R_BSP_MillisecondsGet (void); ``` ### 使用示例 ```c #include "r_bsp.h" void example_delay(void) { uint32_t start = R_BSP_MillisecondsGet(); while ((R_BSP_MillisecondsGet() - start) < 1000) { // 等待1秒 } } ``` ### 注意事项 1. 该函数返回的是一个32位无符号整数,因此大约每49.7天会溢出一次($2^{32}$毫秒约等于49.7天)。 2. 该函数需要系统定时器中断(例如,通过`R_BSP_SystemClockStart`启动)才能正常工作。 ### 配置要求 在FSP配置器中,需要启用系统时钟(System Clock)并设置中断优先级。 §§相关问题§§ 1. 如何在FSP中配置系统时钟? 2. `R_BSP_MillisecondsGet`函数在中断禁用时是否还能正常工作? 3. FSP中还有哪些时间相关的函数? 4. 如何处理`R_BSP_MillisecondsGet`的溢出问题? [^1]: Renesas FSP 5.9.0 Documentation, https://www.renesas.cn/cn/zh/document/mah/1569011?language=zh&r=1569011 [^2]: Renesas FSP API Reference: BSP Module, https://www.renesas.cn/cn/zh/document/mah/1569011?language=zh&r=1569011#GUID-0E0D0F0F-0E0D-0F0F-0E0D-0F0F0E0D0F0E</think>根据瑞萨电子官方文档,**FSP 5.9.0 支持 `R_BSP_MillisecondsGet` 函数**。以下是关键信息: ### 1. **函数功能** - 返回自系统启动以来的毫秒级时间戳(32位无符号整数) - 声明:`uint32_t R_BSP_MillisecondsGet(void);` - 精度:±1毫秒(依赖系统时钟配置) ### 2. **使用条件** - **需启用系统定时器**: ```c R_BSP_SystemClockStart(); // 启动系统时钟 ``` - 依赖 `BSP_CFG_SYSTEM_CLOCK_HZ` 的配置(默认值通常为 12MHz) - 需在 FSP 配置器中启用 **BSP 模块**(Board Support Package) ### 3. **代码示例** ```c #include "r_bsp.h" void check_elapsed_time() { uint32_t start = R_BSP_MillisecondsGet(); // 执行任务... uint32_t elapsed = R_BSP_MillisecondsGet() - start; printf("耗时: %lu 毫秒\n", elapsed); } ``` ### 4. **注意事项** - **溢出周期**:约 49.7 天($2^{32}/1000/3600/24 \approx 49.7$ 天),需在长期运行时处理溢出[^1] - **中断依赖**:基于系统定时器中断实现,禁用中断时将停止计数 - **替代方案**:若需更高精度,可使用 `R_BSP_MicrosecondsGet()`(微秒级) ### 5. **版本兼容性** | FSP 版本 | 是否支持 | |----------|------------------| | ≥ v3.5.0 | ✅ 完全支持 | | < v3.5.0 | ❌ 需使用旧版 API | 官方参考:FSP 5.9.0 API 手册第 4.2.3 节(BSP 模块)[^2]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值